From 8e41c50f7ba2893da23eb80bfe4729518a789449 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 8 Apr 2013 08:33:55 +1000 Subject: [PATCH 1/2] build: Remove extra space in shebang Reviewed-by: Michael Adam (cherry picked from commit 45a596fbe9ed2b198956d58784999df780f6dd65) --- source3/wscript | 2 +- wscript | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source3/wscript b/source3/wscript index 194d712..0c7e260 100644 --- a/source3/wscript +++ b/source3/wscript @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#!/usr/bin/env python srcdir=".." diff --git a/wscript b/wscript index c8dcccd..c2a8dc5 100644 --- a/wscript +++ b/wscript @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#!/usr/bin/env python srcdir = '.' blddir = 'bin' -- 1.7.11.7 From 7c7c59032b18601568636cb5ecbbeacf16d1da98 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 8 Apr 2013 15:57:45 +1000 Subject: [PATCH 2/2] build: Replace #!/usr/bin/env python with passed in PYTHON= This means that if we were forced to use a specific python for the build, we will put that binary into the top of samba-tool, so it continues to work after the install. Andrew Bartlett Reviewed-by: Michael Adam (cherry picked from commit 58e3c5323e343dcab1c528c6b6a44925b76cb297) --- buildtools/wafsamba/samba_python.py | 10 ++++++++++ buildtools/wafsamba/wafsamba.py | 15 ++++++++++++++- wscript | 5 +---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/buildtools/wafsamba/samba_python.py b/buildtools/wafsamba/samba_python.py index b2172f7..847b431 100644 --- a/buildtools/wafsamba/samba_python.py +++ b/buildtools/wafsamba/samba_python.py @@ -5,6 +5,16 @@ from samba_utils import * from samba_autoconf import * from Configure import conf + +@conf +def SAMBA_CHECK_PYTHON(conf, mandatory=True): + # enable tool to build python extensions + conf.find_program('python', var='PYTHON', mandatory=mandatory) + conf.check_tool('python') + path_python = conf.find_program('python') + conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python) + conf.check_python_version((2,4,2)) + @conf def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True): if conf.env["python_headers_checked"] == []: diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py index f7156ec..3559cc1 100644 --- a/buildtools/wafsamba/wafsamba.py +++ b/buildtools/wafsamba/wafsamba.py @@ -696,14 +696,25 @@ def copy_and_fix_python_path(task): replacement="""sys.path.insert(0, "%s") sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"]) + shebang = None + + if task.env["PYTHON"][0] == "/": + replacement_shebang = "#!%s" % task.env["PYTHON"] + else: + replacement_shebang = "#!/usr/bin/env %s" % task.env["PYTHON"] + installed_location=task.outputs[0].bldpath(task.env) source_file = open(task.inputs[0].srcpath(task.env)) installed_file = open(installed_location, 'w') + lineno = 0 for line in source_file: newline = line - if pattern in line: + if lineno == 0 and task.env["PYTHON_SPECIFIED"] == True and line[:2] == "#!": + newline = replacement_shebang + elif pattern in line: newline = line.replace(pattern, replacement) installed_file.write(newline) + lineno = lineno + 1 installed_file.close() os.chmod(installed_location, 0755) return 0 @@ -727,6 +738,8 @@ def install_file(bld, destdir, file, chmod=MODE_644, flat=False, target=inst_file) bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHONARCHDIR"]) bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHONDIR"]) + bld.add_manual_dependency(bld.path.find_or_declare(inst_file), str(bld.env["PYTHON_SPECIFIED"])) + bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHON"]) file = inst_file if base_name: file = os.path.join(base_name, file) diff --git a/wscript b/wscript index c2a8dc5..de518ac 100644 --- a/wscript +++ b/wscript @@ -82,13 +82,10 @@ def configure(conf): conf.RECURSE('lib/replace') - conf.find_program('python', var='PYTHON', mandatory=True) conf.find_program('perl', var='PERL', mandatory=True) conf.find_program('xsltproc', var='XSLTPROC') - # enable tool to build python extensions - conf.check_tool('python') - conf.check_python_version((2,4,2)) + conf.SAMBA_CHECK_PYTHON(mandatory=True) conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=True) if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']: -- 1.7.11.7