3 # Copyright (c) 2001, 2002 Steven Knight
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__"
32 python = sys.executable
34 if sys.platform == 'win32':
39 test = TestSCons.TestSCons()
43 if sys.platform == 'win32':
45 test.write('mylink.py', r"""
54 if string.lower(a[:5]) == '/out:': out = a[5:]
55 infile = open(args[0], 'rb')
56 outfile = open(out, 'wb')
57 for l in infile.readlines():
63 test.write('myas.py', r"""
74 if a[:3] == '/Fo': out = a[3:]
75 infile = open(inf, 'rb')
76 outfile = open(out, 'wb')
77 for l in infile.readlines():
85 test.write('mylink.py', r"""
88 opts, args = getopt.getopt(sys.argv[1:], 'o:')
90 if opt == '-o': out = arg
91 infile = open(args[0], 'rb')
92 outfile = open(out, 'wb')
93 for l in infile.readlines():
99 test.write('myas.py', r"""
102 opts, args = getopt.getopt(sys.argv[1:], 'co:')
103 for opt, arg in opts:
104 if opt == '-o': out = arg
105 infile = open(args[0], 'rb')
106 outfile = open(out, 'wb')
107 for l in infile.readlines():
113 test.write('SConstruct', """
114 env = Environment(LINK = r'%s mylink.py',
117 env.Program(target = 'test1', source = 'test1.s')
118 env.Program(target = 'test2', source = 'test2.S')
119 env.Program(target = 'test3', source = 'test3.asm')
120 env.Program(target = 'test4', source = 'test4.ASM')
121 env.Program(target = 'test5', source = 'test5.spp')
122 env.Program(target = 'test6', source = 'test6.SPP')
123 """ % (python, python, python))
125 test.write('test1.s', r"""This is a .s file.
130 test.write('test2.S', r"""This is a .S file.
135 test.write('test3.asm', r"""This is a .asm file.
140 test.write('test4.ASM', r"""This is a .ASM file.
145 test.write('test5.spp', r"""This is a .spp file.
150 test.write('test6.SPP', r"""This is a .SPP file.
155 test.run(arguments = '.', stderr = None)
157 test.fail_test(test.read('test1' + _exe) != "This is a .s file.\n")
159 test.fail_test(test.read('test2' + _exe) != "This is a .S file.\n")
161 test.fail_test(test.read('test3' + _exe) != "This is a .asm file.\n")
163 test.fail_test(test.read('test4' + _exe) != "This is a .ASM file.\n")
165 test.fail_test(test.read('test5' + _exe) != "This is a .spp file.\n")
167 test.fail_test(test.read('test6' + _exe) != "This is a .SPP file.\n")
170 as = test.detect('AS', 'as')
174 test.write("wrapper.py",
178 open('%s', 'wb').write("wrapper.py\\n")
179 os.system(string.join(sys.argv[1:], " "))
180 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
182 test.write('SConstruct', """
184 bbb = aaa.Copy(AS = r'%s wrapper.py ' + WhereIs('as'))
185 aaa.Program(target = 'aaa', source = ['aaa.s', 'aaa_main.c'])
186 bbb.Program(target = 'bbb', source = ['bbb.s', 'bbb_main.c'])
209 test.write('aaa_main.c', r"""
213 main(int argc, char *argv[])
216 printf("aaa_main.c %s\n", name);
221 test.write('bbb_main.c', r"""
225 main(int argc, char *argv[])
228 printf("bbb_main.c %s\n", name);
233 test.run(arguments = 'aaa' + _exe, stderr = None)
235 test.run(program = test.workpath('aaa'), stdout = "aaa_main.c aaa.s\n")
237 test.fail_test(os.path.exists(test.workpath('wrapper.out')))
239 test.run(arguments = 'bbb' + _exe)
241 test.run(program = test.workpath('bbb'), stdout = "bbb_main.c bbb.s\n")
243 test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
245 test.unlink('wrapper.out')
249 ml = test.where_is('ml')
253 test.write("wrapper.py",
257 open('%s', 'wb').write("wrapper.py\\n")
258 os.system(string.join(sys.argv[1:], " "))
259 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
261 test.write('SConstruct', """
263 ccc = Environment(tools = ['msvc', 'mslink', 'masm'],
264 ASFLAGS = '/nologo /coff')
265 ccc['ENV']['PATH'] = os.environ['PATH']
266 ddd = ccc.Copy(AS = r'%s wrapper.py ' + ccc['AS'])
267 ccc.Program(target = 'ccc', source = ['ccc.asm', 'ccc_main.c'])
268 ddd.Program(target = 'ddd', source = ['ddd.asm', 'ddd_main.c'])
271 test.write('ccc.asm',
275 _name byte "ccc.asm",0
280 test.write('ddd.asm',
284 _name byte "ddd.asm",0
289 test.write('ccc_main.c', r"""
293 main(int argc, char *argv[])
296 printf("ccc_main.c %s\n", name);
301 test.write('ddd_main.c', r"""
305 main(int argc, char *argv[])
308 printf("ddd_main.c %s\n", name);
313 test.run(arguments = 'ccc' + _exe, stderr = None)
315 test.run(program = test.workpath('ccc'), stdout = "ccc_main.c ccc.asm\n")
317 test.fail_test(os.path.exists(test.workpath('wrapper.out')))
319 test.run(arguments = 'ddd' + _exe)
321 test.run(program = test.workpath('ddd'), stdout = "ddd_main.c ddd.asm\n")
323 test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
328 nasm = test.where_is('nasm')
332 test.write("wrapper.py",
336 open('%s', 'wb').write("wrapper.py\\n")
337 os.system(string.join(sys.argv[1:], " "))
338 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
340 test.write('SConstruct', """
341 eee = Environment(tools = ['gcc', 'gnulink', 'nasm'],
343 fff = eee.Copy(AS = r'%s wrapper.py ' + WhereIs('nasm'))
344 eee.Program(target = 'eee', source = ['eee.asm', 'eee_main.c'])
345 fff.Program(target = 'fff', source = ['fff.asm', 'fff_main.c'])
348 test.write('eee.asm',
355 test.write('fff.asm',
362 test.write('eee_main.c', r"""
366 main(int argc, char *argv[])
369 printf("eee_main.c %s\n", name);
374 test.write('fff_main.c', r"""
378 main(int argc, char *argv[])
381 printf("fff_main.c %s\n", name);
386 test.run(arguments = 'eee' + _exe, stderr = None)
388 test.run(program = test.workpath('eee'), stdout = "eee_main.c eee.asm\n")
390 test.fail_test(os.path.exists(test.workpath('wrapper.out')))
392 test.run(arguments = 'fff' + _exe)
394 test.run(program = test.workpath('fff'), stdout = "fff_main.c fff.asm\n")
396 test.fail_test(test.read('wrapper.out') != "wrapper.py\n")