Fix tests on systems where 'ar' prints warnings about creating archives. (Kevin...
[scons.git] / test / RANLIB.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 import os
28 import os.path
29 import string
30 import sys
31 import TestSCons
32
33 python = TestSCons.python
34
35 _exe = TestSCons._exe
36
37 test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
38
39 ranlib = test.detect('RANLIB', 'ranlib')
40
41 test.no_result(not ranlib)
42
43 test.write("wrapper.py",
44 """import os
45 import string
46 import sys
47 open('%s', 'wb').write("wrapper.py\\n")
48 os.system(string.join(sys.argv[1:], " "))
49 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
50
51 test.write('SConstruct', """
52 foo = Environment(LIBS = ['foo'], LIBPATH = ['.'])
53 ranlib = foo.Dictionary('RANLIB')
54 bar = Environment(LIBS = ['bar'], LIBPATH = ['.'],
55                   RANLIB = r'%s wrapper.py ' + ranlib)
56 foo.Library(target = 'foo', source = 'foo.c')
57 bar.Library(target = 'bar', source = 'bar.c')
58
59 main = foo.Object('main', 'main.c')
60
61 foo.Program(target = 'f', source = main)
62 bar.Program(target = 'b', source = main)
63 """ % python)
64
65 test.write('foo.c', r"""
66 void
67 library_function(void)
68 {
69         printf("foo.c\n");
70 }
71 """)
72
73 test.write('bar.c', r"""
74 void
75 library_function(void)
76 {
77         printf("bar.c\n");
78 }
79 """)
80
81 test.write('main.c', r"""
82 int
83 main(int argc, char *argv[])
84 {
85         argv[argc++] = "--";
86         library_function();
87         exit (0);
88 }
89 """)
90
91
92 test.run(arguments = 'f' + _exe, stderr=TestSCons.noisy_ar)
93
94 test.fail_test(os.path.exists(test.workpath('wrapper.out')))
95
96 test.run(arguments = 'b' + _exe, stderr=TestSCons.noisy_ar)
97
98 test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
99
100 test.pass_test()