Merged revisions 1582-1665 via svnmerge from
[scons.git] / test / Repository / StaticLibrary.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 sys
29 import TestSCons
30
31 if sys.platform == 'win32':
32     _obj = '.obj'
33     _exe = '.exe'
34 else:
35     _obj = '.o'
36     _exe = ''
37
38
39
40 test = TestSCons.TestSCons()
41
42 #
43 test.subdir('repository', 'work1', 'work2', 'work3')
44
45 #
46 workpath_repository = test.workpath('repository')
47 repository_aaa_obj = test.workpath('repository', 'aaa' + _obj)
48 repository_bbb_obj = test.workpath('repository', 'bbb' + _obj)
49 repository_foo_obj = test.workpath('repository', 'foo' + _obj)
50 repository_foo = test.workpath('repository', 'foo' + _exe)
51 work1_foo = test.workpath('work1', 'foo' + _exe)
52 work2_aaa_obj = test.workpath('work2', 'aaa' + _obj)
53 work2_foo_obj = test.workpath('work2', 'foo' + _obj)
54 work2_foo = test.workpath('work2', 'foo' + _exe)
55 work3_aaa_obj = test.workpath('work3', 'aaa' + _obj)
56 work3_bbb_obj = test.workpath('work3', 'bbb' + _obj)
57 work3_foo = test.workpath('work3', 'foo' + _exe)
58
59 opts = '-Y ' + workpath_repository
60
61 #
62 test.write(['repository', 'SConstruct'], """
63 env = Environment(LIBS = ['xxx'], LIBPATH = '.')
64 env.Library(target = 'xxx', source = ['aaa.c', 'bbb.c'])
65 env.Program(target = 'foo', source = 'foo.c')
66 """)
67
68 test.write(['repository', 'aaa.c'], r"""
69 #include <stdio.h>
70 #include <stdlib.h>
71 void
72 aaa(void)
73 {
74         printf("repository/aaa.c\n");
75 }
76 """)
77
78 test.write(['repository', 'bbb.c'], r"""
79 #include <stdio.h>
80 #include <stdlib.h>
81 void
82 bbb(void)
83 {
84         printf("repository/bbb.c\n");
85 }
86 """)
87
88 test.write(['repository', 'foo.c'], r"""
89 #include <stdio.h>
90 #include <stdlib.h>
91 extern void aaa(void);
92 extern void bbb(void);
93 int
94 main(int argc, char *argv[])
95 {
96         argv[argc++] = "--";
97         aaa();
98         bbb();
99         printf("repository/foo.c\n");
100         exit (0);
101 }
102 """)
103
104 # Make the repository non-writable,
105 # so we'll detect if we try to write into it accidentally.
106 test.writable('repository', 0)
107
108 #
109 test.run(chdir = 'work1', options = opts, arguments = ".",
110          stderr=TestSCons.noisy_ar,
111          match=TestSCons.match_re_dotall)
112
113 test.run(program = work1_foo, stdout =
114 """repository/aaa.c
115 repository/bbb.c
116 repository/foo.c
117 """)
118
119 test.fail_test(os.path.exists(repository_aaa_obj))
120 test.fail_test(os.path.exists(repository_bbb_obj))
121 test.fail_test(os.path.exists(repository_foo_obj))
122 test.fail_test(os.path.exists(repository_foo))
123
124 test.up_to_date(chdir = 'work1', options = opts, arguments = ".")
125
126 test.write(['work1', 'bbb.c'], r"""
127 #include <stdio.h>
128 #include <stdlib.h>
129 void
130 bbb(void)
131 {
132         printf("work1/bbb.c\n");
133 }
134 """)
135
136 test.run(chdir = 'work1', options = opts, arguments = ".",
137          stderr=TestSCons.noisy_ar,
138          match=TestSCons.match_re_dotall)
139
140 test.run(program = work1_foo, stdout =
141 """repository/aaa.c
142 work1/bbb.c
143 repository/foo.c
144 """)
145
146 test.fail_test(os.path.exists(repository_aaa_obj))
147 test.fail_test(os.path.exists(repository_bbb_obj))
148 test.fail_test(os.path.exists(repository_foo_obj))
149 test.fail_test(os.path.exists(repository_foo))
150
151 test.up_to_date(chdir = 'work1', options = opts, arguments = ".")
152
153 #
154 test.writable('repository', 1)
155
156 test.run(chdir = 'repository', options = opts, arguments = ".",
157          stderr=TestSCons.noisy_ar,
158          match=TestSCons.match_re_dotall)
159
160 test.run(program = repository_foo, stdout =
161 """repository/aaa.c
162 repository/bbb.c
163 repository/foo.c
164 """)
165
166 test.fail_test(not os.path.exists(repository_aaa_obj))
167 test.fail_test(not os.path.exists(repository_bbb_obj))
168 test.fail_test(not os.path.exists(repository_foo_obj))
169
170 test.up_to_date(chdir = 'repository', options = opts, arguments = ".")
171
172 #
173 test.writable('repository', 0)
174
175 #
176 test.up_to_date(chdir = 'work2', options = opts, arguments = ".")
177
178 test.write(['work2', 'bbb.c'], r"""
179 #include <stdio.h>
180 #include <stdlib.h>
181 void
182 bbb(void)
183 {
184         printf("work2/bbb.c\n");
185 }
186 """)
187
188 test.run(chdir = 'work2', options = opts, arguments = ".",
189          stderr=TestSCons.noisy_ar,
190          match=TestSCons.match_re_dotall)
191
192 test.run(program = work2_foo, stdout =
193 """repository/aaa.c
194 work2/bbb.c
195 repository/foo.c
196 """)
197
198 test.fail_test(os.path.exists(work2_aaa_obj))
199 test.fail_test(os.path.exists(work2_foo_obj))
200
201 test.up_to_date(chdir = 'work2', options = opts, arguments = ".")
202
203 #
204 test.up_to_date(chdir = 'work3', options = opts, arguments = ".")
205
206 test.write(['work3', 'foo.c'], r"""
207 #include <stdio.h>
208 #include <stdlib.h>
209 extern void aaa(void);
210 extern void bbb(void);
211 int
212 main(int argc, char *argv[])
213 {
214         argv[argc++] = "--";
215         aaa();
216         bbb();
217         printf("work3/foo.c\n");
218         exit (0);
219 }
220 """)
221
222 test.run(chdir = 'work3', options = opts, arguments = ".")
223
224 test.run(program = work3_foo, stdout =
225 """repository/aaa.c
226 repository/bbb.c
227 work3/foo.c
228 """)
229
230 test.fail_test(os.path.exists(work3_aaa_obj))
231 test.fail_test(os.path.exists(work3_bbb_obj))
232
233 test.up_to_date(chdir = 'work3', options = opts, arguments = ".")
234
235 #
236 test.pass_test()