]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/tools/build/test/indirect_conditional.py
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / tools / build / test / indirect_conditional.py
CommitLineData
7c673cae
FG
1#!/usr/bin/python
2
3# Copyright (C) 2006. Vladimir Prus
4# Distributed under the Boost Software License, Version 1.0.
1e59de90
TL
5# (See accompanying file LICENSE.txt or copy at
6# https://www.bfgroup.xyz/b2/LICENSE.txt)
7c673cae
FG
7
8import BoostBuild
9
10def test_basic():
11 t = BoostBuild.Tester(use_test_config=False)
12
13 t.write("jamroot.jam", """\
14exe a1 : a1.cpp : <conditional>@a1-rule ;
15rule a1-rule ( properties * )
16{
17 if <variant>debug in $(properties)
18 {
19 return <define>OK ;
20 }
21}
22
23exe a2 : a2.cpp : <conditional>@$(__name__).a2-rule
24 <variant>debug:<optimization>speed ;
25rule a2-rule ( properties * )
26{
27 if <optimization>speed in $(properties)
28 {
29 return <define>OK ;
30 }
31}
32
33exe a3 : a3.cpp :
34 <conditional>@$(__name__).a3-rule-1
35 <conditional>@$(__name__).a3-rule-2 ;
36rule a3-rule-1 ( properties * )
37{
38 if <optimization>speed in $(properties)
39 {
40 return <define>OK ;
41 }
42}
43rule a3-rule-2 ( properties * )
44{
45 if <variant>debug in $(properties)
46 {
47 return <optimization>speed ;
48 }
49}
50""")
51
52 t.write("a1.cpp", "#ifdef OK\nint main() {}\n#endif\n")
53 t.write("a2.cpp", "#ifdef OK\nint main() {}\n#endif\n")
54 t.write("a3.cpp", "#ifdef OK\nint main() {}\n#endif\n")
55
56 t.run_build_system()
57
b32b8144
FG
58 t.expect_addition("bin/$toolset/debug*/a1.exe")
59 t.expect_addition("bin/$toolset/debug/optimization-speed*/a2.exe")
60 t.expect_addition("bin/$toolset/debug/optimization-speed*/a3.exe")
7c673cae
FG
61
62 t.cleanup()
63
92f5a8d4
TL
64def test_inherit():
65 """Tests that paths etc. are handled correctly when an indirect
66 conditional is inherited by a subproject."""
67 t = BoostBuild.Tester(use_test_config=False)
68 t.write("Jamroot.jam", """
69import feature ;
70import indirect ;
71exe d1 : d1.cpp ;
72explicit d1 ;
73project : requirements <conditional>@c1 ;
74build-project subdir ;
75feature.feature myrule : : free ;
76rule c1 ( properties * )
77{
78 return <dependency>d1 <include>include <myrule>@parent-generate ;
79}
80rule parent-generate ( project name : property-set : sources * )
81{
82 return $(sources) ;
83}
84rule my-generate ( project name : property-set : sources * )
85{
86 local r = [ $(property-set).get <myrule> ] ;
87 r = [ MATCH @(.*) : $(r) ] ;
88 return [ indirect.call
89 $(r) $(project) $(name) : $(property-set) : $(sources) ] ;
90}
91""")
92 t.write("d1.cpp", "int main(){}\n")
93 t.write("subdir/Jamfile", """
94generate srcs : main.cpp : <generating-rule>@my-generate ;
95exe main : srcs ;
96""")
97 t.write("include/a.h", "")
98 t.write("subdir/main.cpp", "#include <a.h>\nint main() {}\n")
99 t.run_build_system()
100 t.expect_addition("bin/$toolset/debug*/d1.obj")
101 t.expect_addition("bin/$toolset/debug*/d1.exe")
20effc67 102 t.ignore_addition("bin/*/d1.rsp")
92f5a8d4
TL
103 t.expect_addition("subdir/bin/$toolset/debug*/main.obj")
104 t.expect_addition("subdir/bin/$toolset/debug*/main.exe")
20effc67 105 t.ignore_addition("subdir/bin/*/main.rsp")
92f5a8d4
TL
106 t.expect_nothing_more()
107 t.cleanup()
7c673cae
FG
108
109def test_glob_in_indirect_conditional():
110 """
111 Regression test: project-rules.glob rule run from inside an indirect
112 conditional should report an error as it depends on the 'currently loaded
113 project' concept and indirect conditional rules get called only after all
114 the project modules have already finished loading.
115
116 """
117 t = BoostBuild.Tester(use_test_config=False)
118
119 t.write("jamroot.jam", """\
120use-project /library-example/foo : util/foo ;
121build-project app ;
122""")
123 t.write("app/app.cpp", "int main() {}\n");
124 t.write("app/jamfile.jam", "exe app : app.cpp /library-example/foo//bar ;")
125 t.write("util/foo/bar.cpp", """\
126#ifdef _WIN32
127__declspec(dllexport)
128#endif
129void foo() {}
130""")
131 t.write("util/foo/jamfile.jam", """\
132rule print-my-sources ( properties * )
133{
134 ECHO My sources: ;
135 ECHO [ glob *.cpp ] ;
136}
137lib bar : bar.cpp : <conditional>@print-my-sources ;
138""")
139
140 t.run_build_system(status=1)
141 t.expect_output_lines(["My sources:", "bar.cpp"], False)
142 t.expect_output_lines("error: Reference to the project currently being "
143 "loaded requested when there was no project module being loaded.")
144
145 t.cleanup()
146
147
148test_basic()
92f5a8d4 149test_inherit()
7c673cae 150test_glob_in_indirect_conditional()