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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
28 Verify that use of a Scanner that searches a *PATH list doesn't create
29 nodes for directories that don't exist, so they don't get picked up
32 Under the covers, this tests the behavior of the SCons.Node.FS.find_file()
33 utility function that is used by the Scanner.Classic class to search
34 directories in variables such as $CPPPATH.
41 _python_ = TestSCons._python_
43 test = TestSCons.TestSCons()
45 subdir_SConscript = os.path.join('subdir', 'SConscript')
46 subdir_foo = os.path.join('subdir', 'foo')
47 subdir_foo_k = os.path.join('subdir', 'foo.k')
49 test.subdir('subdir', 'inc1', 'inc2')
51 inc2_include_h = test.workpath('inc2', 'include.h')
53 test.write('build.py', r"""
56 path = sys.argv[1].split()
57 input = open(sys.argv[2], 'rb')
58 output = open(sys.argv[3], 'wb')
69 def process(infp, outfp):
70 for line in infp.readlines():
71 if line[:8] == 'include ':
73 process(find_file(file), outfp)
77 process(input, output)
82 test.write('SConstruct', """\
83 def foo(target, source, env):
84 children = source[0].children()
85 children.sort(lambda a,b: cmp(a.name, b.name))
86 fp = open(str(target[0]), 'wb')
90 Command('list.out', 'subdir', foo, source_scanner = DirScanner)
91 SConscript('subdir/SConscript')
94 test.write(['subdir', 'SConscript'], """\
96 kscan = SCons.Scanner.Classic(name = 'kfile',
98 path_variable = 'KPATH',
99 regex = r'^include\s+(\S+)$')
101 env = Environment(KPATH=['.', '..'])
102 env.Append(SCANNERS = kscan)
104 env.Command('foo', 'foo.k', r'%(_python_)s build.py "$KPATH" $SOURCES $TARGET')
107 test.write(['subdir', 'foo.k'], """\
109 include inc1/include.h
110 include %(inc2_include_h)s
113 test.write(['inc1', 'include.h'], """\
117 test.write(['inc2', 'include.h'], """\
121 test.run(arguments = '.')
123 test.must_match('subdir/foo', """\
129 test.must_match('list.out', """\
130 %(subdir_SConscript)s
139 # indent-tabs-mode:nil
141 # vim: set expandtab tabstop=4 shiftwidth=4: