Fix -U, -D and -d with explicit targets that start with ../.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 28 Jun 2003 05:09:59 +0000 (05:09 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 28 Jun 2003 05:09:59 +0000 (05:09 +0000)
[Updating a change that was previously not synchronized to CVS.]

git-svn-id: http://scons.tigris.org/svn/scons/trunk@728 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Script/__init__.py
test/option--D.py
test/option--U.py
test/option-u.py

index 9ae5229d2b0335d985be723356de28d8fa32a618..29f8e114a86d08c3ff0c9c05fe74118734bff124 100644 (file)
@@ -858,32 +858,48 @@ def _main():
     # that are SConscript settable:
     SCons.Node.implicit_cache = ssoptions.get('implicit_cache')
 
-    if target_top:
-        target_top = SCons.Node.FS.default_fs.Dir(target_top)
-        
-        if options.climb_up == 2 and not targets:
-            # -D with default targets
+    lookup_top = None
+    if targets:
+        # They specified targets on the command line, so if they
+        # used -u, -U or -D, we have to look up targets relative
+        # to the top, but we build whatever they specified.
+        if target_top:
+            lookup_top = SCons.Node.FS.default_fs.Dir(target_top)
             target_top = None
-        elif options.climb_up == 3 and not targets:
-            # -U with default targets
-            default_targets = SCons.Script.SConscript.default_targets
-            def check_dir(x, target_top=target_top):
-                if hasattr(x, 'cwd') and not x.cwd is None:
-                    cwd = x.cwd.srcnode()
-                    return cwd == target_top
+    else:
+        # There are no targets specified on the command line,
+        # so if they used -u, -U or -D, we may have to restrict
+        # what actually gets built.
+        if target_top:
+            if options.climb_up == 1:
+                # -u, local directory and below
+                target_top = SCons.Node.FS.default_fs.Dir(target_top)
+                lookup_top = target_top
+            elif options.climb_up == 2:
+                # -D, all Default() targets
+                target_top = None
+                lookup_top = None
+            elif options.climb_up == 3:
+                # -U, local SConscript Default() targets
+                target_top = SCons.Node.FS.default_fs.Dir(target_top)
+                def check_dir(x, target_top=target_top):
+                    if hasattr(x, 'cwd') and not x.cwd is None:
+                        cwd = x.cwd.srcnode()
+                        return cwd == target_top
+                    else:
+                        # x doesn't have a cwd, so it's either not a target,
+                        # or not a file, so go ahead and keep it as a default
+                        # target and let the engine sort it out:
+                        return 1                
+                default_targets = SCons.Script.SConscript.default_targets
+                if default_targets is None:
+                    default_targets = []
                 else:
-                    # x doesn't have a cwd, so it's either not a target,
-                    # or not a file, so go ahead and keep it as a default
-                    # target and let the engine sort it out:
-                    return 1                
-            if default_targets is None:
-                default_targets = []
-            else:
-                default_targets = filter(check_dir, default_targets)
-            SCons.Script.SConscript.default_targets = default_targets
-            target_top = None
+                    default_targets = filter(check_dir, default_targets)
+                SCons.Script.SConscript.default_targets = default_targets
+                target_top = None
+                lookup_top = None
 
-    if not targets:
         targets = SCons.Script.SConscript.default_targets
         if targets is None:
             targets = [SCons.Node.FS.default_fs.Dir('.')]
@@ -892,18 +908,18 @@ def _main():
         sys.stderr.write("scons: *** No targets specified and no Default() targets found.  Stop.\n")
         sys.exit(2)
 
-    def Entry(x, top = target_top):
+    def Entry(x, ltop=lookup_top, ttop=target_top):
         if isinstance(x, SCons.Node.Node):
             node = x
         else:
             node = SCons.Node.Alias.default_ans.lookup(x)
             if node is None:
                 node = SCons.Node.FS.default_fs.Entry(x,
-                                                      directory = top,
+                                                      directory = ltop,
                                                       create = 1)
-        if top and not node.is_under(top):
-            if isinstance(node, SCons.Node.FS.Dir) and top.is_under(node):
-                node = top
+        if ttop and not node.is_under(ttop):
+            if isinstance(node, SCons.Node.FS.Dir) and ttop.is_under(node):
+                node = ttop
             else:
                 node = None
         return node
index 0bc295cef60439786c59028253a3e9e657ba6bcd..d1a118ee0375a148ceddff522d2127b9fa17527a 100644 (file)
@@ -83,7 +83,43 @@ test.run(arguments = '-D bar', chdir = 'sub1')
 test.fail_test(os.path.exists(test.workpath('sub1', 'foo.out')))
 test.fail_test(not os.path.exists(test.workpath('sub2', 'bar.out')))
 
+# Make sure explicit targets beginning with ../ get built.
+test.subdir('sub6', ['sub6', 'dir'])
+
+test.write(['sub6', 'SConstruct'], """\
+def cat(env, source, target):
+    target = str(target[0])
+    source = map(str, source)
+    f = open(target, "wb")
+    for src in source:
+        f.write(open(src, "rb").read())
+    f.close()
+env = Environment(BUILDERS={'Cat':Builder(action=cat)})
+env.Cat('f1.out', 'f1.in')
+f2 = env.Cat('f2.out', 'f2.in')
+Default(f2)
+SConscript('dir/SConscript', "env")
+""")
 
+test.write(['sub6', 'f1.in'], "f1.in\n")
+test.write(['sub6', 'f2.in'], "f2.in\n")
 
-test.pass_test()
+test.write(['sub6', 'dir', 'SConscript'], """\
+Import("env")
+f3 = env.Cat('f3.out', 'f3.in')
+env.Cat('f4.out', 'f4.in')
+Default(f3)
+""")
+
+test.write(['sub6', 'dir', 'f3.in'], "f3.in\n")
+test.write(['sub6', 'dir', 'f4.in'], "f4.in\n")
 
+test.run(chdir = 'sub6/dir', arguments = '-D ../f1.out')
+
+test.fail_test(not os.path.exists(test.workpath('sub6', 'f1.out')))
+test.fail_test(os.path.exists(test.workpath('sub6', 'f2.out')))
+test.fail_test(os.path.exists(test.workpath('sub6', 'dir', 'f3.out')))
+test.fail_test(os.path.exists(test.workpath('sub6', 'dir', 'f4.out')))
+
+
+test.pass_test()
index f5a7b748707432d31647e712c5f5f67d4d10700a..4fb77a3820a2840b216495cafb4deb1bde6967f3 100644 (file)
@@ -164,4 +164,35 @@ test.run(arguments = '-U', status=2, stderr="""\
 scons: *** Do not know how to make target `not_a_target.in'.  Stop.
 """)
 
+# Make sure explicit targets beginning with ../ get built.
+test.subdir('sub6', ['sub6', 'dir'])
+
+test.write(['sub6', 'SConstruct'], """\
+def cat(env, source, target):
+    target = str(target[0])
+    source = map(str, source)
+    f = open(target, "wb")
+    for src in source:
+        f.write(open(src, "rb").read())
+    f.close()
+env = Environment(BUILDERS={'Cat':Builder(action=cat)})
+env.Cat('foo.out', 'foo.in')
+SConscript('dir/SConscript', "env")
+""")
+
+test.write(['sub6', 'foo.in'], "foo.in\n")
+
+test.write(['sub6', 'dir', 'SConscript'], """\
+Import("env")
+bar = env.Cat('bar.out', 'bar.in')
+Default(bar)
+""")
+
+test.write(['sub6', 'dir', 'bar.in'], "bar.in\n")
+
+test.run(chdir = 'sub6/dir', arguments = '-U ../foo.out')
+
+test.fail_test(not os.path.exists(test.workpath('sub6', 'foo.out')))
+test.fail_test(os.path.exists(test.workpath('sub6', 'dir', 'bar.out')))
+
 test.pass_test()
index 2b2ad4fa17c8f3cde610b3f6ecf9bf67ceff4669..82583d4f81ca2a39b83b067d5114c35388e4ce93 100644 (file)
@@ -136,4 +136,40 @@ test.fail_test(os.path.exists(test.workpath('sub4', 'dir', 'f4b.out')))
 test.fail_test(test.read(['build', 'f4a.out']) != "sub4/f4a.in")
 test.fail_test(test.read(['build', 'dir', 'f4b.out']) != "sub4/dir/f4b.in")
 
+# Make sure explicit targets beginning with ../ get built.
+test.subdir('sub6', ['sub6', 'dir'])
+
+test.write(['sub6', 'SConstruct'], """\
+def cat(env, source, target):
+    target = str(target[0])
+    source = map(str, source)
+    f = open(target, "wb")
+    for src in source:
+        f.write(open(src, "rb").read())
+    f.close()
+env = Environment(BUILDERS={'Cat':Builder(action=cat)})
+env.Cat('f1.out', 'f1.in')
+env.Cat('f2.out', 'f2.in')
+SConscript('dir/SConscript', "env")
+""")
+
+test.write(['sub6', 'f1.in'], "f1.in\n")
+test.write(['sub6', 'f2.in'], "f2.in\n")
+
+test.write(['sub6', 'dir', 'SConscript'], """\
+Import("env")
+env.Cat('f3.out', 'f3.in')
+env.Cat('f4.out', 'f4.in')
+""")
+
+test.write(['sub6', 'dir', 'f3.in'], "f3.in\n")
+test.write(['sub6', 'dir', 'f4.in'], "f4.in\n")
+
+test.run(chdir = 'sub6/dir', arguments = '-u ../f2.out')
+
+test.fail_test(os.path.exists(test.workpath('sub6', 'f1.out')))
+test.fail_test(not os.path.exists(test.workpath('sub6', 'f2.out')))
+test.fail_test(os.path.exists(test.workpath('sub6', 'dir', 'f3.out')))
+test.fail_test(os.path.exists(test.workpath('sub6', 'dir', 'f4.out')))
+
 test.pass_test()