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