Remove (lots) more unnecessary imports.
[scons.git] / test / Libs / LIBPATH.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.path
28 import time
29
30 import TestSCons
31
32 _exe = TestSCons._exe
33 _dll = TestSCons._dll
34 dll_ = TestSCons.dll_
35     
36 test = TestSCons.TestSCons()
37
38 test.subdir('lib1', 'lib2')
39
40 prog1 = test.workpath('prog') + _exe
41 prog2 = test.workpath(dll_ + 'shlib') + _dll
42
43 test.write('SConstruct', """
44 env1 = Environment(LIBS = [ 'foo1' ],
45                    LIBPATH = [ '$FOO' ],
46                    FOO='./lib1')
47
48 f1 = env1.SharedObject('f1', 'f1.c')
49
50 env1.Program(target = 'prog', source = 'prog.c')
51 env1.Library(target = './lib1/foo1', source = f1)
52
53 env2 = Environment(LIBS = 'foo2',
54                    LIBPATH = '.')
55 env2.SharedLibrary(target = 'shlib', source = 'shlib.c', no_import_lib = 1)
56 env2.Library(target = 'foo2', source = f1)
57 """)
58
59 test.write('f1.c', r"""
60 #include <stdio.h>
61
62 void
63 f1(void)
64 {
65         printf("f1.c\n");
66 }
67 """)
68
69 test.write('shlib.c', r"""
70 void f1(void);
71 int
72 test()
73 {
74     f1();
75     return 0;
76 }
77 """)
78
79 test.write('prog.c', r"""
80 #include <stdio.h>
81
82 void f1(void);
83 int
84 main(int argc, char *argv[])
85 {
86         argv[argc++] = "--";
87         f1();
88         printf("prog.c\n");
89         return 0;
90 }
91 """)
92
93 test.run(arguments = '.',
94          stderr=TestSCons.noisy_ar,
95          match=TestSCons.match_re_dotall)
96
97 test.run(program = prog1,
98          stdout = "f1.c\nprog.c\n")
99
100 oldtime1 = os.path.getmtime(prog1)
101 oldtime2 = os.path.getmtime(prog2)
102 time.sleep(2)
103 test.run(arguments = '.')
104
105 test.fail_test(oldtime1 != os.path.getmtime(prog1))
106 test.fail_test(oldtime2 != os.path.getmtime(prog2))
107
108 test.write('f1.c', r"""
109 #include <stdio.h>
110
111 void
112 f1(void)
113 {
114         printf("f1.c 1\n");
115 }
116 """)
117
118 test.run(arguments = '.',
119          stderr=TestSCons.noisy_ar,
120          match=TestSCons.match_re_dotall)
121 test.run(program = prog1,
122          stdout = "f1.c 1\nprog.c\n")
123 test.fail_test(oldtime2 == os.path.getmtime(prog2))
124 #test.up_to_date(arguments = '.')
125 # Change LIBPATH and make sure we don't rebuild because of it.
126 test.write('SConstruct', """
127 env1 = Environment(LIBS = [ 'foo1' ],
128                   LIBPATH = [ './lib1', './lib2' ])
129
130 f1 = env1.SharedObject('f1', 'f1.c')
131
132 env1.Program(target = 'prog', source = 'prog.c')
133 env1.Library(target = './lib1/foo1', source = f1)
134
135 env2 = Environment(LIBS = 'foo2',
136                    LIBPATH = Split('. ./lib2'))
137 env2.SharedLibrary(target = 'shlib', source = 'shlib.c', no_import_lib = 1)
138 env2.Library(target = 'foo2', source = f1)
139 """)
140
141 test.up_to_date(arguments = '.', stderr=None)
142
143 test.write('f1.c', r"""
144 #include <stdio.h>
145
146 void
147 f1(void)
148 {
149         printf("f1.c 2\n");
150 }
151 """)
152
153 test.run(arguments = '.',
154          stderr=TestSCons.noisy_ar,
155          match=TestSCons.match_re_dotall)
156 test.run(program = prog1,
157          stdout = "f1.c 2\nprog.c\n")
158
159 test.up_to_date(arguments = '.')
160
161 # We need at least one file for some implementations of the Library
162 # builder, notably the SGI one.
163 test.write('empty.c', 'int a=0;\n')
164
165 # Check that a null-string LIBPATH doesn't blow up.
166 test.write('SConstruct', """
167 env = Environment(LIBPATH = '')
168 env.Library('foo', source = 'empty.c')
169 """)
170
171 test.run(arguments = '.',
172          stderr=TestSCons.noisy_ar,
173          match=TestSCons.match_re_dotall)
174
175 test.pass_test()