1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
#!/usr/bin/env python3
# Copyright 2003 Dave Abrahams
# Copyright 2002, 2003, 2005, 2006 Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or copy at
# https://www.bfgroup.xyz/b2/LICENSE.txt)
import BoostBuild
def test_basic():
t = BoostBuild.Tester(["-d3", "-d+12"], use_test_config=False)
t.write("a.cpp", """
#include <a.h>
# include "a.h"
#include <x.h>
int main() {}
""")
t.write("a.h", "\n")
t.write("a_c.c", """\
#include <a.h>
# include "a.h"
#include <x.h>
""")
t.write("b.cpp", """\
#include "a.h"
int main() {}
""")
t.write("b.h", "\n")
t.write("c.cpp", """\
#include "x.h"
int main() {}
""")
t.write("e.cpp", """\
#include "x.h"
int main() {}
""")
t.write("x.foo", "")
t.write("y.foo", "")
t.write("src1/a.h", '#include "b.h"\n')
t.write("src1/b.h", '#include "c.h"\n')
t.write("src1/c.h", "\n")
t.write("src1/z.h", """\
extern int dummy_variable_suppressing_empty_file_warning_on_hp_cxx_compiler;
""")
t.write("src2/b.h", "\n")
t.write("jamroot.jam", """\
import foo ;
import types/cpp ;
import types/exe ;
project test : requirements <include>src1 ;
exe a : x.foo a.cpp a_c.c ;
exe b : b.cpp ;
# Because of <define>FOO, c.cpp will be compiled to a different directory than
# everything for main target "a". Therefore, without <implicit-dependency>, C
# preprocessor processing that module will not find "x.h", which is part of
# "a"'s dependency graph.
#
# --------------------------
# More detailed explanation:
# --------------------------
# c.cpp includes x.h which does not exist on the current include path so Boost
# Jam will try to match it to existing Jam targets to cover cases as this one
# where the file is generated by the same build.
#
# However, as x.h is not part of "c" metatarget's dependency graph, Boost
# Build will not actualize its target by default, i.e. create its Jam target.
#
# To get the Jam target created in time, we use the <implicit-dependency>
# feature. This tells Boost Build that it needs to actualize the dependency
# graph for metatarget "a", even though that metatarget has not been directly
# mentioned and is not a dependency for any of the metatargets mentioned in the
# current build request.
#
# Note that Boost Build does not automatically add a dependency between the
# Jam targets in question so, if Boost Jam does not add a dependency on a target
# from that other dependency graph (x.h in our case), i.e. if c.cpp does not
# actually include x.h, us actualizing it will have no effect in the end as
# Boost Jam will not have a reason to actually build those targets in spite of
# knowing about them.
exe c : c.cpp : <define>FOO <implicit-dependency>a ;
""")
t.write("foo.jam", """\
import generators ;
import modules ;
import os ;
import print ;
import type ;
import types/cpp ;
type.register FOO : foo ;
generators.register-standard foo.foo : FOO : CPP H ;
nl = "
" ;
rule foo ( targets * : sources * : properties * )
{
# On NT, you need an exported symbol in order to have an import library
# generated. We will not really use the symbol defined here, just force the
# import library creation.
if ( [ os.name ] = NT || [ modules.peek : OS ] in CYGWIN ) &&
<main-target-type>LIB in $(properties)
{
.decl = "void __declspec(dllexport) foo() {}" ;
}
print.output $(<[1]) ;
print.text $(.decl:E="//")$(nl) ;
print.output $(<[2]) ;
print.text "#include <z.h>"$(nl) ;
}
""")
t.write("foo.py",
r"""import bjam
import b2.build.type as type
import b2.build.generators as generators
from b2.manager import get_manager
type.register("FOO", ["foo"])
generators.register_standard("foo.foo", ["FOO"], ["CPP", "H"])
def prepare_foo(targets, sources, properties):
if properties.get('os') in ['windows', 'cygwin']:
bjam.call('set-target-variable', targets, "DECL",
"void __declspec(dllexport) foo() {}")
get_manager().engine().register_action("foo.foo",
"echo -e $(DECL:E=//)\\n > $(<[1])\n"
"echo -e "#include <z.h>\\n" > $(<[2])\n", function=prepare_foo)
""")
# Check that main target 'c' was able to find 'x.h' from 'a's dependency
# graph.
t.run_build_system()
t.expect_addition("bin/$toolset/debug*/c.exe")
# Check handling of first level includes.
# Both 'a' and 'b' include "a.h" and should be updated.
t.touch("a.h")
t.run_build_system()
t.expect_touch("bin/$toolset/debug*/a.exe")
t.expect_touch("bin/$toolset/debug*/a.obj")
t.expect_touch("bin/$toolset/debug*/a_c.obj")
t.expect_touch("bin/$toolset/debug*/b.exe")
t.expect_touch("bin/$toolset/debug*/b.obj")
t.ignore_touch("bin/*/a.rsp")
t.ignore_touch("bin/*/b.rsp")
t.expect_nothing_more()
# Only source files using include <a.h> should be compiled.
t.touch("src1/a.h")
t.run_build_system()
t.expect_touch("bin/$toolset/debug*/a.exe")
t.expect_touch("bin/$toolset/debug*/a.obj")
t.expect_touch("bin/$toolset/debug*/a_c.obj")
t.ignore_touch("bin/*/a.rsp")
t.expect_nothing_more()
# "src/a.h" includes "b.h" (in the same dir).
t.touch("src1/b.h")
t.run_build_system()
t.expect_touch("bin/$toolset/debug*/a.exe")
t.expect_touch("bin/$toolset/debug*/a.obj")
t.expect_touch("bin/$toolset/debug*/a_c.obj")
t.ignore_touch("bin/*/a.rsp")
t.expect_nothing_more()
# Included by "src/b.h". We had a bug: file included using double quotes
# (e.g. "b.h") was not scanned at all in this case.
t.touch("src1/c.h")
t.run_build_system()
t.expect_touch("bin/$toolset/debug*/a.exe")
t.touch("b.h")
t.run_build_system()
t.expect_nothing_more()
# Test dependency on a generated header.
#
# TODO: we have also to check that generated header is found correctly if
# it is different for different subvariants. Lacking any toolset support,
# this check will be implemented later.
t.touch("x.foo")
t.run_build_system()
t.expect_touch("bin/$toolset/debug*/a.obj")
t.expect_touch("bin/$toolset/debug*/a_c.obj")
# Check that generated headers are scanned for dependencies as well.
t.touch("src1/z.h")
t.run_build_system()
t.expect_touch("bin/$toolset/debug*/a.obj")
t.expect_touch("bin/$toolset/debug*/a_c.obj")
t.cleanup()
def test_scanned_includes_with_absolute_paths():
"""
Regression test: on Windows, <includes> with absolute paths were not
considered when scanning dependencies.
"""
t = BoostBuild.Tester(["-d3", "-d+12"])
t.write("jamroot.jam", """\
path-constant TOP : . ;
exe app : main.cpp : <include>$(TOP)/include ;
""");
t.write("main.cpp", """\
#include <dir/header.h>
int main() {}
""")
t.write("include/dir/header.h", "\n")
t.run_build_system()
t.expect_addition("bin/$toolset/debug*/main.obj")
t.touch("include/dir/header.h")
t.run_build_system()
t.expect_touch("bin/$toolset/debug*/main.obj")
t.cleanup()
test_basic()
test_scanned_includes_with_absolute_paths()
|