Merged revisions 2647-2719 via svnmerge from
[scons.git] / test / subdivide.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Verify that rebuilds do not occur when SConsignFile(None) is used to
29 put a .sconsign file in each directory and we subdvide the dependency
30 tree with subsidiary *SConstruct* files in various subdirectories.
31
32 This depends on using content signatures for evaluation of intermediate
33 Nodes.  We used to configure this explicitly using
34 TargetSignatures('content'), but we now rely on the default behavior
35 being the equivalent of Decider('content').
36 """
37
38 import os.path
39
40 import TestSCons
41
42 _python_ = TestSCons._python_
43
44 test = TestSCons.TestSCons()
45
46 #if os.path.exists('sconsign.py'):
47 #    sconsign = 'sconsign.py'
48 #elif os.path.exists('sconsign'):
49 #    sconsign = 'sconsign'
50 #else:
51 #    print "Can find neither 'sconsign.py' nor 'sconsign' scripts."
52 #    test.no_result(1)
53
54 test.subdir('src', ['src', 'sub'])
55
56 test.write('fake_cc.py', """\
57 import sys
58 ofp = open(sys.argv[1], 'wb')
59 ofp.write('fake_cc.py:  %s\\n' % sys.argv)
60 for s in sys.argv[2:]:
61     ofp.write(open(s, 'rb').read())
62 """)
63
64 test.write('fake_link.py', """\
65 import sys
66 ofp = open(sys.argv[1], 'wb')
67 ofp.write('fake_link.py:  %s\\n' % sys.argv)
68 for s in sys.argv[2:]:
69     ofp.write(open(s, 'rb').read())
70 """)
71
72 test.write('SConstruct', """\
73 SConsignFile(None)
74 env = Environment(PROGSUFFIX = '.exe',
75                   OBJSUFFIX = '.obj',
76                   CCCOM = r'%(_python_)s fake_cc.py $TARGET $SOURCES',
77                   LINKCOM = r'%(_python_)s fake_link.py $TARGET $SOURCES')
78 env.SConscript('src/SConstruct', exports=['env'])
79 env.Object('foo.c')
80 """ % locals())
81
82 test.write(['src', 'SConstruct'], """\
83 SConsignFile(None)
84 env = Environment(PROGSUFFIX = '.exe',
85                   OBJSUFFIX = '.obj',
86                   CCCOM = r'%(_python_)s fake_cc.py $TARGET $SOURCES',
87                   LINKCOM = r'%(_python_)s fake_link.py $TARGET $SOURCES')
88 p = env.Program('prog', ['main.c', '../foo$OBJSUFFIX', 'sub/bar.c'])
89 env.Default(p)
90 """ % locals())
91
92 test.write('foo.c', """\
93 foo.c
94 """)
95
96 test.write(['src', 'main.c'], """\
97 src/main.c
98 """)
99
100 test.write(['src', 'sub', 'bar.c'], """\
101 src/sub/bar.c
102 """)
103
104 test.run()
105
106 src_prog_exe    = os.path.join('src', 'prog.exe')
107 src_main_c      = os.path.join('src', 'main.c')
108 src_main_obj    = os.path.join('src', 'main.obj')
109 src_sub_bar_c   = os.path.join('src', 'sub', 'bar.c')
110 src_sub_bar_obj = os.path.join('src', 'sub', 'bar.obj')
111
112 expect = """\
113 fake_link.py:  ['fake_link.py', '%(src_prog_exe)s', '%(src_main_obj)s', 'foo.obj', '%(src_sub_bar_obj)s']
114 fake_cc.py:  ['fake_cc.py', '%(src_main_obj)s', '%(src_main_c)s']
115 src/main.c
116 fake_cc.py:  ['fake_cc.py', 'foo.obj', 'foo.c']
117 foo.c
118 fake_cc.py:  ['fake_cc.py', '%(src_sub_bar_obj)s', '%(src_sub_bar_c)s']
119 src/sub/bar.c
120 """ % locals()
121
122 if os.sep == '\\':
123     import string
124     expect = string.replace(expect, '\\', '\\\\')
125
126 test.must_match(['src', 'prog.exe'], expect)
127
128 test.up_to_date(chdir='src', arguments = test.workpath())
129
130 test.up_to_date(arguments = '.')
131
132 test.pass_test()