wafsamba/samba_waf18: redefine flex function
authorAlexander Bokovoy <ab@samba.org>
Thu, 6 Sep 2018 06:36:18 +0000 (09:36 +0300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 7 Sep 2018 13:45:36 +0000 (15:45 +0200)
There is a bug in waf: flex routine adjusts its inputs against
the task's current working directory but assumes it is being called from
within the build variant directory.

For Samba this means we adjust one level up than the actual work
directory we use to run (bin/ vs bin/default) and flex doesn't find the
source files.

Fix the issue by creating a local override of flex definition that
utilizes the same workd directory for both path adjustment and running
the flex itself.

Signed-off-by: Alexander Bokovoy <ab@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Fri Sep  7 15:45:36 CEST 2018 on sn-devel-144

buildtools/wafsamba/samba_waf18.py

index 282755c1fa68b939811da88a5289cc6f4c2a8889..8a4558d46ded8a823153db64b2317cce1d723da2 100644 (file)
@@ -6,9 +6,36 @@ from waflib import ConfigSet
 from waflib.TaskGen import feature, after
 from waflib.Configure import conf, ConfigurationContext
 
-from waflib.Tools import bison, flex
-sys.modules['bison'] = bison
-sys.modules['flex'] = flex
+from waflib.Tools.flex import decide_ext
+
+# This version of flexfun runs in tsk.get_cwd() as opposed to the
+# bld.variant_dir: since input paths adjusted against tsk.get_cwd(), we have to
+# use tsk.get_cwd() for the work directory as well.
+def flexfun(tsk):
+    env = tsk.env
+    bld = tsk.generator.bld
+    def to_list(xx):
+        if isinstance(xx, str):
+            return [xx]
+        return xx
+    tsk.last_cmd = lst = []
+    lst.extend(to_list(env.FLEX))
+    lst.extend(to_list(env.FLEXFLAGS))
+    inputs = [a.path_from(tsk.get_cwd()) for a in tsk.inputs]
+    if env.FLEX_MSYS:
+        inputs = [x.replace(os.sep, '/') for x in inputs]
+    lst.extend(inputs)
+    lst = [x for x in lst if x]
+    txt = bld.cmd_and_log(lst, cwd=tsk.get_cwd(), env=env.env or None, quiet=0)
+    tsk.outputs[0].write(txt.replace('\r\n', '\n').replace('\r', '\n')) # issue #1207
+
+TaskGen.declare_chain(
+    name = 'flex',
+    rule = flexfun, # issue #854
+    ext_in = '.l',
+    decider = decide_ext,
+)
+
 
 for y in (Build.BuildContext, Build.CleanContext, Build.InstallContext, Build.UninstallContext, Build.ListContext):
     class tmp(y):