From 38aacd7a7bc551797d8c60cc695fc4922941add9 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 1 Feb 2011 14:29:35 +1100 Subject: waf: Replace python installation rule to allow PYTHONARCHDIR and PYTHONDIR The old rule could only substitute one part of one line, but we need to add a second line to handle when PYTHONDIR and PYTHONARCHDIR do not match. This also avoids shelling out to sed with a regex, which was difficult to read. Andrew Bartlett --- buildtools/wafsamba/wafsamba.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'buildtools/wafsamba/wafsamba.py') diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py index 050777fe5d..dcf7198642 100644 --- a/buildtools/wafsamba/wafsamba.py +++ b/buildtools/wafsamba/wafsamba.py @@ -621,6 +621,28 @@ def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None): Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT +def copy_and_fix_python_path(task): + pattern='sys.path.insert(0, "bin/python")' + if task.env["PYTHONARCHDIR"] in sys.path and task.env["PYTHONDIR"] in sys.path: + replacement = "" + elif task.env["PYTHONARCHDIR"] == task.env["PYTHONDIR"]: + replacement="""sys.path.insert(0, "%s")""" % task.env["PYTHONDIR"] + else: + replacement="""sys.path.insert(0, "%s") +sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"]) + + installed_location=task.outputs[0].bldpath(task.env) + source_file = open(task.inputs[0].srcpath(task.env)) + installed_file = open(installed_location, 'w') + for line in source_file: + newline = line + if pattern in line: + newline = line.replace(pattern, replacement) + installed_file.write(newline) + installed_file.close() + os.chmod(installed_location, 0755) + return 0 + def install_file(bld, destdir, file, chmod=MODE_644, flat=False, python_fixup=False, destname=None, base_name=None): @@ -634,14 +656,8 @@ def install_file(bld, destdir, file, chmod=MODE_644, flat=False, if python_fixup: # fixup the python path it will use to find Samba modules inst_file = file + '.inst' - if bld.env["PYTHONARCHDIR"] not in sys.path: - regex = "s|\(sys.path.insert.*\)bin/python\(.*\)$|\\1${PYTHONARCHDIR}\\2|g" - else: - # Eliminate updating sys.path if the target python dir is already - # in python path. - regex = "s|sys.path.insert.*bin/python.*$||g" bld.SAMBA_GENERATOR('python_%s' % destname, - rule="sed '%s' < ${SRC} > ${TGT}" % regex, + rule=copy_and_fix_python_path, source=file, target=inst_file) file = inst_file -- cgit