aboutsummaryrefslogtreecommitdiff
path: root/build2/cc
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-01-25 15:41:44 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-02-13 12:39:24 +0200
commit88f0780e34116c0441a8d8c58b8a8fd9fde4b1f5 (patch)
tree1240b36211772479dc1220712e0daed4e35ecd85 /build2/cc
parent61aa8e2b4bd7849838c04dc1f421c4760d88319f (diff)
Add model mutex, make var_pool const by default
Diffstat (limited to 'build2/cc')
-rw-r--r--build2/cc/common4
-rw-r--r--build2/cc/common.cxx10
-rw-r--r--build2/cc/compile14
-rw-r--r--build2/cc/compile.cxx48
-rw-r--r--build2/cc/init.cxx67
-rw-r--r--build2/cc/install4
-rw-r--r--build2/cc/install.cxx10
-rw-r--r--build2/cc/link4
-rw-r--r--build2/cc/link.cxx22
-rw-r--r--build2/cc/module.cxx8
10 files changed, 106 insertions, 85 deletions
diff --git a/build2/cc/common b/build2/cc/common
index f0476f9..c11e733 100644
--- a/build2/cc/common
+++ b/build2/cc/common
@@ -210,8 +210,8 @@ namespace build2
private:
file&
- resolve_library (name,
- scope&,
+ resolve_library (scope&,
+ name,
lorder,
const dir_paths&,
optional<dir_paths>&) const;
diff --git a/build2/cc/common.cxx b/build2/cc/common.cxx
index 6429a38..b941e6e 100644
--- a/build2/cc/common.cxx
+++ b/build2/cc/common.cxx
@@ -4,7 +4,7 @@
#include <build2/cc/common>
-#include <build2/file> // import()
+#include <build2/file> // import()
#include <build2/scope>
#include <build2/context>
#include <build2/variable>
@@ -287,7 +287,7 @@ namespace build2
if (sysd == nullptr) find_sysd ();
if (!lo) find_lo ();
- file& t (resolve_library (n, bs, *lo, *sysd, usrd));
+ file& t (resolve_library (bs, n, *lo, *sysd, usrd));
if (proc_lib)
{
@@ -386,8 +386,8 @@ namespace build2
// that's the only way to guarantee it will be up-to-date.
//
file& common::
- resolve_library (name n,
- scope& s,
+ resolve_library (scope& s,
+ name n,
lorder lo,
const dir_paths& sysd,
optional<dir_paths>& usrd) const
@@ -768,7 +768,7 @@ namespace build2
const char* bl (lt.a != nullptr
? (lt.s != nullptr ? "both" : "static")
: "shared");
- lt.assign ("bin.lib") = bl;
+ lt.assign (var_pool["bin.lib"]) = bl;
target* r (l ? &lt : (p.is_a<liba> () ? static_cast<target*> (a) : s));
diff --git a/build2/cc/compile b/build2/cc/compile
index 67897f2..11b3919 100644
--- a/build2/cc/compile
+++ b/build2/cc/compile
@@ -27,10 +27,10 @@ namespace build2
compile (data&&);
virtual match_result
- match (action, target&, const string& hint) const override;
+ match (slock&, action, target&, const string& hint) const override;
virtual recipe
- apply (action, target&) const override;
+ apply (slock&, action, target&) const override;
target_state
perform_update (action, target&) const;
@@ -40,10 +40,10 @@ namespace build2
private:
void
- append_lib_options (cstrings&, target&, scope&, lorder) const;
+ append_lib_options (scope&, cstrings&, target&, lorder) const;
void
- hash_lib_options (sha256&, target&, scope&, lorder) const;
+ hash_lib_options (scope&, sha256&, target&, lorder) const;
// Mapping of include prefixes (e.g., foo in <foo/bar>) for auto-
// generated headers to directories where they will be generated.
@@ -61,10 +61,10 @@ namespace build2
append_prefixes (prefix_map&, target&, const variable&) const;
void
- append_lib_prefixes (prefix_map&, target&, scope&, lorder) const;
+ append_lib_prefixes (scope&, prefix_map&, target&, lorder) const;
prefix_map
- build_prefix_map (target&, scope&, lorder) const;
+ build_prefix_map (scope&, target&, lorder) const;
// Reverse-lookup target type from extension.
//
@@ -74,7 +74,7 @@ namespace build2
// Header dependency injection.
//
void
- inject (action, target&, lorder, file&, depdb&) const;
+ inject (slock&, action, target&, lorder, file&, depdb&) const;
private:
const string rule_id;
diff --git a/build2/cc/compile.cxx b/build2/cc/compile.cxx
index f837765..bc35272 100644
--- a/build2/cc/compile.cxx
+++ b/build2/cc/compile.cxx
@@ -44,7 +44,7 @@ namespace build2
"insufficient space");
match_result compile::
- match (action a, target& t, const string&) const
+ match (slock& ml, action a, target& t, const string&) const
{
tracer trace (x, "compile::match");
@@ -58,7 +58,8 @@ namespace build2
// file specified for an obj*{} member overrides the one specified for
// the group. Also "see through" groups.
//
- for (prerequisite_member p: reverse_group_prerequisite_members (a, t))
+ for (prerequisite_member p:
+ reverse_group_prerequisite_members (ml, a, t))
{
if (p.is_a (x_src))
{
@@ -75,7 +76,7 @@ namespace build2
// (first one is cc.export.*) recursively, prerequisite libraries first.
//
void compile::
- append_lib_options (cstrings& args, target& t, scope& bs, lorder lo) const
+ append_lib_options (scope& bs, cstrings& args, target& t, lorder lo) const
{
auto opt = [&args, this] (file& l, const string& t, bool com, bool exp)
{
@@ -116,7 +117,7 @@ namespace build2
}
void compile::
- hash_lib_options (sha256& cs, target& t, scope& bs, lorder lo) const
+ hash_lib_options (scope& bs, sha256& cs, target& t, lorder lo) const
{
auto opt = [&cs, this] (file& l, const string& t, bool com, bool exp)
{
@@ -155,7 +156,7 @@ namespace build2
// recursively, prerequisite libraries first.
//
void compile::
- append_lib_prefixes (prefix_map& m, target& t, scope& bs, lorder lo) const
+ append_lib_prefixes (scope& bs, prefix_map& m, target& t, lorder lo) const
{
auto opt = [&m, this] (file& l, const string& t, bool com, bool exp)
{
@@ -191,7 +192,7 @@ namespace build2
}
recipe compile::
- apply (action a, target& xt) const
+ apply (slock& ml, action a, target& xt) const
{
tracer trace (x, "compile::apply");
@@ -250,7 +251,7 @@ namespace build2
// Inject dependency on the output directory.
//
- fsdir* dir (inject_fsdir (a, t));
+ fsdir* dir (inject_fsdir (ml, a, t));
// Search and match all the existing prerequisites. The injection code
// takes care of the ones it is adding.
@@ -260,7 +261,7 @@ namespace build2
//
optional<dir_paths> usr_lib_dirs; // Extract lazily.
- for (prerequisite_member p: group_prerequisite_members (a, t))
+ for (prerequisite_member p: group_prerequisite_members (ml, a, t))
{
// A dependency on a library is there so that we can get its
// *.export.poptions. In particular, making sure it is executed before
@@ -281,7 +282,7 @@ namespace build2
search_library (
sys_lib_dirs, usr_lib_dirs, p.prerequisite) == nullptr)
{
- match_only (a, p.search ());
+ match_only (ml, a, p.search ());
}
}
@@ -293,7 +294,7 @@ namespace build2
if (a.operation () == clean_id && !pt.dir.sub (rs.out_path ()))
continue;
- build2::match (a, pt);
+ build2::match (ml, a, pt);
t.prerequisite_targets.push_back (&pt);
}
@@ -351,7 +352,7 @@ namespace build2
// Hash *.export.poptions from prerequisite libraries.
//
- hash_lib_options (cs, t, bs, lo);
+ hash_lib_options (bs, cs, t, lo);
// Extra system header dirs (last).
//
@@ -385,7 +386,7 @@ namespace build2
if (dd.writing () || dd.mtime () > t.mtime ())
t.mtime (timestamp_nonexistent);
- inject (a, t, lo, src, dd);
+ inject (ml, a, t, lo, src, dd);
dd.close ();
}
@@ -525,7 +526,7 @@ namespace build2
}
auto compile::
- build_prefix_map (target& t, scope& bs, lorder lo) const -> prefix_map
+ build_prefix_map (scope& bs, target& t, lorder lo) const -> prefix_map
{
prefix_map m;
@@ -536,7 +537,7 @@ namespace build2
// Then process the include directories from prerequisite libraries.
//
- append_lib_prefixes (m, t, bs, lo);
+ append_lib_prefixes (bs, m, t, lo);
return m;
}
@@ -715,7 +716,12 @@ namespace build2
}
void compile::
- inject (action a, target& t, lorder lo, file& src, depdb& dd) const
+ inject (slock& ml,
+ action a,
+ target& t,
+ lorder lo,
+ file& src,
+ depdb& dd) const
{
tracer trace (x, "compile::inject");
@@ -739,14 +745,14 @@ namespace build2
const process_path* xc (nullptr);
cstrings args;
- auto init_args = [&t, lo, &src, &rs, &bs, &xc, &args, this] ()
+ auto init_args = [&ml, &t, lo, &src, &rs, &bs, &xc, &args, this] ()
{
xc = &cast<process_path> (rs[x_path]);
args.push_back (xc->recall_string ());
// Add *.export.poptions from prerequisite libraries.
//
- append_lib_options (args, t, bs, lo);
+ append_lib_options (bs, args, t, lo);
append_options (args, t, c_poptions);
append_options (args, t, x_poptions);
@@ -895,7 +901,7 @@ namespace build2
// from the depdb cache or from the compiler run. Return whether the
// extraction process should be restarted.
//
- auto add = [&trace, &update, &pm, a, &t, lo, &dd, &bs, this]
+ auto add = [&trace, &ml, &update, &pm, a, &t, lo, &dd, &bs, this]
(path f, bool cache) -> bool
{
// Find or maybe insert the target.
@@ -991,7 +997,7 @@ namespace build2
// then we would have failed below.
//
if (pm.empty ())
- pm = build_prefix_map (t, bs, lo);
+ pm = build_prefix_map (bs, t, lo);
// First try the whole file. Then just the directory.
//
@@ -1068,7 +1074,7 @@ namespace build2
// Match to a rule.
//
- build2::match (a, *pt);
+ build2::match (ml, a, *pt);
// Update.
//
@@ -1417,7 +1423,7 @@ namespace build2
// Add *.export.poptions from prerequisite libraries.
//
- append_lib_options (args, t, bs, lo);
+ append_lib_options (bs, args, t, lo);
// Extra system header dirs (last).
//
diff --git a/build2/cc/init.cxx b/build2/cc/init.cxx
index a162daa..ebe7653 100644
--- a/build2/cc/init.cxx
+++ b/build2/cc/init.cxx
@@ -35,7 +35,7 @@ namespace build2
// Enter variables. Note: some overridable, some not.
//
- auto& v (var_pool);
+ auto& v (var_pool.rw (r));
v.insert<strings> ("config.cc.poptions", true);
v.insert<strings> ("config.cc.coptions", true);
@@ -90,10 +90,12 @@ namespace build2
assert (first);
+ auto& vp (var_pool.rw (rs));
+
// Load cc.core.vars.
//
if (!cast_false<bool> (rs["cc.core.vars.loaded"]))
- load_module ("cc.core.vars", rs, rs, loc);
+ load_module (rs, rs, "cc.core.vars", loc);
// Configure.
//
@@ -169,14 +171,20 @@ namespace build2
variable_map h;
if (first)
{
- h.assign ("config.bin.target") =
- cast<target_triplet> (rs["cc.target"]).string ();
+ // Note that these variables have not yet been registered (we don't
+ // yet have the "bin.vars" module).
+ //
+ const variable& t (vp.insert ("config.bin.target"));
+ h.assign (t) = cast<target_triplet> (rs["cc.target"]).string ();
if (auto l = hints["config.bin.pattern"])
- h.assign ("config.bin.pattern") = cast<string> (l);
+ {
+ const variable& p (vp.insert ("config.bin.pattern"));
+ h.assign (p) = cast<string> (l);
+ }
}
- load_module ("bin.config", rs, rs, loc, false, h);
+ load_module (rs, rs, "bin.config", loc, false, h);
}
// Verify bin's target matches ours (we do it even if we loaded it
@@ -205,20 +213,20 @@ namespace build2
if (cast<string> (l) != "shared")
{
if (!cast_false<bool> (rs["bin.ar.config.loaded"]))
- load_module ("bin.ar.config", rs, rs, loc);
+ load_module (rs, rs, "bin.ar.config", loc);
}
}
if (cid == "msvc")
{
if (!cast_false<bool> (rs["bin.ld.config.loaded"]))
- load_module ("bin.ld.config", rs, rs, loc);
+ load_module (rs, rs, "bin.ld.config", loc);
}
if (tsys == "mingw32")
{
if (!cast_false<bool> (rs["bin.rc.config.loaded"]))
- load_module ("bin.rc.config", rs, rs, loc);
+ load_module (rs, rs, "bin.rc.config", loc);
}
// Load (optionally) the pkgconfig.config module.
@@ -233,10 +241,13 @@ namespace build2
// Prepare configuration hints.
//
variable_map h;
- h.assign ("config.pkgconfig.target") =
- cast<target_triplet> (rs["cc.target"]);
- load_module ("pkgconfig.config", rs, rs, loc, true, h);
+ // Note that this variable has not yet been registered.
+ //
+ const variable& t (vp.insert ("config.pkgconfig.target"));
+ h.assign (t) = cast<target_triplet> (rs["cc.target"]);
+
+ load_module (rs, rs, "pkgconfig.config", loc, true, h);
}
return true;
@@ -259,12 +270,12 @@ namespace build2
// Load cc.core.config.
//
if (!cast_false<bool> (rs["cc.core.config.loaded"]))
- load_module ("cc.core.config", rs, rs, loc, false, hints);
+ load_module (rs, rs, "cc.core.config", loc, false, hints);
// Load the bin module.
//
if (!cast_false<bool> (rs["bin.loaded"]))
- load_module ("bin", rs, rs, loc);
+ load_module (rs, rs, "bin", loc);
const string& cid (cast<string> (rs["cc.id"]));
const string& tsys (cast<string> (rs["cc.target.system"]));
@@ -277,7 +288,7 @@ namespace build2
if (cast<string> (l) != "shared")
{
if (!cast_false<bool> (rs["bin.ar.loaded"]))
- load_module ("bin.ar", rs, rs, loc);
+ load_module (rs, rs, "bin.ar", loc);
}
}
@@ -287,7 +298,7 @@ namespace build2
if (cid == "msvc")
{
if (!cast_false<bool> (rs["bin.ld.loaded"]))
- load_module ("bin.ld", rs, rs, loc);
+ load_module (rs, rs, "bin.ld", loc);
}
// If our target is MinGW, then we will need the resource compiler
@@ -296,7 +307,7 @@ namespace build2
if (tsys == "mingw32")
{
if (!cast_false<bool> (rs["bin.rc.loaded"]))
- load_module ("bin.rc", rs, rs, loc);
+ load_module (rs, rs, "bin.rc", loc);
}
return true;
@@ -308,13 +319,13 @@ namespace build2
//
static inline bool
init_alias (tracer& trace,
+ scope& rs,
+ scope& bs,
const char* m,
const char* c,
const char* c_loaded,
const char* cxx,
const char* cxx_loaded,
- scope& rs,
- scope& bs,
const location& loc,
const variable_map& hints)
{
@@ -338,13 +349,13 @@ namespace build2
//
if (lc && lp && rs["config.c"])
{
- load_module (c, rs, rs, loc, false, hints);
- load_module (cxx, rs, rs, loc, false, hints);
+ load_module (rs, rs, c, loc, false, hints);
+ load_module (rs, rs, cxx, loc, false, hints);
}
else
{
- if (lp) load_module (cxx, rs, rs, loc, false, hints);
- if (lc) load_module (c, rs, rs, loc, false, hints);
+ if (lp) load_module (rs, rs, cxx, loc, false, hints);
+ if (lc) load_module (rs, rs, c, loc, false, hints);
}
return true;
@@ -360,10 +371,11 @@ namespace build2
const variable_map& hints)
{
tracer trace ("cc::config_init");
- return init_alias (trace, "cc.config",
+ return init_alias (trace, rs, bs,
+ "cc.config",
"c.config", "c.config.loaded",
"cxx.config", "cxx.config.loaded",
- rs, bs, loc, hints);
+ loc, hints);
}
bool
@@ -376,10 +388,11 @@ namespace build2
const variable_map& hints)
{
tracer trace ("cc::init");
- return init_alias (trace, "cc",
+ return init_alias (trace, rs, bs,
+ "cc",
"c", "c.loaded",
"cxx", "cxx.loaded",
- rs, bs, loc, hints);
+ loc, hints);
}
}
}
diff --git a/build2/cc/install b/build2/cc/install
index 561ed87..ff7af4d 100644
--- a/build2/cc/install
+++ b/build2/cc/install
@@ -25,10 +25,10 @@ namespace build2
install (data&&, const link&);
virtual target*
- filter (action, target&, prerequisite_member) const override;
+ filter (slock&, action, target&, prerequisite_member) const override;
virtual match_result
- match (action, target&, const string&) const override;
+ match (slock&, action, target&, const string&) const override;
virtual void
install_extra (file&, const install_dir&) const override;
diff --git a/build2/cc/install.cxx b/build2/cc/install.cxx
index 28d7db2..074654b 100644
--- a/build2/cc/install.cxx
+++ b/build2/cc/install.cxx
@@ -23,7 +23,7 @@ namespace build2
install (data&& d, const link& l): common (move (d)), link_ (l) {}
target* install::
- filter (action a, target& t, prerequisite_member p) const
+ filter (slock& ml, action a, target& t, prerequisite_member p) const
{
if (t.is_a<exe> ())
{
@@ -53,11 +53,11 @@ namespace build2
return pt->in (t.weak_scope ()) ? pt : nullptr;
}
- return file_rule::filter (a, t, p);
+ return file_rule::filter (ml, a, t, p);
}
match_result install::
- match (action a, target& t, const string& hint) const
+ match (slock& ml, action a, target& t, const string& hint) const
{
// @@ How do we split the hint between the two?
//
@@ -65,8 +65,8 @@ namespace build2
// We only want to handle installation if we are also the
// ones building this target. So first run link's match().
//
- match_result r (link_.match (a, t, hint));
- return r ? install::file_rule::match (a, t, "") : r;
+ match_result r (link_.match (ml, a, t, hint));
+ return r ? install::file_rule::match (ml, a, t, "") : r;
}
void install::
diff --git a/build2/cc/link b/build2/cc/link
index c7d3c93..5f28204 100644
--- a/build2/cc/link
+++ b/build2/cc/link
@@ -25,10 +25,10 @@ namespace build2
link (data&&);
virtual match_result
- match (action, target&, const string& hint) const override;
+ match (slock&, action, target&, const string& hint) const override;
virtual recipe
- apply (action, target&) const override;
+ apply (slock&, action, target&) const override;
target_state
perform_update (action, target&) const;
diff --git a/build2/cc/link.cxx b/build2/cc/link.cxx
index c94eb26..6de294a 100644
--- a/build2/cc/link.cxx
+++ b/build2/cc/link.cxx
@@ -41,7 +41,7 @@ namespace build2
}
match_result link::
- match (action a, target& t, const string& hint) const
+ match (slock& ml, action a, target& t, const string& hint) const
{
tracer trace (x, "link::match");
@@ -64,7 +64,7 @@ namespace build2
//
bool seen_x (false), seen_c (false), seen_obj (false), seen_lib (false);
- for (prerequisite_member p: group_prerequisite_members (a, t))
+ for (prerequisite_member p: group_prerequisite_members (ml, a, t))
{
if (p.is_a (x_src))
{
@@ -145,7 +145,7 @@ namespace build2
optional<dir_paths> usr_lib_dirs; // Extract lazily.
- for (prerequisite_member p: group_prerequisite_members (a, t))
+ for (prerequisite_member p: group_prerequisite_members (ml, a, t))
{
if (p.is_a<lib> () || p.is_a<liba> () || p.is_a<libs> ())
{
@@ -159,7 +159,7 @@ namespace build2
if (pt == nullptr)
{
pt = &p.search ();
- match_only (a, *pt);
+ match_only (ml, a, *pt);
}
// If the prerequisite came from the lib{} group, then also
@@ -316,7 +316,7 @@ namespace build2
}
recipe link::
- apply (action a, target& xt) const
+ apply (slock& ml, action a, target& xt) const
{
tracer trace (x, "link::apply");
@@ -415,7 +415,7 @@ namespace build2
// Inject dependency on the output directory.
//
- inject_fsdir (a, t);
+ inject_fsdir (ml, a, t);
optional<dir_paths> usr_lib_dirs; // Extract lazily.
@@ -429,7 +429,7 @@ namespace build2
lt == otype::a ? obja::static_type :
objs::static_type);
- for (prerequisite_member p: group_prerequisite_members (a, t))
+ for (prerequisite_member p: group_prerequisite_members (ml, a, t))
{
target* pt (nullptr);
@@ -471,7 +471,7 @@ namespace build2
pt = &link_member (*l, lo);
}
- build2::match (a, *pt);
+ build2::match (ml, a, *pt);
t.prerequisite_targets.push_back (pt);
continue;
}
@@ -567,7 +567,7 @@ namespace build2
//
bool found (false);
for (prerequisite_member p1:
- reverse_group_prerequisite_members (a, *pt))
+ reverse_group_prerequisite_members (ml, a, *pt))
{
// Most of the time we will have just a single source so fast-path
// that case.
@@ -576,7 +576,7 @@ namespace build2
{
if (!found)
{
- build2::match (a, *pt); // Now p1 should be resolved.
+ build2::match (ml, a, *pt); // Now p1 should be resolved.
// Searching our own prerequisite is ok.
//
@@ -637,7 +637,7 @@ namespace build2
ot.prerequisites.emplace_back (p);
}
- build2::match (a, *pt);
+ build2::match (ml, a, *pt);
}
t.prerequisite_targets.push_back (pt);
diff --git a/build2/cc/module.cxx b/build2/cc/module.cxx
index 3e20694..c7c7c3c 100644
--- a/build2/cc/module.cxx
+++ b/build2/cc/module.cxx
@@ -279,6 +279,8 @@ namespace build2
//
variable_map h;
+ // Note that all these variables have already been registered.
+ //
h.assign ("config.cc.id") = cast<string> (rs[x_id]);
h.assign ("config.cc.target") = cast<target_triplet> (rs[x_target]);
@@ -288,7 +290,7 @@ namespace build2
if (!ci.bin_pattern.empty ())
h.assign ("config.bin.pattern") = move (ci.bin_pattern);
- load_module ("cc.core.config", rs, rs, loc, false, h);
+ load_module (rs, rs, "cc.core.config", loc, false, h);
}
else
{
@@ -331,7 +333,7 @@ namespace build2
// extra bin.* modules we may need.
//
if (!cast_false<bool> (rs["cc.core.loaded"]))
- load_module ("cc.core", rs, rs, loc);
+ load_module (rs, rs, "cc.core", loc);
// Register target types and configure their "installability".
//
@@ -347,7 +349,7 @@ namespace build2
for (const target_type* const* ht (x_hdr); *ht != nullptr; ++ht)
{
t.insert (**ht);
- install_path (**ht, rs, dir_path ("include"));
+ install_path (rs, **ht, dir_path ("include"));
}
}