]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/test/dependency_test.py
3 # Copyright 2003 Dave Abrahams
4 # Copyright 2002, 2003, 2005, 2006 Vladimir Prus
5 # Distributed under the Boost Software License, Version 1.0.
6 # (See accompanying file LICENSE_1_0.txt or copy at
7 # http://www.boost.org/LICENSE_1_0.txt)
13 t
= BoostBuild
.Tester(["-d3", "-d+12"], pass_d0
=False, use_test_config
=False)
43 t
.write("src1/a.h", '#include "b.h"\n')
44 t
.write("src1/b.h", '#include "c.h"\n')
45 t
.write("src1/c.h", "\n")
46 t
.write("src1/z.h", """\
47 extern int dummy_variable_suppressing_empty_file_warning_on_hp_cxx_compiler;
50 t
.write("src2/b.h", "\n")
52 t
.write("jamroot.jam", """\
57 project test : requirements <include>src1 ;
59 exe a : x.foo a.cpp a_c.c ;
62 # Because of <define>FOO, c.cpp will be compiled to a different directory than
63 # everything for main target "a". Therefore, without <implicit-dependency>, C
64 # preprocessor processing that module will not find "x.h", which is part of
65 # "a"'s dependency graph.
67 # --------------------------
68 # More detailed explanation:
69 # --------------------------
70 # c.cpp includes x.h which does not exist on the current include path so Boost
71 # Jam will try to match it to existing Jam targets to cover cases as this one
72 # where the file is generated by the same build.
74 # However, as x.h is not part of "c" metatarget's dependency graph, Boost
75 # Build will not actualize its target by default, i.e. create its Jam target.
77 # To get the Jam target created in time, we use the <implicit-dependency>
78 # feature. This tells Boost Build that it needs to actualize the dependency
79 # graph for metatarget "a", even though that metatarget has not been directly
80 # mentioned and is not a dependency for any of the metatargets mentioned in the
81 # current build request.
83 # Note that Boost Build does not automatically add a dependency between the
84 # Jam targets in question so, if Boost Jam does not add a dependency on a target
85 # from that other dependency graph (x.h in our case), i.e. if c.cpp does not
86 # actually include x.h, us actualizing it will have no effect in the end as
87 # Boost Jam will not have a reason to actually build those targets in spite of
89 exe c : c.cpp : <define>FOO <implicit-dependency>a ;
92 t
.write("foo.jam", """\
100 type.register FOO : foo ;
102 generators.register-standard foo.foo : FOO : CPP H ;
107 rule foo ( targets * : sources * : properties * )
109 # On NT, you need an exported symbol in order to have an import library
110 # generated. We will not really use the symbol defined here, just force the
111 # import library creation.
112 if ( [ os.name ] = NT || [ modules.peek : OS ] in CYGWIN ) &&
113 <main-target-type>LIB in $(properties)
115 .decl = "void __declspec(dllexport) foo() {}" ;
117 print.output $(<[1]) ;
118 print.text $(.decl:E="//")$(nl) ;
119 print.output $(<[2]) ;
120 print.text "#include <z.h>"$(nl) ;
126 import b2.build.type as type
127 import b2.build.generators as generators
129 from b2.manager import get_manager
131 type.register("FOO", ["foo"])
132 generators.register_standard("foo.foo", ["FOO"], ["CPP", "H"])
134 def prepare_foo(targets, sources, properties):
135 if properties.get('os') in ['windows', 'cygwin']:
136 bjam.call('set-target-variable', targets, "DECL",
137 "void __declspec(dllexport) foo() {}")
139 get_manager().engine().register_action("foo.foo",
140 "echo -e $(DECL:E=//)\\n > $(<[1])\n"
141 "echo -e "#include <z.h>\\n" > $(<[2])\n", function=prepare_foo)
144 # Check that main target 'c' was able to find 'x.h' from 'a's dependency
147 t
.expect_addition("bin/$toolset/debug*/c.exe")
149 # Check handling of first level includes.
151 # Both 'a' and 'b' include "a.h" and should be updated.
155 t
.expect_touch("bin/$toolset/debug*/a.exe")
156 t
.expect_touch("bin/$toolset/debug*/a.obj")
157 t
.expect_touch("bin/$toolset/debug*/a_c.obj")
158 t
.expect_touch("bin/$toolset/debug*/b.exe")
159 t
.expect_touch("bin/$toolset/debug*/b.obj")
160 t
.expect_nothing_more()
162 # Only source files using include <a.h> should be compiled.
166 t
.expect_touch("bin/$toolset/debug*/a.exe")
167 t
.expect_touch("bin/$toolset/debug*/a.obj")
168 t
.expect_touch("bin/$toolset/debug*/a_c.obj")
169 t
.expect_nothing_more()
171 # "src/a.h" includes "b.h" (in the same dir).
174 t
.expect_touch("bin/$toolset/debug*/a.exe")
175 t
.expect_touch("bin/$toolset/debug*/a.obj")
176 t
.expect_touch("bin/$toolset/debug*/a_c.obj")
177 t
.expect_nothing_more()
179 # Included by "src/b.h". We had a bug: file included using double quotes
180 # (e.g. "b.h") was not scanned at all in this case.
183 t
.expect_touch("bin/$toolset/debug*/a.exe")
187 t
.expect_nothing_more()
189 # Test dependency on a generated header.
191 # TODO: we have also to check that generated header is found correctly if
192 # it is different for different subvariants. Lacking any toolset support,
193 # this check will be implemented later.
196 t
.expect_touch("bin/$toolset/debug*/a.obj")
197 t
.expect_touch("bin/$toolset/debug*/a_c.obj")
199 # Check that generated headers are scanned for dependencies as well.
202 t
.expect_touch("bin/$toolset/debug*/a.obj")
203 t
.expect_touch("bin/$toolset/debug*/a_c.obj")
208 def test_scanned_includes_with_absolute_paths():
210 Regression test: on Windows, <includes> with absolute paths were not
211 considered when scanning dependencies.
214 t
= BoostBuild
.Tester(["-d3", "-d+12"], pass_d0
=False)
216 t
.write("jamroot.jam", """\
217 path-constant TOP : . ;
218 exe app : main.cpp : <include>$(TOP)/include ;
221 t
.write("main.cpp", """\
222 #include <dir/header.h>
226 t
.write("include/dir/header.h", "\n")
229 t
.expect_addition("bin/$toolset/debug*/main.obj")
231 t
.touch("include/dir/header.h")
233 t
.expect_touch("bin/$toolset/debug*/main.obj")
239 test_scanned_includes_with_absolute_paths()