Updates and slight refactor in fix
[scons.git] / test / toolpath / basic.py
blob0d2429e91279f34eb1b7a93584b47398c85c386b
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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 import TestSCons
30 test = TestSCons.TestSCons()
32 test.write('SConstruct', """
33 def foo(env):
34 env['TOOL_FOO'] = 1
36 env1 = Environment(tools=[foo, 'bar'], toolpath=['tools'])
37 print("env1['TOOL_FOO'] = %s"%env1.get('TOOL_FOO'))
38 print("env1['TOOL_BAR'] = %s"%env1.get('TOOL_BAR'))
40 # pick a built-in tool with pretty simple behavior
41 env2 = Environment(tools=['zip'])
42 print("env2['ZIP'] = %s"%env2.get('ZIP'))
43 print("env2['TOOL_zip1'] = %s"%env2.get('TOOL_zip1'))
44 print("env2['TOOLDIR_zip'] = %s"%env2.get('TOOLDIR_zip'))
46 # Only find tools in current dir, or Scons.Tool.TOOLNAME
47 env3 = Environment(tools=['zip'], toolpath=['.'])
48 print("env3['ZIP'] = %s"%env3.get('ZIP'))
49 print("env3['TOOL_zip1'] = %s"%env3.get('TOOL_zip1'))
50 print("env3['TOOLDIR_zip'] = %s"%env3.get('TOOLDIR_zip'))
52 env4 = Environment(tools=['zip'], toolpath=['tools'])
53 print("env4['ZIP'] = %s"%env4.get('ZIP'))
54 print("env4['TOOL_zip1'] = %s"%env4.get('TOOL_zip1'))
55 print("env4['TOOLDIR_zip'] = %s"%env4.get('TOOLDIR_zip'))
57 # Should pick up from tools dir, and then current dir
58 env5 = Environment(tools=['zip'], toolpath=['tools', '.'])
59 print("env5['ZIP'] = %s"%env5.get('ZIP'))
60 print("env5['TOOL_zip1'] = %s"%env5.get('TOOL_zip1'))
61 print("env5['TOOLDIR_zip'] = %s"%env5.get('TOOLDIR_zip'))
64 # Should pick up from current dir, and then tools dir
65 env6 = Environment(tools=['zip'], toolpath=['.', 'tools'])
66 print("env6['ZIP'] = %s"%env6.get('ZIP'))
67 print("env6['TOOL_zip1'] = %s"%env6.get('TOOL_zip1'))
68 print("env6['TOOLDIR_zip'] = %s"%env6.get('TOOLDIR_zip'))
70 env7 = Environment(TOOLPATH="tools", tools=['zip'], toolpath=['$TOOLPATH'])
71 print("env7['ZIP'] = %s"%env7.get('ZIP'))
72 print("env7['TOOL_zip1'] = %s"%env7.get('TOOL_zip1'))
73 print("env7['TOOLDIR_zip'] = %s"%env7.get('TOOLDIR_zip'))
75 env8 = Environment(tools=[])
76 env8.Tool('zip', toolpath=['tools'])
77 print("env8['ZIP'] = %s"%env8.get('ZIP'))
78 print("env8['TOOL_zip1'] = %s"%env8.get('TOOL_zip1'))
79 print("env8['TOOLDIR_zip'] = %s"%env8.get('TOOLDIR_zip'))
81 env9 = Environment(tools=[])
82 Tool('zip', toolpath=['tools'])(env9)
83 print("env9['ZIP'] = %s"%env9.get('ZIP'))
84 print("env9['TOOL_zip1'] = %s"%env9.get('TOOL_zip1'))
85 print("env9['TOOLDIR_zip'] = %s"%env9.get('TOOLDIR_zip'))
87 env0 = Environment(TOOLPATH='tools', tools=[])
88 env0.Tool('zip', toolpath=['$TOOLPATH'])
89 print("env0['ZIP'] = %s"%env0.get('ZIP'))
90 print("env0['TOOL_zip1'] = %s"%env0.get('TOOL_zip1'))
91 print("env0['TOOLDIR_zip'] = %s"%env0.get('TOOLDIR_zip'))
93 base = Environment(tools=[], toolpath=['tools'])
94 derived = base.Clone(tools=['bar'])
95 print("derived['TOOL_BAR'] = %s"%derived.get('TOOL_BAR'))
96 """)
98 test.write('zip.py', r"""
99 def generate(env):
100 env['TOOL_zip1'] = 1
101 def exists(env):
102 return 1
103 """,mode='w')
105 test.subdir('tools')
107 test.write(['tools', 'Common.py'], r"""\
108 One = 1
109 """)
111 test.write(['tools', 'zip.py'], r"""\
112 import Common
113 def generate(env):
114 env['TOOLDIR_zip'] = Common.One
115 def exists(env):
116 return Common.One
117 """)
119 test.write(['tools', 'bar.py'], r"""\
120 def generate(env):
121 env['TOOL_BAR'] = 1
122 def exists(env):
123 return 1
124 """)
126 test.run(arguments = '.', stdout = """\
127 scons: Reading SConscript files ...
128 env1['TOOL_FOO'] = 1
129 env1['TOOL_BAR'] = 1
130 env2['ZIP'] = zip
131 env2['TOOL_zip1'] = None
132 env2['TOOLDIR_zip'] = None
133 env3['ZIP'] = None
134 env3['TOOL_zip1'] = 1
135 env3['TOOLDIR_zip'] = None
136 env4['ZIP'] = None
137 env4['TOOL_zip1'] = None
138 env4['TOOLDIR_zip'] = 1
139 env5['ZIP'] = None
140 env5['TOOL_zip1'] = None
141 env5['TOOLDIR_zip'] = 1
142 env6['ZIP'] = None
143 env6['TOOL_zip1'] = 1
144 env6['TOOLDIR_zip'] = None
145 env7['ZIP'] = None
146 env7['TOOL_zip1'] = None
147 env7['TOOLDIR_zip'] = 1
148 env8['ZIP'] = None
149 env8['TOOL_zip1'] = None
150 env8['TOOLDIR_zip'] = 1
151 env9['ZIP'] = None
152 env9['TOOL_zip1'] = None
153 env9['TOOLDIR_zip'] = 1
154 env0['ZIP'] = None
155 env0['TOOL_zip1'] = None
156 env0['TOOLDIR_zip'] = 1
157 derived['TOOL_BAR'] = 1
158 scons: done reading SConscript files.
159 scons: Building targets ...
160 scons: `.' is up to date.
161 scons: done building targets.
162 """)
164 test.pass_test()
166 # Local Variables:
167 # tab-width:4
168 # indent-tabs-mode:nil
169 # End:
170 # vim: set expandtab tabstop=4 shiftwidth=4: