]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/usr/bin/python |
2 | ||
3 | # Copyright 2008, 2012 Jurko Gospodnetic | |
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 | |
8 | # Tests that generators get selected correctly. | |
9 | # | |
10 | # We do not use the internal C++-compiler CPP --> OBJ generator to avoid | |
11 | # problems with specific compilers or their configurations, e.g. IBM's AIX test | |
12 | # runner 'AIX Version 5.3 TL7 SP5 (5300-07-05-0831)' using the 'IBM XL C/C++ | |
13 | # for AIX, V12.1 (Version: 12.01.0000.0000)' reporting errors when run with a | |
14 | # source file whose suffix is not '.cpp'. | |
15 | ||
16 | import BoostBuild | |
17 | ||
18 | ||
19 | ############################################################################### | |
20 | # | |
21 | # test_generator_added_after_already_building_a_target_of_its_target_type() | |
22 | # ------------------------------------------------------------------------- | |
23 | # | |
24 | ############################################################################### | |
25 | ||
26 | def test_generator_added_after_already_building_a_target_of_its_target_type(): | |
27 | """ | |
28 | Regression test for a Boost Build bug causing it to not use a generator | |
29 | if it got added after already building a target of its target type. | |
30 | ||
31 | """ | |
32 | t = BoostBuild.Tester() | |
33 | ||
34 | t.write("dummy.cpp", "void f() {}\n") | |
35 | ||
36 | t.write("jamroot.jam", """\ | |
37 | import common ; | |
38 | import generators ; | |
39 | import type ; | |
40 | type.register MY_OBJ : my_obj ; | |
41 | generators.register-standard common.copy : CPP : MY_OBJ ; | |
42 | ||
43 | # Building this dummy target must not cause a later defined CPP target type | |
44 | # generator not to be recognized as viable. | |
45 | my-obj dummy : dummy.cpp ; | |
46 | alias the-other-obj : Other//other-obj ; | |
47 | """) | |
48 | ||
49 | t.write("Other/source.extension", "A dummy source file.") | |
50 | ||
51 | t.write("Other/mygen.jam", """\ | |
52 | import common ; | |
53 | import generators ; | |
54 | import type ; | |
55 | type.register MY_TYPE : extension ; | |
56 | generators.register-standard $(__name__).generate-a-cpp-file : MY_TYPE : CPP ; | |
57 | rule generate-a-cpp-file { ECHO Generating a CPP file... ; } | |
58 | CREATE-FILE = [ common.file-creation-command ] ; | |
59 | actions generate-a-cpp-file { $(CREATE-FILE) "$(<)" } | |
60 | """) | |
61 | ||
62 | t.write("Other/mygen.py", """\ | |
92f5a8d4 | 63 | from __future__ import print_function |
7c673cae FG |
64 | import b2.build.generators as generators |
65 | import b2.build.type as type | |
66 | ||
67 | from b2.manager import get_manager | |
68 | ||
69 | import os | |
70 | ||
71 | type.register('MY_TYPE', ['extension']) | |
72 | generators.register_standard('mygen.generate-a-cpp-file', ['MY_TYPE'], ['CPP']) | |
73 | if os.name == 'nt': | |
74 | action = 'echo void g() {} > "$(<)"' | |
75 | else: | |
76 | action = 'echo "void g() {}" > "$(<)"' | |
77 | def f(*args): | |
92f5a8d4 | 78 | print("Generating a CPP file...") |
7c673cae FG |
79 | |
80 | get_manager().engine().register_action("mygen.generate-a-cpp-file", action, | |
81 | function=f) | |
82 | """) | |
83 | ||
84 | t.write("Other/jamfile.jam", """\ | |
85 | import mygen ; | |
86 | my-obj other-obj : source.extension ; | |
87 | """) | |
88 | ||
89 | t.run_build_system() | |
90 | t.expect_output_lines("Generating a CPP file...") | |
11fdf7f2 TL |
91 | t.expect_addition("bin/dummy.my_obj") |
92 | t.expect_addition("Other/bin/other-obj.cpp") | |
93 | t.expect_addition("Other/bin/other-obj.my_obj") | |
7c673cae FG |
94 | t.expect_nothing_more() |
95 | ||
96 | t.cleanup() | |
97 | ||
98 | ||
99 | ############################################################################### | |
100 | # | |
101 | # test_using_a_derived_source_type_created_after_generator_already_used() | |
102 | # ----------------------------------------------------------------------- | |
103 | # | |
104 | ############################################################################### | |
105 | ||
106 | def test_using_a_derived_source_type_created_after_generator_already_used(): | |
107 | """ | |
108 | Regression test for a Boost Build bug causing it to not use a generator | |
109 | with a source type derived from one of the generator's sources but created | |
110 | only after already using the generateor. | |
111 | ||
112 | """ | |
113 | t = BoostBuild.Tester() | |
114 | ||
115 | t.write("dummy.xxx", "Hello. My name is Peter Pan.\n") | |
116 | ||
117 | t.write("jamroot.jam", """\ | |
118 | import common ; | |
119 | import generators ; | |
120 | import type ; | |
121 | type.register XXX : xxx ; | |
122 | type.register YYY : yyy ; | |
123 | generators.register-standard common.copy : XXX : YYY ; | |
124 | ||
125 | # Building this dummy target must not cause a later defined XXX2 target type not | |
126 | # to be recognized as a viable source type for building YYY targets. | |
127 | yyy dummy : dummy.xxx ; | |
128 | alias the-test-output : Other//other ; | |
129 | """) | |
130 | ||
131 | t.write("Other/source.xxx2", "Hello. My name is Tinkerbell.\n") | |
132 | ||
133 | t.write("Other/jamfile.jam", """\ | |
134 | import type ; | |
135 | type.register XXX2 : xxx2 : XXX ; | |
136 | # We are careful not to do anything between defining our new XXX2 target type | |
137 | # and using the XXX --> YYY generator that could potentially cover the Boost | |
138 | # Build bug by clearing its internal viable source target type state. | |
139 | yyy other : source.xxx2 ; | |
140 | """) | |
141 | ||
142 | t.run_build_system() | |
11fdf7f2 TL |
143 | t.expect_addition("bin/dummy.yyy") |
144 | t.expect_addition("Other/bin/other.yyy") | |
7c673cae FG |
145 | t.expect_nothing_more() |
146 | ||
147 | t.cleanup() | |
148 | ||
149 | ||
150 | ############################################################################### | |
151 | # | |
152 | # main() | |
153 | # ------ | |
154 | # | |
155 | ############################################################################### | |
156 | ||
157 | test_generator_added_after_already_building_a_target_of_its_target_type() | |
158 | test_using_a_derived_source_type_created_after_generator_already_used() |