]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/test/project_id.py
3 # Copyright (C) 2012. Jurko Gospodnetic
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or copy at
6 # http://www.boost.org/LICENSE_1_0.txt)
8 # Tests Boost Build's project-id handling.
14 def test_assigning_project_ids():
15 t
= BoostBuild
.Tester(pass_toolset
=False)
16 t
.write("jamroot.jam", """\
22 rule assert-project-id ( id ? : module-name ? )
24 module-name ?= [ CALLER_MODULE ] ;
25 assert.result $(id) : project.attribute $(module-name) id ;
28 # Project rule modifies the main project id.
29 assert-project-id ; # Initial project id is empty
30 project foo ; assert-project-id /foo ;
31 project ; assert-project-id /foo ;
32 project foo ; assert-project-id /foo ;
33 project bar ; assert-project-id /bar ;
34 project /foo ; assert-project-id /foo ;
35 project "" ; assert-project-id /foo ;
37 # Calling the use-project rule does not modify the project's main id.
39 # We need to load the 'a' Jamfile module manually as the use-project rule will
40 # only schedule the load to be done after the current module load finishes.
41 a-module = [ project.load a ] ;
42 assert-project-id : $(a-module) ;
44 assert-project-id : $(a-module) ;
45 modules.call-in $(a-module) : project baz ;
46 assert-project-id /baz : $(a-module) ;
48 assert-project-id /baz : $(a-module) ;
50 # Make sure the project id still holds after all the scheduled use-project loads
51 # complete. We do this by scheduling the assert for the Jam action scheduling
53 notfile x : @assert-a-rule ;
54 rule assert-a-rule ( target : : properties * )
56 assert-project-id /baz : $(a-module) ;
59 t
.write("a/jamfile.jam", """\
60 # Initial project id for this module is empty.
67 def test_using_project_ids_in_target_references():
68 t
= BoostBuild
.Tester()
69 __write_appender(t
, "appender.jam")
70 t
.write("jamroot.jam", """\
72 type.register AAA : _a ;
73 type.register BBB : _b ;
76 appender.register aaa-to-bbb : AAA : BBB ;
79 use-project /id2 : a ;
81 bbb b1 : /id1//target ;
82 bbb b2 : /id2//target ;
83 bbb b3 : /id3//target ;
85 bbb b5 : /project-a1//target ;
86 bbb b6 : /project-a2//target ;
87 bbb b7 : /project-a3//target ;
91 t
.write("a/source._a", "")
92 t
.write("a/jamfile.jam", """\
96 alias target : source._a ;
101 t
.expect_addition("bin/$toolset/b%d._b" % x
for x
in range(1, 8))
102 t
.expect_nothing_more()
107 def test_repeated_ids_for_different_projects():
108 t
= BoostBuild
.Tester()
110 t
.write("a/jamfile.jam", "")
111 t
.write("jamroot.jam", "project foo ; use-project foo : a ;")
112 t
.run_build_system(status
=1)
113 t
.expect_output_lines("""\
114 error: Attempt to redeclare already registered project id '/foo'.
115 error: Original project:
116 error: Name: Jamfile<*>
117 error: Module: Jamfile<*>
119 error: File: jamroot.jam
122 error: Module: Jamfile<*>
123 error: File: a*jamfile.jam
124 error: Location: a""")
126 t
.write("jamroot.jam", "use-project foo : a ; project foo ;")
127 t
.run_build_system(status
=1)
128 t
.expect_output_lines("""\
129 error: Attempt to redeclare already registered project id '/foo'.
130 error: Original project:
131 error: Name: Jamfile<*>
132 error: Module: Jamfile<*>
134 error: File: jamroot.jam
137 error: Module: Jamfile<*>
138 error: File: a*jamfile.jam
139 error: Location: a""")
141 t
.write("jamroot.jam", """\
144 modules.call-in [ project.load a ] : project foo ;
147 t
.run_build_system(status
=1)
148 t
.expect_output_lines("""\
149 error: at jamroot.jam:4
150 error: Attempt to redeclare already registered project id '/foo'.
151 error: Original project:
152 error: Name: Jamfile<*>
153 error: Module: Jamfile<*>
155 error: File: a*jamfile.jam
158 error: Module: Jamfile<*>
159 error: File: jamroot.jam
160 error: Location: .""")
165 def test_repeated_ids_for_same_project():
166 t
= BoostBuild
.Tester()
168 t
.write("jamroot.jam", "project foo ; project foo ;")
171 t
.write("jamroot.jam", "project foo ; use-project foo : . ;")
174 t
.write("jamroot.jam", "project foo ; use-project foo : ./. ;")
177 t
.write("jamroot.jam", """\
179 use-project foo : . ;
180 use-project foo : ./aaa/.. ;
181 use-project foo : ./. ;
185 # On Windows we have a case-insensitive file system and we can use
186 # backslashes as path separators.
187 # FIXME: Make a similar test pass on Cygwin.
188 if sys
.platform
in ['win32']:
189 t
.write("a/fOo bAr/b/jamfile.jam", "")
190 t
.write("jamroot.jam", r
"""
191 use-project bar : "a/foo bar/b" ;
192 use-project bar : "a/foO Bar/b" ;
193 use-project bar : "a/foo BAR/b/" ;
194 use-project bar : "a\\.\\FOO bar\\b\\" ;
199 t
.write("bar/jamfile.jam", "")
200 t
.write("jamroot.jam", """\
201 use-project bar : bar ;
202 use-project bar : bar/ ;
203 use-project bar : bar// ;
204 use-project bar : bar/// ;
205 use-project bar : bar//// ;
206 use-project bar : bar/. ;
207 use-project bar : bar/./ ;
208 use-project bar : bar/////./ ;
209 use-project bar : bar/../bar/xxx/.. ;
210 use-project bar : bar/..///bar/xxx///////.. ;
211 use-project bar : bar/./../bar/xxx/.. ;
212 use-project bar : bar/.////../bar/xxx/.. ;
213 use-project bar : bar/././../bar/xxx/.. ;
214 use-project bar : bar/././//////////../bar/xxx/.. ;
215 use-project bar : bar/.///.////../bar/xxx/.. ;
216 use-project bar : bar/./././xxx/.. ;
217 use-project bar : bar/xxx////.. ;
218 use-project bar : bar/xxx/.. ;
219 use-project bar : bar///////xxx/.. ;
224 # On Windows we have a case-insensitive file system and we can use
225 # backslashes as path separators.
226 # FIXME: Make a similar test pass on Cygwin.
227 if sys
.platform
in ['win32']:
228 t
.write("baR/jamfile.jam", "")
229 t
.write("jamroot.jam", r
"""
230 use-project bar : bar ;
231 use-project bar : BAR ;
232 use-project bar : bAr ;
233 use-project bar : bAr/ ;
234 use-project bar : bAr\\ ;
235 use-project bar : bAr\\\\ ;
236 use-project bar : bAr\\\\///// ;
237 use-project bar : bAr/. ;
238 use-project bar : bAr/./././ ;
239 use-project bar : bAr\\.\\.\\.\\ ;
240 use-project bar : bAr\\./\\/.\\.\\ ;
241 use-project bar : bAr/.\\././ ;
242 use-project bar : Bar ;
243 use-project bar : BaR ;
244 use-project bar : BaR/./../bAr/xxx/.. ;
245 use-project bar : BaR/./..\\bAr\\xxx/.. ;
246 use-project bar : BaR/xxx/.. ;
247 use-project bar : BaR///\\\\\\//xxx/.. ;
248 use-project bar : Bar\\xxx/.. ;
249 use-project bar : BAR/xXx/.. ;
250 use-project bar : BAR/xXx\\\\/\\/\\//\\.. ;
258 def test_unresolved_project_references():
259 t
= BoostBuild
.Tester()
261 __write_appender(t
, "appender.jam")
262 t
.write("a/source._a", "")
263 t
.write("a/jamfile.jam", "import alias ; alias target : source._a ;")
264 t
.write("jamroot.jam", """\
266 type.register AAA : _a ;
267 type.register BBB : _b ;
270 appender.register aaa-to-bbb : AAA : BBB ;
272 use-project foo : a ;
275 bbb b2 : /foo//target ;
276 bbb b-invalid : invalid//target ;
277 bbb b-root-invalid : /invalid//target ;
278 bbb b-missing-root : foo//target ;
279 bbb b-invalid-target : /foo//invalid ;
282 t
.run_build_system(["b1", "b2"])
283 t
.expect_addition("bin/$toolset/debug*/b%d._b" % x
for x
in range(1, 3))
284 t
.expect_nothing_more()
286 t
.run_build_system(["b-invalid"], status
=1)
287 t
.expect_output_lines("""\
288 error: Unable to find file or target named
289 error: 'invalid//target'
290 error: referred to from project at
292 error: could not resolve project reference 'invalid'""")
294 t
.run_build_system(["b-root-invalid"], status
=1)
295 t
.expect_output_lines("""\
296 error: Unable to find file or target named
297 error: '/invalid//target'
298 error: referred to from project at
300 error: could not resolve project reference '/invalid'""")
302 t
.run_build_system(["b-missing-root"], status
=1)
303 t
.expect_output_lines("""\
304 error: Unable to find file or target named
306 error: referred to from project at
308 error: could not resolve project reference 'foo' - possibly missing a """
309 "leading slash ('/') character.")
311 t
.run_build_system(["b-invalid-target"], status
=1)
312 t
.expect_output_lines("""\
313 error: Unable to find file or target named
314 error: '/foo//invalid'
315 error: referred to from project at
317 t
.expect_output_lines("*could not resolve project reference*", False)
322 def __write_appender(t
, name
):
324 r
"""# Copyright 2012 Jurko Gospodnetic
325 # Distributed under the Boost Software License, Version 1.0.
326 # (See accompanying file LICENSE_1_0.txt or copy at
327 # http://www.boost.org/LICENSE_1_0.txt)
329 # Support for registering test generators that construct their targets by
330 # simply appending their given input data, e.g. list of sources & targets.
332 import "class" : new ;
337 rule register ( id composing ? : source-types + : target-types + )
339 local caller-module = [ CALLER_MODULE ] ;
340 id = $(caller-module).$(id) ;
341 local g = [ new generator $(id) $(composing) : $(source-types) :
343 $(g).set-rule-name $(__name__).appender ;
344 generators.register $(g) ;
348 if [ modules.peek : NT ]
356 ECHO_CMD
= "echo $(X)" ;
359 local appender
-runs
;
361 # We set up separate actions for building each target in order to avoid having
362 # to iterate over them in action (i.e. shell) code. We have to be extra careful
363 # though to achieve the exact same effect as if doing all the work in just one
364 # action. Otherwise Boost Jam might, under some circumstances, run only some of
365 # our actions. To achieve this we register a series of actions for all the
366 # targets (since they all have the same target list - either all or none of them
367 # get run independent of which target actually needs to get built), each
368 # building only a single target. Since all our actions use the same targets, we
369 # can not use 'on-target' parameters to pass data to a specific action so we
370 # pass them using the second 'sources' parameter which our actions then know how
371 # to interpret correctly. This works well since Boost Jam does not automatically
372 # add dependency relations between specified action targets & sources and so the
373 # second argument, even though most often used to pass in a list of sources, can
374 # actually be used for passing in any type of information.
375 rule
appender ( targets
+ : sources
+ : properties
* )
377 appender
-runs
= [ CALC $
(appender
-runs
:E
=0) + 1 ] ;
378 local target
-index
= 0 ;
379 local target
-count
= [ sequence
.length $
(targets
) ] ;
380 local original
-targets
;
383 target
-index
= [ CALC $
(target
-index
) + 1 ] ;
384 local appender
-run
= $
(appender
-runs
) ;
385 if $
(targets
[2])-defined
387 appender
-run
+= [$
(target
-index
)/$
(target
-count
)] ;
389 append $
(targets
) : $
(appender
-run
:J
=" ") $
(t
) $
(sources
) ;
395 $
(ECHO_CMD
)-------------------------------------------------$
(X
)
396 $
(ECHO_CMD
)Appender run
: $
(>[1])$
(X
)
397 $
(ECHO_CMD
)Appender run
: $
(>[1])$
(X
)>> "$(>[2])"
398 $
(ECHO_CMD
)Target group
: $
(<:J
=' ')$
(X
)
399 $
(ECHO_CMD
)Target group
: $
(<:J
=' ')$
(X
)>> "$(>[2])"
400 $
(ECHO_CMD
) Target
: '$(>[2])'$
(X
)
401 $
(ECHO_CMD
) Target
: '$(>[2])'$
(X
)>> "$(>[2])"
402 $
(ECHO_CMD
) Sources
: '$(>[3-]:J=' ')'$
(X
)
403 $
(ECHO_CMD
) Sources
: '$(>[3-]:J=' ')'$
(X
)>> "$(>[2])"
404 $
(ECHO_CMD
)=================================================$
(X
)
405 $
(ECHO_CMD
)-------------------------------------------------$
(X
)>> "$(>[2])"
410 test_assigning_project_ids()
411 test_using_project_ids_in_target_references()
412 test_repeated_ids_for_same_project()
413 test_repeated_ids_for_different_projects()
414 test_unresolved_project_references()