Steven checked in some changes yesterday which fixed a great number of
[scons.git] / test / subdivide.py
index a81695753b192ea21818cc694330d1fb2c50e5ef..2802fc8add1776374d39b456d9ece2fefc187c8d 100644 (file)
@@ -26,81 +26,123 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 """
 Verify that rebuilds do not occur when SConsignFile(None) is used to
-put a .sconsign file in each directory, and TargetSignatures('content')
-is used to subdivide a dependency tree.
+put a .sconsign file in each directory and we subdvide the dependency
+tree with subsidiary *SConstruct* files in various subdirectories.
+
+This depends on using content signatures for evaluation of intermediate
+Nodes.  We used to configure this explicitly using
+TargetSignatures('content'), but we now rely on the default behavior
+being the equivalent of Decider('content').
 """
 
-import os.path
+import os
 
 import TestSCons
 
 test = TestSCons.TestSCons()
 
-#if os.path.exists('sconsign.py'):
-#    sconsign = 'sconsign.py'
-#elif os.path.exists('sconsign'):
-#    sconsign = 'sconsign'
-#else:
-#    print "Can find neither 'sconsign.py' nor 'sconsign' scripts."
-#    test.no_result(1)
-
 test.subdir('src', ['src', 'sub'])
 
+# Because this test sets SConsignFile(None), we execute our fake
+# scripts directly, not by feeding them to the Python executable.
+# That is, we chmod 0755 and us a "#!/usr/bin/env python" first
+# line for POSIX systems, and add .PY to the %PATHEXT% variable on
+# Windows.  If we didn't do this, then running this script with
+# suitable prileveges would create a .sconsign file in the directory
+# where the Python executable lives.  This can happen out of the
+# box on Mac OS X, with the result that the .sconsign statefulness
+# can mess up other tests.
+
+fake_cc_py = test.workpath('fake_cc.py')
+fake_link_py = test.workpath('fake_link.py')
+
+test.write(fake_cc_py, """\
+#!/usr/bin/env python
+import sys
+ofp = open(sys.argv[1], 'wb')
+ofp.write('fake_cc.py:  %s\\n' % sys.argv)
+for s in sys.argv[2:]:
+    ofp.write(open(s, 'rb').read())
+""")
+
+test.write(fake_link_py, """\
+#!/usr/bin/env python
+import sys
+ofp = open(sys.argv[1], 'wb')
+ofp.write('fake_link.py:  %s\\n' % sys.argv)
+for s in sys.argv[2:]:
+    ofp.write(open(s, 'rb').read())
+""")
+
+test.chmod(fake_cc_py, 0755)
+test.chmod(fake_link_py, 0755)
+
 test.write('SConstruct', """\
 SConsignFile(None)
-TargetSignatures('content')
-env = Environment()
+env = Environment(PROGSUFFIX = '.exe',
+                  OBJSUFFIX = '.obj',
+                  CCCOM = r'%(fake_cc_py)s $TARGET $SOURCES',
+                  LINKCOM = r'%(fake_link_py)s $TARGET $SOURCES')
+env.PrependENVPath('PATHEXT', '.PY')
 env.SConscript('src/SConstruct', exports=['env'])
 env.Object('foo.c')
-""")
+""" % locals())
 
 test.write(['src', 'SConstruct'], """\
 SConsignFile(None)
-TargetSignatures('content')
-env = Environment()
-p = env.Program('prog', ['main.c', '../foo%s', 'sub/bar.c'])
+env = Environment(PROGSUFFIX = '.exe',
+                  OBJSUFFIX = '.obj',
+                  CCCOM = r'%(fake_cc_py)s $TARGET $SOURCES',
+                  LINKCOM = r'%(fake_link_py)s $TARGET $SOURCES')
+env.PrependENVPath('PATHEXT', '.PY')
+p = env.Program('prog', ['main.c', '../foo$OBJSUFFIX', 'sub/bar.c'])
 env.Default(p)
-""" % TestSCons._obj)
+""" % locals())
 
 test.write('foo.c', """\
-#include <stdio.h>
-#include <stdlib.h>
-void
-foo(void) {
-    printf("foo.c\\n");
-}
+foo.c
 """)
 
 test.write(['src', 'main.c'], """\
-#include <stdio.h>
-#include <stdlib.h>
-extern void foo(void);
-extern void bar(void);
-int
-main(int argc, char *argv[]) {
-    foo();
-    bar();
-    printf("src/main.c\\n");
-    exit (0);
-}
+src/main.c
 """)
 
 test.write(['src', 'sub', 'bar.c'], """\
-#include <stdio.h>
-#include <stdlib.h>
-void
-bar(void) {
-    printf("bar.c\\n");
-}
+src/sub/bar.c
 """)
 
 test.run()
 
-test.run(program=test.workpath('src', 'prog'),
-         stdout="foo.c\nbar.c\nsrc/main.c\n")
+src_prog_exe    = os.path.join('src', 'prog.exe')
+src_main_c      = os.path.join('src', 'main.c')
+src_main_obj    = os.path.join('src', 'main.obj')
+src_sub_bar_c   = os.path.join('src', 'sub', 'bar.c')
+src_sub_bar_obj = os.path.join('src', 'sub', 'bar.obj')
+
+expect = """\
+fake_link.py:  ['%(fake_link_py)s', '%(src_prog_exe)s', '%(src_main_obj)s', 'foo.obj', '%(src_sub_bar_obj)s']
+fake_cc.py:  ['%(fake_cc_py)s', '%(src_main_obj)s', '%(src_main_c)s']
+src/main.c
+fake_cc.py:  ['%(fake_cc_py)s', 'foo.obj', 'foo.c']
+foo.c
+fake_cc.py:  ['%(fake_cc_py)s', '%(src_sub_bar_obj)s', '%(src_sub_bar_c)s']
+src/sub/bar.c
+""" % locals()
+
+if os.sep == '\\':
+    import string
+    expect = string.replace(expect, '\\', '\\\\')
+
+test.must_match(['src', 'prog.exe'], expect)
 
 test.up_to_date(chdir='src', arguments = test.workpath())
 
 test.up_to_date(arguments = '.')
 
 test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: