setup: make the name of the main script flexible

Summary:
Previously, the main script is hard-coded as `hg`. We use a wrapper named
`hg` for logging. Therefore make the name more flexible by reading `HGNAME`.
The name is enforced starting with `hg` and cannot have strange characters.

Test Plan:
`HGNAME=hg-foobar python setup.py install --user`. Make sure the `hg-foobar`
script gets installed in `~/.local/bin`, has the correct `libdir` set, is
working, and the working copy does not have `hg-foobar`.

Also make sure `make local` does not write `$HGNAME` in the working copy.


Reviewers: durham, #mercurial

Reviewed By: durham

Subscribers: durham, phillco

Differential Revision: https://phabricator.intern.facebook.com/D6695942

Signature: 6695942:1515633395:dec1d46590a1210f2012de964f4b4ad830af9292
This commit is contained in:
Jun Wu 2018-01-10 12:06:26 -08:00
parent 4ead882012
commit 1ed82fae8e

View File

@ -214,6 +214,12 @@ def write_if_changed(path, content):
fh.write(content) fh.write(content)
scripts = ['hg'] scripts = ['hg']
# Rename hg to $HGNAME. Useful when "hg" is a wrapper calling $HGNAME (or chg).
hgname = os.environ.get('HGNAME', 'hg')
if not re.match('\Ahg[.0-9a-z-]*\Z', hgname):
raise RuntimeError('Illegal HGNAME: %s' % hgname)
if os.name == 'nt': if os.name == 'nt':
# We remove hg.bat if we are able to build hg.exe. # We remove hg.bat if we are able to build hg.exe.
scripts.append('contrib/win32/hg.bat') scripts.append('contrib/win32/hg.bat')
@ -525,6 +531,14 @@ class hgbuildscripts(build_scripts):
return build_scripts.run(self) return build_scripts.run(self)
def copy_scripts(self):
build_scripts.copy_scripts(self)
# Rename hg to hgname
if hgname != 'hg':
oldpath = os.path.join(self.build_dir, 'hg')
newpath = os.path.join(self.build_dir, hgname)
os.rename(oldpath, newpath)
class hgbuildpy(build_py): class hgbuildpy(build_py):
def finalize_options(self): def finalize_options(self):
build_py.finalize_options(self) build_py.finalize_options(self)