5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 Test that detection of file-writing options in LEXFLAGS works.
28 Also test that construction vars for the same purpose work.
32 from pathlib
import Path
35 from TestCmd
import IS_WINDOWS
37 _python_
= TestSCons
._python
_
40 test
= TestSCons
.TestSCons()
45 test
.file_fixture('mylex.py')
47 test
.write('SConstruct', """\
48 DefaultEnvironment(tools=[])
49 SConscript(dirs=['sub1', 'sub2'])
52 # this SConscript is for the options-in-flags version
53 test
.write(['sub1', 'SConscript'], f
"""\
57 LEX=r'{_python_} mylex.py',
58 LEXFLAGS='-x --header-file=header.h --tables-file=tables.t',
59 tools=['default', 'lex'],
61 targs = env.CFile(target='aaa', source='aaa.l')
62 t = [str(target) for target in targs]
63 # fail ourselves if the two extra files were not detected
64 if not all((len(t) == 3, "header.h" in t, "tables.t" in t)):
67 test
.write(['sub1', 'aaa.l'], "aaa.l\nLEXFLAGS\n")
69 # this SConscript is for the construction var version
70 test
.write(['sub2', 'SConscript'], f
"""\
74 LEX=r'{_python_} mylex.py',
76 tools=['default', 'lex'],
81 LEX_HEADER_FILE='header.h',
82 LEX_TABLES_FILE='tables.t',
85 test
.write(['sub2', 'aaa.l'], "aaa.l\nLEXFLAGS\n")
87 test
.run('.', stderr
=None)
89 lexflags
= ' -x --header-file=header.h --tables-file=tables.t -t'
90 if IS_WINDOWS
and not sysconfig
.get_platform() in ("mingw",):
91 lexflags
= ' --nounistd' + lexflags
92 # Read in with mode='r' because mylex.py implicitly wrote to stdout
94 test
.must_match(['sub1', 'aaa.c'], "aaa.l\n%s\n" % lexflags
, mode
='r')
96 # NOTE: this behavior is "wrong" but we're keeping it for compat.
97 # the generated files should go into 'sub1', not the topdir.
98 test
.must_match(['header.h'], 'lex header\n')
99 test
.must_match(['tables.t'], 'lex table\n')
101 # To confirm the files from the file-output options were tracked,
102 # we should do a clean and make sure they got removed.
103 # As noted, they currently don't go into the tracked location,
104 # so using the check in the SConscript instead.
105 #test.run(arguments='-c .')
106 #test.must_not_exist(test.workpath(['sub1', 'header.h']))
107 #test.must_not_exist(test.workpath(['sub1', 'tables.t']))
110 headerfile
= sub2
/ 'header.h'
111 tablefile
= sub2
/ 'tables.t'
112 lexflags
= f
' -x --header-file={headerfile} --tables-file={tablefile} -t'
113 if IS_WINDOWS
and not sysconfig
.get_platform() in ("mingw",):
114 lexflags
= ' --nounistd' + lexflags
115 # Read in with mode='r' because mylex.py implicitly wrote to stdout
117 test
.must_match(['sub2', 'aaa.c'], "aaa.l\n%s\n" % lexflags
, mode
='r')
118 test
.must_match(['sub2', 'header.h'], 'lex header\n')
119 test
.must_match(['sub2', 'tables.t'], 'lex table\n')
121 # To confirm the files from the file-output options were tracked,
122 # do a clean and make sure they got removed.
123 test
.run(arguments
='-c .', stderr
=None)
124 test
.must_not_exist(test
.workpath('sub2', 'header.h'))
125 test
.must_not_exist(test
.workpath('sub2', 'tables.t'))
131 # indent-tabs-mode:nil
133 # vim: set expandtab tabstop=4 shiftwidth=4: