Updates to PR 4374 from mwichmann to correct config file hash changes
[scons.git] / test / Libs / LIBPATH.py
blob74e92192bc6cff72974c24a01960caca4a66b269
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 import os.path
27 import time
29 import TestSCons
31 _exe = TestSCons._exe
32 _dll = TestSCons._dll
33 dll_ = TestSCons.dll_
35 test = TestSCons.TestSCons()
37 test.subdir('lib1', 'lib2')
39 prog1 = test.workpath('prog') + _exe
40 prog2 = test.workpath(dll_ + 'shlib') + _dll
42 test.write('SConstruct', """\
43 DefaultEnvironment(tools=[]) # test speedup
44 env1 = Environment(LIBS=['foo1'], LIBPATH=['$FOO'], FOO='./lib1')
46 f1 = env1.SharedObject('f1', 'f1.c')
48 env1.Program(target='prog', source='prog.c')
49 env1.Library(target='./lib1/foo1', source=f1)
51 env2 = Environment(LIBS='foo2', LIBPATH='.')
52 env2.SharedLibrary(target='shlib', source='shlib.c', no_import_lib=1)
53 env2.Library(target='foo2', source=f1)
54 """)
56 test.write('f1.c', r"""
57 #include <stdio.h>
59 void
60 f1(void)
62 printf("f1.c\n");
64 """)
66 test.write('shlib.c', r"""
67 void f1(void);
68 int
69 test()
71 f1();
72 return 0;
74 """)
76 test.write('prog.c', r"""
77 #include <stdio.h>
79 void f1(void);
80 int
81 main(int argc, char *argv[])
83 argv[argc++] = "--";
84 f1();
85 printf("prog.c\n");
86 return 0;
88 """)
90 test.run(arguments = '.',
91 stderr=TestSCons.noisy_ar,
92 match=TestSCons.match_re_dotall)
94 test.run(program = prog1,
95 stdout = "f1.c\nprog.c\n")
97 oldtime1 = os.path.getmtime(prog1)
98 oldtime2 = os.path.getmtime(prog2)
99 test.sleep() # delay for timestamps
100 test.run(arguments='.')
102 test.fail_test(oldtime1 != os.path.getmtime(prog1))
103 test.fail_test(oldtime2 != os.path.getmtime(prog2))
105 test.write('f1.c', r"""
106 #include <stdio.h>
108 void
109 f1(void)
111 printf("f1.c 1\n");
113 """)
115 test.run(arguments='.', stderr=TestSCons.noisy_ar, match=TestSCons.match_re_dotall)
116 test.run(program=prog1, 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 DefaultEnvironment(tools=[]) # test speedup
122 env1 = Environment(LIBS=['foo1'], LIBPATH=['./lib1', './lib2'])
124 f1 = env1.SharedObject('f1', 'f1.c')
126 env1.Program(target='prog', source='prog.c')
127 env1.Library(target='./lib1/foo1', source=f1)
129 env2 = Environment(LIBS='foo2', LIBPATH=Split('. ./lib2'))
130 env2.SharedLibrary(target='shlib', source='shlib.c', no_import_lib=1)
131 env2.Library(target='foo2', source=f1)
132 """)
134 test.up_to_date(arguments='.', stderr=None)
136 test.write('f1.c', r"""
137 #include <stdio.h>
139 void
140 f1(void)
142 printf("f1.c 2\n");
144 """)
146 test.run(arguments='.', stderr=TestSCons.noisy_ar, match=TestSCons.match_re_dotall)
147 test.run(program=prog1, stdout="f1.c 2\nprog.c\n")
149 test.up_to_date(arguments='.')
151 # We need at least one file for some implementations of the Library
152 # builder, notably the SGI one.
153 test.write('empty.c', 'int a=0;\n')
155 # Check that a null-string LIBPATH doesn't blow up.
156 test.write('SConstruct', """\
157 DefaultEnvironment(tools=[]) # test speedup
158 env = Environment(LIBPATH='')
159 env.Library('foo', source='empty.c')
160 """)
162 test.run(arguments='.', stderr=TestSCons.noisy_ar, match=TestSCons.match_re_dotall)
164 test.pass_test()
166 # Local Variables:
167 # tab-width:4
168 # indent-tabs-mode:nil
169 # End:
170 # vim: set expandtab tabstop=4 shiftwidth=4: