Added fix for TeX includes with same name as subdirs.
[scons.git] / test / WhereIs.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 import os
28 import sys
29
30 import TestSCons
31
32 test = TestSCons.TestSCons()
33
34 subdir_SConscript = os.path.join('subdir', 'SConscript')
35 sub1_xxx_exe = test.workpath('sub1', 'xxx.exe')
36 sub2_xxx_exe = test.workpath('sub2', 'xxx.exe')
37 sub3_xxx_exe = test.workpath('sub3', 'xxx.exe')
38 sub4_xxx_exe = test.workpath('sub4', 'xxx.exe')
39
40 test.subdir('subdir', 'sub1', 'sub2', 'sub3', 'sub4')
41
42 if sys.platform != 'win32':
43     test.write(sub1_xxx_exe, "\n")
44
45 os.mkdir(sub2_xxx_exe)
46
47 test.write(sub3_xxx_exe, "\n")
48 os.chmod(sub3_xxx_exe, 0777)
49
50 test.write(sub4_xxx_exe, "\n")
51 os.chmod(sub4_xxx_exe, 0777)
52
53 env_path = os.environ['PATH']
54
55 pathdirs_1234 = [ test.workpath('sub1'),
56                   test.workpath('sub2'),
57                   test.workpath('sub3'),
58                   test.workpath('sub4'),
59                 ] + env_path.split(os.pathsep)
60
61 pathdirs_1243 = [ test.workpath('sub1'),
62                   test.workpath('sub2'),
63                   test.workpath('sub4'),
64                   test.workpath('sub3'),
65                 ] + env_path.split(os.pathsep)
66
67 test.write('SConstruct', """
68 SConscript('%s')
69 env = Environment()
70 print WhereIs('xxx.exe')
71 print WhereIs('xxx.exe', %s)
72 print env.WhereIs('xxx.exe', %s)
73 print WhereIs('xxx.exe', %s)
74 print WhereIs('xxx.exe', %s)
75 print WhereIs('xxx.exe', %s, reject=%s)
76 env.Replace( XXXNAME='xxx.exe' )
77 print env.WhereIs( '$XXXNAME', %s )
78 """ % (subdir_SConscript,
79        repr(os.pathsep.join(pathdirs_1234)),
80        repr(os.pathsep.join(pathdirs_1243)),
81        repr(pathdirs_1234),
82        repr(pathdirs_1243),
83        repr(pathdirs_1243),
84        repr(sub4_xxx_exe),
85        repr(os.pathsep.join(pathdirs_1243)),
86       ))
87
88 test.write(subdir_SConscript, """
89 env = Environment()
90 print WhereIs('xxx.exe')
91 print WhereIs('xxx.exe', %s)
92 print env.WhereIs('xxx.exe', %s)
93 print WhereIs('xxx.exe', %s)
94 print WhereIs('xxx.exe', %s)
95 """ % (repr(os.pathsep.join(pathdirs_1234)),
96        repr(os.pathsep.join(pathdirs_1243)),
97        repr(pathdirs_1234),
98        repr(pathdirs_1243),
99       ))
100
101 os.environ['PATH'] = os.pathsep.join(pathdirs_1234)
102
103 expect = [ test.workpath(sub3_xxx_exe),
104            test.workpath(sub3_xxx_exe),
105            test.workpath(sub4_xxx_exe),
106            test.workpath(sub3_xxx_exe),
107            test.workpath(sub4_xxx_exe),
108            test.workpath(sub3_xxx_exe),
109            test.workpath(sub3_xxx_exe),
110            test.workpath(sub4_xxx_exe),
111            test.workpath(sub3_xxx_exe),
112            test.workpath(sub4_xxx_exe),
113            test.workpath(sub3_xxx_exe),
114            test.workpath(sub4_xxx_exe)
115          ]
116
117 test.run(arguments = ".",
118          stdout = test.wrap_stdout(read_str = "\n".join(expect) + "\n",
119                                    build_str = "scons: `.' is up to date.\n"))
120
121 os.environ['PATH'] = os.pathsep.join(pathdirs_1243)
122
123 expect = [ test.workpath(sub4_xxx_exe),
124            test.workpath(sub3_xxx_exe),
125            test.workpath(sub4_xxx_exe),
126            test.workpath(sub3_xxx_exe),
127            test.workpath(sub4_xxx_exe),
128            test.workpath(sub4_xxx_exe),
129            test.workpath(sub3_xxx_exe),
130            test.workpath(sub4_xxx_exe),
131            test.workpath(sub3_xxx_exe),
132            test.workpath(sub4_xxx_exe),
133            test.workpath(sub3_xxx_exe),
134            test.workpath(sub4_xxx_exe)
135          ]
136
137 test.run(arguments = ".",
138          stdout = test.wrap_stdout(read_str = "\n".join(expect) + "\n",
139                                    build_str = "scons: `.' is up to date.\n"))
140
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: