]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/tools/build/test/builtin_glob_archive.py
update sources to v12.2.3
[ceph.git] / ceph / src / boost / tools / build / test / builtin_glob_archive.py
CommitLineData
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
10import os
11import sys
12import StringIO
13import BoostBuild
14
15vms = ( os.name == 'posix' and sys.platform == 'OpenVMS')
16
17t = BoostBuild.Tester()
18
19## Setup test archive sources and symbols they contain.
20sources = {
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
36def 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
46def 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("""\
54static-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
73def 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
100setup_archive("auxilliary1.lib", sources)
101archive1 = archive
102setup_archive("auxilliary2.lib", sources)
103archive2 = archive
104
105## all arguments empty
106test_glob_archive([archive1], "[ GLOB_ARCHIVE ]", [])
107
108## empty query
109test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : ]", [])
110
111## no-match
112test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : a ]", [])
113
114## match exact
115test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : a$obj ]",
116 ["$archive1(a$obj)"])
117
118## glob wildcards:1
119test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : b.* ]",
120 ["$archive1(b$obj)"])
121
122## glob wildcards:2
123test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : \\b?match[\.]* ]",
124 ["$archive1(b_match$obj)"])
125
126## glob wildcards:3
127test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : b* ]",
128 ["$archive1(b$obj)", "$archive1(b_match$obj)"])
129
130## glob multiple patterns with multiple results.
131test_glob_archive([archive1], "[ GLOB_ARCHIVE $archive1 : b.* b_* ]",
132 ["$archive1(b$obj)", "$archive1(b_match$obj)"])
133
134## glob multiple archives and patterns.
135test_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.
141test_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.
147test_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
153case_sensitive_members = ( not vms )
154
155if case_sensitive_members:
156 test_glob_archive([archive1],
157 "[ GLOB_ARCHIVE $archive1 : casecheck$obj : true ]",
158 ["$archive1(CaseCheck$obj)"])
159elif 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.
167test_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.
174symbol_glob_supported = ( vms )
175
176if 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
207else:
208 test_glob_archive([archive1],
209 "[ GLOB_ARCHIVE $archive1 : : : symbol ]",
210 [])
211
212
213t.cleanup()
214