Eliminate unnecessary WIN32/Win32/win32 references in tests, too.
[scons.git] / test / 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 TestSCons
28 import sys
29 import os.path
30 import time
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.Object('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 void
61 f1(void)
62 {
63         printf("f1.c\n");
64 }
65 """)
66
67 test.write('shlib.c', r"""
68 void f1(void);
69 int
70 test()
71 {
72     f1();
73     return 0;
74 }
75 """)
76
77 test.write('prog.c', r"""
78 void f1(void);
79 int
80 main(int argc, char *argv[])
81 {
82         argv[argc++] = "--";
83         f1();
84         printf("prog.c\n");
85         return 0;
86 }
87 """)
88
89 test.run(arguments = '.',
90          stderr=TestSCons.noisy_ar,
91          match=TestSCons.match_re_dotall)
92
93 test.run(program = prog1,
94          stdout = "f1.c\nprog.c\n")
95
96 oldtime1 = os.path.getmtime(prog1)
97 oldtime2 = os.path.getmtime(prog2)
98 time.sleep(2)
99 test.run(arguments = '.')
100
101 test.fail_test(oldtime1 != os.path.getmtime(prog1))
102 test.fail_test(oldtime2 != os.path.getmtime(prog2))
103
104 test.write('f1.c', r"""
105 void
106 f1(void)
107 {
108         printf("f1.c 1\n");
109 }
110 """)
111
112 test.run(arguments = '.',
113          stderr=TestSCons.noisy_ar,
114          match=TestSCons.match_re_dotall)
115 test.run(program = prog1,
116          stdout = "f1.c 1\nprog.c\n")
117 test.fail_test(oldtime2 == os.path.getmtime(prog2))
118 #test.up_to_date(arguments = '.')
119 # Change LIBPATH and make sure we don't rebuild because of it.
120 test.write('SConstruct', """
121 env1 = Environment(LIBS = [ 'foo1' ],
122                   LIBPATH = [ './lib1', './lib2' ])
123
124 f1 = env1.Object('f1', 'f1.c')
125
126 env1.Program(target = 'prog', source = 'prog.c')
127 env1.Library(target = './lib1/foo1', source = f1)
128
129 env2 = Environment(LIBS = 'foo2',
130                    LIBPATH = Split('. ./lib2'))
131 env2.SharedLibrary(target = 'shlib', source = 'shlib.c', no_import_lib = 1)
132 env2.Library(target = 'foo2', source = f1)
133 """)
134
135 test.up_to_date(arguments = '.', stderr=None)
136
137 test.write('f1.c', r"""
138 void
139 f1(void)
140 {
141         printf("f1.c 2\n");
142 }
143 """)
144
145 test.run(arguments = '.',
146          stderr=TestSCons.noisy_ar,
147          match=TestSCons.match_re_dotall)
148 test.run(program = prog1,
149          stdout = "f1.c 2\nprog.c\n")
150
151 test.up_to_date(arguments = '.')
152
153 # We need at least one file for some implementations of the Library
154 # builder, notably the SGI one.
155 test.write('empty.c', 'int a=0;\n')
156
157 # Check that a null-string LIBPATH doesn't blow up.
158 test.write('SConstruct', """
159 env = Environment(LIBPATH = '')
160 env.Library('foo', source = 'empty.c')
161 """)
162
163 test.run(arguments = '.',
164          stderr=TestSCons.noisy_ar,
165          match=TestSCons.match_re_dotall)
166
167 test.pass_test()