0176c07925a0a94400b93856499d20cd6dd8a31e
[scons.git] / test / LIBPATH.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2001, 2002 Steven Knight
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 if sys.platform == 'win32':
33     _exe = '.exe'
34     _dll = '.dll'
35     lib_ = ''
36 else:
37     _exe = ''
38     _dll = '.so'
39     lib_ = 'lib'
40     
41 test = TestSCons.TestSCons()
42
43 test.subdir('lib1', 'lib2')
44
45 prog1 = test.workpath('prog') + _exe
46 prog2 = test.workpath(lib_ + 'shlib') + _dll
47
48 test.write('SConstruct', """
49 env1 = Environment(LIBS = [ 'foo1' ],
50                   LIBPATH = [ './lib1' ])
51
52 f1 = env1.Object('f1', 'f1.c')
53
54 env1.Program(target = 'prog', source = 'prog.c')
55 env1.Library(target = './lib1/foo1', source = f1)
56
57 env2 = Environment(LIBS = 'foo2',
58                    LIBPATH = '.')
59 env2.SharedLibrary(target = 'shlib', source = 'shlib.c')
60 env2.Library(target = 'foo2', source = f1)
61 """)
62
63 test.write('f1.c', r"""
64 void
65 f1(void)
66 {
67         printf("f1.c\n");
68 }
69 """)
70
71 test.write('shlib.c', r"""
72 void f1(void);
73 int
74 test()
75 {
76     f1();
77 }
78 """)
79
80 test.write('prog.c', r"""
81 void f1(void);
82 int
83 main(int argc, char *argv[])
84 {
85         argv[argc++] = "--";
86         f1();
87         printf("prog.c\n");
88         return 0;
89 }
90 """)
91
92 test.run(arguments = '.')
93
94 test.run(program = prog1,
95          stdout = "f1.c\nprog.c\n")
96
97 oldtime1 = os.path.getmtime(prog1)
98 oldtime2 = os.path.getmtime(prog2)
99 time.sleep(2)
100 test.run(arguments = '.')
101
102 test.fail_test(oldtime1 != os.path.getmtime(prog1))
103 test.fail_test(oldtime2 != os.path.getmtime(prog2))
104
105 test.write('f1.c', r"""
106 void
107 f1(void)
108 {
109         printf("f1.c 1\n");
110 }
111 """)
112
113 test.run(arguments = '.')
114 test.run(program = prog1,
115          stdout = "f1.c 1\nprog.c\n")
116 test.fail_test(oldtime2 == os.path.getmtime(prog2))
117 #test.up_to_date(arguments = '.')
118 # Change LIBPATH and make sure we don't rebuild because of it.
119 test.write('SConstruct', """
120 env1 = Environment(LIBS = [ 'foo1' ],
121                   LIBPATH = [ './lib1', './lib2' ])
122
123 f1 = env1.Object('f1', 'f1.c')
124
125 env1.Program(target = 'prog', source = 'prog.c')
126 env1.Library(target = './lib1/foo1', source = f1)
127
128 env2 = Environment(LIBS = 'foo2',
129                    LIBPATH = Split('. ./lib2'))
130 env2.SharedLibrary(target = 'shlib', source = 'shlib.c')
131 env2.Library(target = 'foo2', source = f1)
132 """)
133
134 test.up_to_date(arguments = '.', stderr=None)
135
136 test.write('f1.c', r"""
137 void
138 f1(void)
139 {
140         printf("f1.c 2\n");
141 }
142 """)
143
144 test.run(arguments = '.')
145 test.run(program = prog1,
146          stdout = "f1.c 2\nprog.c\n")
147
148 test.up_to_date(arguments = '.')
149
150 # Check that a null-string LIBPATH doesn't blow up.
151 test.write('SConstruct', """
152 env = Environment(LIBPATH = '')
153 env.Library('foo', source = '')
154 """)
155
156 test.run(arguments = '.')
157
158 test.pass_test()