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 the FindPathDirs() function (actually a class)
29 can be used to specify a path_function of a scanner.
34 _python_ = TestSCons._python_
36 test = TestSCons.TestSCons()
38 test.subdir('inc1', 'inc2')
40 test.write('build.py', r"""
44 path = string.split(sys.argv[1])
45 input = open(sys.argv[2], 'rb')
46 output = open(sys.argv[3], 'wb')
55 def process(infp, outfp):
56 for line in infp.readlines():
57 if line[:8] == 'include ':
59 process(find_file(file), outfp)
63 process(input, output)
68 # Execute a subsidiary SConscript just to make sure we can
69 # get at the Scanner keyword from there.
71 test.write('SConstruct', """\
72 SConscript('SConscript')
75 test.write('SConscript', """\
79 include_re = re.compile(r'^include\s+(\S+)$', re.M)
81 def kfile_scan(node, env, path, arg):
82 contents = node.get_text_contents()
83 includes = include_re.findall(contents)
89 file = str(dir) + os.sep + inc
90 if os.path.exists(file):
95 kscan = Scanner(name = 'kfile',
96 function = kfile_scan,
99 path_function = FindPathDirs('KPATH'))
101 ##########################################################
102 # Test scanner as found automatically from the environment
103 # (backup_source_scanner)
105 env = Environment(KPATH=['inc1', 'inc2'])
106 env.Append(SCANNERS = kscan)
108 env.Command('foo', 'foo.k', r'%(_python_)s build.py "$KPATH" $SOURCES $TARGET')
120 test.write(['inc1', 'xxx'], "inc1/xxx 1\n")
121 test.write(['inc2', 'yyy'], "inc2/yyy 1\n")
128 test.must_match('foo', "foo.k 1 line 1\ninc1/xxx 1\ninc2/yyy 1\nfoo.k 1 line 4\n")
130 test.up_to_date(arguments = '.')
134 test.write(['inc1', 'xxx'], "inc1/xxx 2\n")
138 test.must_match('foo', "foo.k 1 line 1\ninc1/xxx 2\ninc2/yyy 1\nfoo.k 1 line 4\n")
142 test.write(['inc1', 'yyy'], "inc1/yyy 2\n")
146 test.must_match('foo', "foo.k 1 line 1\ninc1/xxx 2\ninc1/yyy 2\nfoo.k 1 line 4\n")
154 # indent-tabs-mode:nil
156 # vim: set expandtab tabstop=4 shiftwidth=4: