Remove more unnecessary imports from test scripts.
[scons.git] / test / implicit / IMPLICIT_COMMAND_DEPENDENCIES.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 Verify that the $IMPLICIT_COMMAND_DEPENDENCIES variable controls
29 whether or not the implicit dependency on executed commands
30 is added to targets.
31 """
32
33 import TestSCons
34
35 python = TestSCons.python
36 _python_ = TestSCons._python_
37
38 test = TestSCons.TestSCons()
39
40 generate_build_py_py_contents = """\
41 #!%(python)s
42 import os
43 import sys
44
45 open(sys.argv[1], 'w').write('''\
46 #!/usr/bin/env %(python)s
47 import os
48 import string
49 import sys
50 fp = open(sys.argv[1], 'wb')
51 args = [os.path.split(sys.argv[0])[1]] + sys.argv[1:]
52 fp.write(string.join(args) + '\\\\n' + '%(extra)s')
53 for infile in sys.argv[2:]:
54     fp.write(open(infile, 'rb').read())
55 fp.close()
56 ''')
57 os.chmod(sys.argv[1], 0755)
58
59 """
60
61 extra = ''
62 test.write('generate_build_py.py', generate_build_py_py_contents % locals())
63
64 test.write('SConstruct', """
65 generate = Builder(action = r'%(_python_)s $GENERATE $TARGET')
66 build = Builder(action = r'$BUILD_PY $TARGET $SOURCES')
67 env = Environment(BUILDERS = {
68                         'GenerateBuild' : generate,
69                         'BuildFile' : build,
70                   },
71                   GENERATE = 'generate_build_py.py',
72                   BUILD_PY = 'build.py',
73                   )
74 env.PrependENVPath('PATH', '.')
75 env.PrependENVPath('PATHEXT', '.PY')
76 env0        = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = 0)
77 env1        = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = 1)
78 envNone     = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = None)
79 envFalse    = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = False)
80 envTrue     = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = True)
81
82 build_py = env.GenerateBuild('${BUILD_PY}', [])
83 AlwaysBuild(build_py)
84
85 env.BuildFile('file.out',               'file.in')
86 env0.BuildFile('file0.out',             'file.in')
87 env1.BuildFile('file1.out',             'file.in')
88 envNone.BuildFile('fileNone.out',       'file.in')
89 envFalse.BuildFile('fileFalse.out',     'file.in')
90 envTrue.BuildFile('fileTrue.out',       'file.in')
91 envTrue.BuildFile('fileQuote.out',      'file.in', BUILD_PY='"build.py"')
92 """ % locals())
93
94
95
96 test.write('file.in',     "file.in\n")
97
98 test.run(arguments = '--tree=all .')
99
100 expect_none = 'build.py %s file.in\nfile.in\n'
101
102 test.must_match('file.out',         expect_none % 'file.out')
103 test.must_match('file0.out',        expect_none % 'file0.out')
104 test.must_match('file1.out',        expect_none % 'file1.out')
105 test.must_match('fileNone.out',     expect_none % 'fileNone.out')
106 test.must_match('fileFalse.out',    expect_none % 'fileFalse.out')
107 test.must_match('fileTrue.out',     expect_none % 'fileTrue.out')
108 test.must_match('fileQuote.out',    expect_none % 'fileQuote.out')
109
110
111
112 extra = 'xyzzy\\\\n'
113 test.write('generate_build_py.py', generate_build_py_py_contents % locals())
114
115 test.run(arguments = '--tree=all .')
116
117 expect_extra = 'build.py %s file.in\nxyzzy\nfile.in\n'
118
119 test.must_match('file.out',         expect_extra % 'file.out')
120 test.must_match('file0.out',        expect_none % 'file0.out')
121 test.must_match('file1.out',        expect_extra % 'file1.out')
122 test.must_match('fileNone.out',     expect_none % 'fileNone.out')
123 test.must_match('fileFalse.out',    expect_none % 'fileFalse.out')
124 test.must_match('fileTrue.out',     expect_extra % 'fileTrue.out')
125 test.must_match('fileQuote.out',    expect_extra % 'fileQuote.out')
126
127
128 test.pass_test()
129
130 # Local Variables:
131 # tab-width:4
132 # indent-tabs-mode:nil
133 # End:
134 # vim: set expandtab tabstop=4 shiftwidth=4: