http://scons.tigris.org/issues/show_bug.cgi?id=2329
[scons.git] / test / Scanner / generated.py
index 2dfd32262be48c94bb077ba722b970c9c1cbc9d4..021204358626aa6ef8a5620c9b653a3e265a3c08 100644 (file)
@@ -34,10 +34,6 @@ factors triggered the bug Scott saw, and partly because the real-world
 complexity is valuable in its own right.
 """
 
-import os.path
-import sys
-
-import TestCmd
 import TestSCons
 
 test = TestSCons.TestSCons()
@@ -55,10 +51,7 @@ test.write('SConstruct', """\
 ###
 
 experimenttop = r"%s"
-
 import os
-import os.path
-import string
 import Mylib
 
 BStaticLibMerge = Builder(generator = Mylib.Gen_StaticLibMerge)
@@ -77,7 +70,7 @@ e["EXPORT_INCLUDE"] = os.path.join(experimenttop, "export", "include")
 e["EXPORT_LIB"] = os.path.join(experimenttop, "export", "lib")
 e["INSTALL_BIN"] = os.path.join(experimenttop, "install", "bin")
 
-build_dir = os.path.join(experimenttop, "tmp-bld-dir")
+variant_dir = os.path.join(experimenttop, "tmp-bld-dir")
 src_dir = os.path.join(experimenttop, "src")
 
 env.Append(CPPPATH = [e["EXPORT_INCLUDE"]])
@@ -91,7 +84,6 @@ Mylib.Subdirs(env, "src")
 
 test.write('Mylib.py', """\
 import os
-import string
 import re
 
 def Subdirs(env, dirlist):
@@ -99,10 +91,10 @@ def Subdirs(env, dirlist):
         env.SConscript(file, "env")
 
 def _subconf_list(dirlist):
-    return map(lambda x: os.path.join(x, "SConscript"), string.split(dirlist))
+    return [os.path.join(x, "SConscript") for x in dirlist.split()]
 
 def StaticLibMergeMembers(local_env, libname, hackpath, files):
-    for file in string.split(files):
+    for file in files.split():
         # QQQ Fix limits in grok'ed regexp
         tmp = re.sub(".c$", ".o", file)
         objname = re.sub(".cpp", ".o", tmp)
@@ -128,22 +120,22 @@ def Gen_StaticLibMerge(source, target, env, for_signature):
     return [["ar", "cq"] + target + srclist, ["ranlib"] + target]
 
 def StaticLibrary(env, target, source):
-    env.StaticLibrary(target, string.split(source))
+    env.StaticLibrary(target, source.split())
 
 def SharedLibrary(env, target, source):
-    env.SharedLibrary(target, string.split(source))
+    env.SharedLibrary(target, source.split())
 
 def ExportHeader(env, headers):
-    env.Install(dir = env["EXPORT_INCLUDE"], source = string.split(headers))
+    env.Install(dir = env["EXPORT_INCLUDE"], source = headers.split())
 
 def ExportLib(env, libs):
-    env.Install(dir = env["EXPORT_LIB"], source = string.split(libs))
+    env.Install(dir = env["EXPORT_LIB"], source = libs.split())
 
 def InstallBin(env, bins):
-    env.Install(dir = env["INSTALL_BIN"], source = string.split(bins))
+    env.Install(dir = env["INSTALL_BIN"], source = bins.split())
 
 def Program(env, target, source):
-    env.Program(target, string.split(source))
+    env.Program(target, source.split())
 
 def AddCFlags(env, str):
     env.Append(CPPFLAGS = " " + str)
@@ -153,13 +145,13 @@ def AddCFlags(env, str):
 #    AddCFlags(env, str)
 
 def AddIncludeDirs(env, str):
-    env.Append(CPPPATH = string.split(str))
+    env.Append(CPPPATH = str.split())
 
 def AddLibs(env, str):
-    env.Append(LIBS = string.split(str))
+    env.Append(LIBS = str.split())
 
 def AddLibDirs(env, str):
-    env.Append(LIBPATH = string.split(str))
+    env.Append(LIBPATH = str.split())
 
 """)
 
@@ -196,7 +188,6 @@ env = env.Clone()    # Yes, clobber intentionally
 
 test.write(['src', 'lib_geng', 'SConscript'], """\
 # --- Begin SConscript boilerplate ---
-import string
 import sys
 import Mylib
 Import("env")
@@ -240,8 +231,8 @@ for k in fromdict.keys():
         except SCons.Errors.UserError:
              pass
 todict["CFLAGS"] = fromdict["CPPFLAGS"] + " " + \
-    string.join(map(lambda x: "-I" + x, env["CPPPATH"])) + " " + \
-    string.join(map(lambda x: "-L" + x, env["LIBPATH"])) 
+    ' '.join(["-I" + x for x in env["CPPPATH"]]) + " " + \
+    ' '.join(["-L" + x for x in env["LIBPATH"]])
 todict["CXXFLAGS"] = todict["CFLAGS"]
 
 generated_hdrs = "libg_gx.h libg_gy.h libg_gz.h"
@@ -250,9 +241,9 @@ static_hdrs = "libg_w.h"
 exported_hdrs = static_hdrs
 lib_name = "g"
 lib_fullname = env.subst("${LIBPREFIX}g${LIBSUFFIX}")
-lib_srcs = string.split("libg_1.c libg_2.c libg_3.c")
+lib_srcs = "libg_1.c libg_2.c libg_3.c".split()
 import re
-lib_objs = map(lambda x: re.sub("\.c$", ".o", x), lib_srcs)
+lib_objs = [re.sub("\.c$", ".o", x) for x in lib_srcs]
 
 Mylib.ExportHeader(env, exported_hdrs)
 Mylib.ExportLib(env, lib_fullname)
@@ -282,11 +273,11 @@ cmd_justlib = "%s %s -C ${SOURCES[0].dir}" % (escape(sys.executable),
 #
 # SCons bug??
 
-env.Command(string.split(generated_hdrs),
+env.Command(generated_hdrs.split(),
             ["MAKE-HEADER.py"],
             cmd_generated)
 recurse_env.Command([lib_fullname] + lib_objs,
-                    lib_srcs + string.split(generated_hdrs + " " + static_hdrs),
+                    lib_srcs + (generated_hdrs + " " + static_hdrs).split(),
                     cmd_justlib) 
 """)
 
@@ -310,18 +301,16 @@ import os
 Scanned = {}
 
 def write_out(file, dict):
-    keys = dict.keys()
-    keys.sort()
     f = open(file, 'wb')
-    for k in keys:
+    for k in sorted(dict.keys()):
         file = os.path.split(k)[1]
         f.write(file + ": " + str(dict[k]) + "\\n")
     f.close()
 
-orig_function = CScan.scan
+orig_function = CScan.__call__
 
-def MyCScan(node, paths, orig_function=orig_function):
-    deps = orig_function(node, paths)
+def MyCScan(node, paths, cwd, orig_function=orig_function):
+    deps = orig_function(node, paths, cwd)
 
     global Scanned
     n = str(node)
@@ -333,7 +322,7 @@ def MyCScan(node, paths, orig_function=orig_function):
 
     return deps
 
-CScan.scan = MyCScan
+CScan.__call__ = MyCScan
 
 env = Environment(CPPPATH = ".")
 l = env.StaticLibrary("g", Split("libg_1.c libg_2.c libg_3.c"))
@@ -411,10 +400,6 @@ int g_3()
 test.run(stderr=TestSCons.noisy_ar,
          match=TestSCons.match_re_dotall)
 
-# XXX Note that the generated .h files still get scanned twice,
-# once before they're generated and once after.  That's the
-# next thing to fix here.
-
 test.must_match("MyCScan.out", """\
 libg_1.c: 1
 libg_2.c: 1
@@ -426,3 +411,9 @@ libg_w.h: 1
 """)
 
 test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: