buildtools/wafsamba: re-write shebang for delivered python scripts
authorNoel Power <noel.power@suse.com>
Wed, 12 Dec 2018 20:30:32 +0000 (20:30 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 13 Dec 2018 23:51:33 +0000 (00:51 +0100)
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>
buildtools/wafsamba/samba_python.py
buildtools/wafsamba/wafsamba.py

index 419c559848f6bf8009feb15f0fcbc289677226ef..dd602451cfa2cd2156e8e431cf8ecb44d80d52cd 100644 (file)
@@ -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)
 
index f31432a01483b1a90bf3ef94cf8c6ec2e17db136..230a76d8f2c97ffade5ee12b86e0cd25b0377dc0 100644 (file)
@@ -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: