]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/usr/bin/python |
2 | ||
3 | # Copyright 2014 Steven Watanabe | |
4 | # Copyright 2015 Artur Shepilko | |
5 | # Distributed under the Boost Software License, Version 1.0. | |
6 | # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) | |
7 | ||
8 | # This tests the GLOB_ARCHIVE rule. | |
9 | ||
10 | import os | |
11 | import sys | |
12 | import StringIO | |
13 | import BoostBuild | |
14 | ||
15 | vms = ( os.name == 'posix' and sys.platform == 'OpenVMS') | |
16 | ||
17 | t = BoostBuild.Tester() | |
18 | ||
19 | ## Setup test archive sources and symbols they contain. | |
20 | sources = { | |
21 | "a.cpp" : ["a"], | |
22 | "b.cpp" : ["b"], | |
23 | "b_match.cpp" : ["b_match"], | |
24 | "c/nopath_check.cpp" : ["nopath_check"], | |
25 | "CaseCheck.cpp" : ["CaseCheck"], | |
26 | "seq_check1.cpp" : ["seq_check1"], | |
27 | "seq_check2.cpp" : ["seq_check2"], | |
28 | "seq_check3.cpp" : ["seq_check3"], | |
29 | "symbols_check.c" : ["symbol", "symbol_match"], | |
30 | "members_and_symbols_check.c" : ["member_and_symbol_match"], | |
31 | "symbol_case_check.c" : ["SymbolCaseCheck"], | |
32 | "main_check.cpp" : ["main"] | |
33 | } | |
34 | ||
35 | ||
36 | def create_sources(path, sources): | |
37 | for s in sources : | |
38 | f = os.path.join(path, s) | |
39 | t.write(f, "") | |
40 | output = StringIO.StringIO() | |
41 | for sym in sources[s] : | |
42 | output.write("int %s() { return 0; }\n" % sym) | |
43 | t.write(f, output.getvalue()) | |
44 | ||
45 | ||
46 | def setup_archive(name, sources): | |
47 | global archive | |
48 | global obj_suffix | |
49 | archive = t.adjust_names(name)[0] | |
50 | obj_suffix = t.adjust_names(".obj")[0] | |
51 | output = StringIO.StringIO() | |
52 | t.write("jamroot.jam","") | |
53 | output.write("""\ | |
54 | static-lib %s : | |
55 | """ % name.split(".")[0]) | |
56 | ## sort the sources, so we can test order of the globbed members | |
57 | for s in sorted(sources) : | |
58 | output.write("""\ | |
59 | %s | |
60 | """ % s) | |
61 | output.write("""\ | |
62 | ; | |
63 | """) | |
64 | t.write("lib/jamfile.jam", output.getvalue()) | |
65 | create_sources("lib", sources) | |
66 | t.run_build_system(subdir="lib") | |
b32b8144 | 67 | built_archive = "lib/bin/$toolset/debug*/%s" % name |
7c673cae FG |
68 | t.expect_addition(built_archive) |
69 | t.copy(built_archive, name) | |
70 | t.rm("lib") | |
71 | ||
72 | ||
73 | def test_glob_archive(archives, glob, expected, sort_results = False): | |
74 | output = StringIO.StringIO() | |
75 | ## replace placeholders | |
76 | glob = glob.replace("$archive1", archives[0]).replace("$obj", obj_suffix) | |
77 | expected = [ m.replace("$archive1", | |
78 | archives[0]).replace("$obj", obj_suffix) for m in expected ] | |
79 | if len(archives) > 1 : | |
80 | glob = glob.replace("$archive2", archives[1]).replace("$obj", obj_suffix) | |
81 | expected = [ m.replace("$archive2", | |
82 | archives[1]).replace("$obj", obj_suffix) for m in expected ] | |
83 | ## create test jamfile | |
84 | if sort_results : glob = "[ SORT %s ]" % glob | |
85 | output.write("""\ | |
86 | for local p in %s | |
87 | { | |
88 | ECHO $(p) ; | |
89 | } | |
90 | UPDATE ; | |
91 | """ % glob) | |
92 | t.write("file.jam", output.getvalue()) | |
93 | ## run test jamfile and match against expected results | |
94 | if sort_results : expected.sort() | |
95 | t.run_build_system(["-ffile.jam"], stdout="\n".join(expected + [""])) | |
96 | t.rm("file.jam") | |
97 | ||
98 | ||
99 | ## RUN TESTS | |
100 | setup_archive("auxilliary1.lib", sources) | |
101 | archive1 = archive | |
102 | setup_archive("auxilliary2.lib", sources) | |
103 | archive2 = archive | |
104 | ||
105 | ## all arguments empty | |
106 | test_glob_archive([archive1], "[ GLOB_ARCHIVE ]", []) | |
107 | ||
108 | ## empty query | |
109 | test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : ]", []) | |
110 | ||
111 | ## no-match | |
112 | test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : a ]", []) | |
113 | ||
114 | ## match exact | |
115 | test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : a$obj ]", | |
116 | ["$archive1(a$obj)"]) | |
117 | ||
118 | ## glob wildcards:1 | |
119 | test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : b.* ]", | |
120 | ["$archive1(b$obj)"]) | |
121 | ||
122 | ## glob wildcards:2 | |
123 | test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : \\b?match[\.]* ]", | |
124 | ["$archive1(b_match$obj)"]) | |
125 | ||
126 | ## glob wildcards:3 | |
127 | test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : b* ]", | |
128 | ["$archive1(b$obj)", "$archive1(b_match$obj)"]) | |
129 | ||
130 | ## glob multiple patterns with multiple results. | |
131 | test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : b.* b_* ]", | |
132 | ["$archive1(b$obj)", "$archive1(b_match$obj)"]) | |
133 | ||
134 | ## glob multiple archives and patterns. | |
135 | test_glob_archive([archive1, archive2], | |
136 | "[ GLOB_ARCHIVE $archive1 $archive2 : b.* b_* ]", | |
137 | ["$archive1(b$obj)", "$archive1(b_match$obj)", | |
138 | "$archive2(b$obj)", "$archive2(b_match$obj)"]) | |
139 | ||
140 | ## glob same archive multiple times. | |
141 | test_glob_archive([archive1, archive1], | |
142 | "[ GLOB_ARCHIVE $archive1 $archive2 $archive1 : b.* ]", | |
143 | ["$archive1(b$obj)", "$archive2(b$obj)", "$archive1(b$obj)"]) | |
144 | ||
145 | ## returned archive member has no path, even though its source object-file did. | |
146 | ## this is rather NT-specific, where members also store their object-file's path. | |
147 | test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : nopath_check$obj ]", | |
148 | ["$archive1(nopath_check$obj)"]) | |
149 | ||
150 | ## case insensitive matching, when archives support case sensitive member names. | |
151 | ## VMS implementation forces case-insensitive matching and downcased member names. | |
152 | ||
153 | case_sensitive_members = ( not vms ) | |
154 | ||
155 | if case_sensitive_members: | |
156 | test_glob_archive([archive1], | |
157 | "[ GLOB_ARCHIVE $archive1 : casecheck$obj : true ]", | |
158 | ["$archive1(CaseCheck$obj)"]) | |
159 | elif vms: | |
160 | test_glob_archive([archive1], | |
161 | "[ GLOB_ARCHIVE $archive1 : CaseCheck$obj : false ]", | |
162 | ["$archive1(casecheck$obj)"]) | |
163 | ||
164 | ||
165 | ## test the order of matched members, in general it should match the | |
166 | ## insertion sequence. | |
167 | test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : seq_check*$obj ]", | |
168 | ["$archive1(seq_check1$obj)", "$archive1(seq_check2$obj)", | |
169 | "$archive1(seq_check3$obj)"]) | |
170 | ||
171 | ||
172 | ## glob members by symbols they contain. | |
173 | ## Currently supported only on VMS. | |
174 | symbol_glob_supported = ( vms ) | |
175 | ||
176 | if symbol_glob_supported : | |
177 | ## NOTE: generated symbols are compiler-dependent and may be specifically | |
178 | ## mangled (as in C++ case), so globbing by exact symbol is non-trivial. | |
179 | ## However, C-generated symbols are likely to have more portable names, | |
180 | ## so for the glob-by-symbol tests we glob C-generated archive members. | |
181 | ||
182 | ## glob members by exact symbol. | |
183 | test_glob_archive([archive1], | |
184 | "[ GLOB_ARCHIVE $archive1 : : : symbol ]", | |
185 | ["$archive1(symbols_check$obj)"]) | |
186 | ||
187 | ## glob members by symbol wildcard. | |
188 | test_glob_archive([archive1], | |
189 | "[ GLOB_ARCHIVE $archive1 : : : symbol_* ]", | |
190 | ["$archive1(symbols_check$obj)"]) | |
191 | ||
192 | ## glob members by member pattern AND symbol pattern. | |
193 | test_glob_archive([archive1], | |
194 | "[ GLOB_ARCHIVE $archive1 : *symbol* : : *member* ]", | |
195 | ["$archive1(members_and_symbols_check$obj)"]) | |
196 | ||
197 | ## case insensitive symbol glob. | |
198 | test_glob_archive([archive1], | |
199 | "[ GLOB_ARCHIVE $archive1 : : true : symbolcasecheck ]", | |
200 | ["$archive1(symbol_case_check$obj)"]) | |
201 | ||
202 | ## glob member that contains main symbol. | |
203 | test_glob_archive([archive1], | |
204 | "[ GLOB_ARCHIVE $archive1 : : : main _main ]", | |
205 | ["$archive1(main_check$obj)"]) | |
206 | ||
207 | else: | |
208 | test_glob_archive([archive1], | |
209 | "[ GLOB_ARCHIVE $archive1 : : : symbol ]", | |
210 | []) | |
211 | ||
212 | ||
213 | t.cleanup() | |
214 |