[ci skip] multi-user should be multiuser
[scons.git] / test / long-lines / signature.py
blobef1b956c7509c29449fa7f9c3a63347b36349b8b
1 #!/usr/bin/env python
3 # MIT License
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.
26 """
27 Verify that use of long command lines correctly excludes arguments
28 surrounded by $( $) from the signature calculation.
29 """
31 import os
32 import TestSCons
34 _python_ = TestSCons._python_
36 test = TestSCons.TestSCons()
38 build_py = test.workpath('build.py')
40 # create a dummy command which understands a tempfile syntax
41 # so it doesn't have to be that platform/compiler's specific syntax.
42 test.write(build_py, """\
43 #!%(_python_)s
44 import sys
45 if sys.argv[1].startswith('@'):
46 tempfile = sys.argv[1][1:]
47 with open(tempfile, 'r') as tmp:
48 args = tmp.read().split()
49 else:
50 args = sys.argv[1:]
52 with open(args[0], 'w') as ofp, open(args[1], 'r') as ifp:
53 ofp.write(ifp.read())
54 ofp.write('FILEFLAG=%%s\\n' %% args[2])
55 ofp.write('TIMESTAMP=%%s\\n' %% args[3])
56 """ % locals())
58 os.chmod(build_py, 0o755)
60 test.write('SConstruct', """\
61 DefaultEnvironment(tools=[])
62 arg = 'a_long_ignored_argument'
63 extra_arguments = arg
64 MAXLINE=1024
65 while len(extra_arguments) <= MAXLINE:
66 extra_arguments = extra_arguments + ' ' + arg
67 env = Environment(
68 tools=[],
69 FILECOM=[
70 r'%(build_py)s',
71 '$TARGET',
72 '$SOURCE',
73 '$FILEFLAG',
74 '$(',
75 '$TIMESTAMP',
76 '$)',
77 '$EXTRA_ARGUMENTS',
79 FILEFLAG=ARGUMENTS.get('FILEFLAG'),
80 TIMESTAMP=ARGUMENTS.get('TIMESTAMP'),
81 EXTRA_ARGUMENTS=extra_arguments,
82 MAXLINELENGTH=MAXLINE,
83 TEMPFILEPREFIX='@',
85 env.PrependENVPath('PATHEXT', '.PY')
86 env.Command('file.out', 'file.in', r'%(_python_)s ${TEMPFILE(FILECOM)}')
87 """ % locals())
89 test.write('file.in', "file.in\n", mode='w')
91 test.run(arguments='FILEFLAG=first TIMESTAMP=20090207 .')
93 test.must_match('file.out', "file.in\nFILEFLAG=first\nTIMESTAMP=20090207\n", mode='r')
95 test.up_to_date(options='FILEFLAG=first TIMESTAMP=20090208', arguments = '.')
97 test.run(arguments='FILEFLAG=second TIMESTAMP=20090208 .')
99 test.must_match('file.out', "file.in\nFILEFLAG=second\nTIMESTAMP=20090208\n", mode='r')
101 test.up_to_date(options='FILEFLAG=second TIMESTAMP=20090209', arguments = '.')
103 test.pass_test()
105 # Local Variables:
106 # tab-width:4
107 # indent-tabs-mode:nil
108 # End:
109 # vim: set expandtab tabstop=4 shiftwidth=4: