Added fix for TeX includes with same name as subdirs.
[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
39
40 import TestSCons
41
42 test = TestSCons.TestSCons()
43
44 test.subdir('src', ['src', 'sub'])
45
46 _python_ = TestSCons._python_
47
48 # Because this test sets SConsignFile(None), we execute our fake
49 # scripts directly, not by feeding them to the Python executable.
50 # That is, we chmod 0755 and us a "#!/usr/bin/env python" first
51 # line for POSIX systems, and add .PY to the %PATHEXT% variable on
52 # Windows.  If we didn't do this, then running this script with
53 # suitable prileveges would create a .sconsign file in the directory
54 # where the Python executable lives.  This can happen out of the
55 # box on Mac OS X, with the result that the .sconsign statefulness
56 # can mess up other tests.
57
58 fake_cc_py = test.workpath('fake_cc.py')
59 fake_link_py = test.workpath('fake_link.py')
60
61 test.write(fake_cc_py, """\
62 #!/usr/bin/env python
63 import sys
64 ofp = open(sys.argv[1], 'wb')
65 ofp.write('fake_cc.py:  %s\\n' % sys.argv)
66 for s in sys.argv[2:]:
67     ofp.write(open(s, 'rb').read())
68 """)
69
70 test.write(fake_link_py, """\
71 #!/usr/bin/env python
72 import sys
73 ofp = open(sys.argv[1], 'wb')
74 ofp.write('fake_link.py:  %s\\n' % sys.argv)
75 for s in sys.argv[2:]:
76     ofp.write(open(s, 'rb').read())
77 """)
78
79 test.chmod(fake_cc_py, 0755)
80 test.chmod(fake_link_py, 0755)
81
82 test.write('SConstruct', """\
83 SConsignFile(None)
84 env = Environment(PROGSUFFIX = '.exe',
85                   OBJSUFFIX = '.obj',
86                   CCCOM = r'%(_python_)s %(fake_cc_py)s $TARGET $SOURCES',
87                   LINKCOM = r'%(_python_)s %(fake_link_py)s $TARGET $SOURCES')
88 env.PrependENVPath('PATHEXT', '.PY')
89 env.SConscript('src/SConstruct', exports=['env'])
90 env.Object('foo.c')
91 """ % locals())
92
93 test.write(['src', 'SConstruct'], """\
94 SConsignFile(None)
95 env = Environment(PROGSUFFIX = '.exe',
96                   OBJSUFFIX = '.obj',
97                   CCCOM = r'%(_python_)s %(fake_cc_py)s $TARGET $SOURCES',
98                   LINKCOM = r'%(_python_)s %(fake_link_py)s $TARGET $SOURCES')
99 env.PrependENVPath('PATHEXT', '.PY')
100 p = env.Program('prog', ['main.c', '../foo$OBJSUFFIX', 'sub/bar.c'])
101 env.Default(p)
102 """ % locals())
103
104 test.write('foo.c', """\
105 foo.c
106 """)
107
108 test.write(['src', 'main.c'], """\
109 src/main.c
110 """)
111
112 test.write(['src', 'sub', 'bar.c'], """\
113 src/sub/bar.c
114 """)
115
116 test.run()
117
118 src_prog_exe    = os.path.join('src', 'prog.exe')
119 src_main_c      = os.path.join('src', 'main.c')
120 src_main_obj    = os.path.join('src', 'main.obj')
121 src_sub_bar_c   = os.path.join('src', 'sub', 'bar.c')
122 src_sub_bar_obj = os.path.join('src', 'sub', 'bar.obj')
123
124 expect = """\
125 fake_link.py:  ['%(fake_link_py)s', '%(src_prog_exe)s', '%(src_main_obj)s', 'foo.obj', '%(src_sub_bar_obj)s']
126 fake_cc.py:  ['%(fake_cc_py)s', '%(src_main_obj)s', '%(src_main_c)s']
127 src/main.c
128 fake_cc.py:  ['%(fake_cc_py)s', 'foo.obj', 'foo.c']
129 foo.c
130 fake_cc.py:  ['%(fake_cc_py)s', '%(src_sub_bar_obj)s', '%(src_sub_bar_c)s']
131 src/sub/bar.c
132 """ % locals()
133
134 if os.sep == '\\':
135     expect = expect.replace('\\', '\\\\')
136
137 test.must_match(['src', 'prog.exe'], expect)
138
139 test.up_to_date(chdir='src', arguments = test.workpath())
140
141 test.up_to_date(arguments = '.')
142
143 test.pass_test()
144
145 # Local Variables:
146 # tab-width:4
147 # indent-tabs-mode:nil
148 # End:
149 # vim: set expandtab tabstop=4 shiftwidth=4: