diff options
author | Noel Power <noel.power@suse.com> | 2018-12-12 20:30:32 +0000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2018-12-14 00:51:33 +0100 |
commit | bae5364bf39f863d25e3c7caac59c6af28b4f441 (patch) | |
tree | 20e2b3191729858b1357c3c810693d37c86ba920 /buildtools/wafsamba | |
parent | 0756b59f810ee9d4bf9b6d5eac02d8951751ff79 (diff) | |
download | samba-bae5364bf39f863d25e3c7caac59c6af28b4f441.tar.gz |
buildtools/wafsamba: re-write shebang for delivered python scripts
Can't see how the orig code would have worked though
a)
task.env["PYTHON"] is a list
b) task.env["PYTHON_SPECIFIED"] can (and is in our case false) looks
like it would only be true for python2 but in anycase no harm we
always rewrite the shebang
So now it works as follows,
1. PYTHON (which is where the shebang is got) is set to python3 by default
2. To override the default you need to set PYTHON (e.g. to build with python2)
3. If you give a full path in PYTHON then shebang is of the format
"#!{FULL_PYTHON_INTERPRETER_PATH)
4. If you specify PYTHON=python or PYTHON=python2 etc. shebang format is
"#!!/usr/bin/env python", "#!!/usr/bin/env python2" etc.
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'buildtools/wafsamba')
-rw-r--r-- | buildtools/wafsamba/samba_python.py | 4 | ||||
-rw-r--r-- | buildtools/wafsamba/wafsamba.py | 8 |
2 files changed, 7 insertions, 5 deletions
diff --git a/buildtools/wafsamba/samba_python.py b/buildtools/wafsamba/samba_python.py index 419c559848f..dd602451cfa 100644 --- a/buildtools/wafsamba/samba_python.py +++ b/buildtools/wafsamba/samba_python.py @@ -30,10 +30,12 @@ def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,6,0)): conf.setenv('default') if not os.getenv('PYTHON', None): - conf.env['PYTHON'] = sys.executable + conf.env['PYTHON'] = 'python3' + conf.find_program('python', var='PYTHON', mandatory=mandatory) conf.load('python') path_python = conf.find_program('python') + conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python) conf.check_python_version(version) diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py index f31432a0148..230a76d8f2c 100644 --- a/buildtools/wafsamba/wafsamba.py +++ b/buildtools/wafsamba/wafsamba.py @@ -772,10 +772,10 @@ def copy_and_fix_python_path(task): replacement="""sys.path.insert(0, "%s") sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"]) - if task.env["PYTHON"][0] == "/": - replacement_shebang = "#!%s\n" % task.env["PYTHON"] + if task.env["PYTHON"][0].startswith("/"): + replacement_shebang = "#!%s\n" % task.env["PYTHON"][0] else: - replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PYTHON"] + replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PYTHON"][0] installed_location=task.outputs[0].bldpath(task.env) source_file = open(task.inputs[0].srcpath(task.env)) @@ -783,7 +783,7 @@ sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"]) lineno = 0 for line in source_file: newline = line - if (lineno == 0 and task.env["PYTHON_SPECIFIED"] is True and + if (lineno == 0 and line[:2] == "#!"): newline = replacement_shebang elif pattern in line: |