Added fix for TeX includes with same name as subdirs.
[scons.git] / test / YACC / YACCVCGFILESUFFIX.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 Test setting the YACCVCGFILESUFFIX variable.
29 """
30
31 import TestSCons
32
33 _python_ = TestSCons._python_
34
35 test = TestSCons.TestSCons()
36
37
38
39 test.write('myyacc.py', """\
40 import getopt
41 import os.path
42 import sys
43 vcg = None
44 opts, args = getopt.getopt(sys.argv[1:], 'go:')
45 for o, a in opts:
46     if o == '-g':
47         vcg = 1
48     elif o == '-o':
49         outfile = open(a, 'wb')
50 for f in args:
51     infile = open(f, 'rb')
52     for l in [l for l in infile.readlines() if l != '/*yacc*/\\n']:
53         outfile.write(l)
54 outfile.close()
55 if vcg:
56     base, ext = os.path.splitext(args[0])
57     open(base+'.vcgsuffix', 'wb').write(" ".join(sys.argv)+'\\n')
58 sys.exit(0)
59 """)
60
61 test.write('SConstruct', """
62 env = Environment(tools=['default', 'yacc'],
63                   YACC = r'%(_python_)s myyacc.py',
64                   YACCVCGFILESUFFIX = '.vcgsuffix')
65 env.CXXFile(target = 'aaa', source = 'aaa.yy')
66 env.CXXFile(target = 'bbb', source = 'bbb.yy', YACCFLAGS = '-g')
67 """ % locals())
68
69 test.write('aaa.yy', "aaa.yy\n/*yacc*/\n")
70 test.write('bbb.yy', "bbb.yy\n/*yacc*/\n")
71
72 test.run(arguments = '.')
73
74 test.must_match('aaa.cc', "aaa.yy\n")
75 test.must_not_exist('aaa.vcg')
76 test.must_not_exist('aaa.vcgsuffix')
77
78 test.must_match('bbb.cc', "bbb.yy\n")
79 test.must_not_exist('bbb.vcg')
80 test.must_match('bbb.vcgsuffix', "myyacc.py -g -o bbb.cc bbb.yy\n")
81
82 test.up_to_date(arguments = '.')
83
84
85
86 test.pass_test()
87
88 # Local Variables:
89 # tab-width:4
90 # indent-tabs-mode:nil
91 # End:
92 # vim: set expandtab tabstop=4 shiftwidth=4: