From 4f5b6cb7ed4e05e98cce7e692462f49e24b7a39a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 22 Aug 2019 14:38:57 +0200 Subject: Targets, scopes, vars --- build2/cc/common.cxx | 43 +++++++++++++++++++---------------- build2/cc/common.hxx | 4 +++- build2/cc/compile-rule.cxx | 56 ++++++++++++++++++++++++++-------------------- build2/cc/init.cxx | 5 +++-- build2/cc/link-rule.cxx | 13 ++++++----- build2/cc/module.cxx | 16 +++++++------ build2/cc/msvc.cxx | 9 ++++++-- build2/cc/pkgconfig.cxx | 4 ++-- build2/cc/utility.cxx | 2 +- 9 files changed, 88 insertions(+), 64 deletions(-) (limited to 'build2/cc') diff --git a/build2/cc/common.cxx b/build2/cc/common.cxx index aa0eb89..4f5db4c 100644 --- a/build2/cc/common.cxx +++ b/build2/cc/common.cxx @@ -87,7 +87,7 @@ namespace build2 bool impl (proc_impl && proc_impl (l, la)); bool cc (false), same (false); - auto& vp (var_pool); + auto& vp (top_bs.ctx.var_pool); lookup c_e_libs; lookup x_e_libs; @@ -221,7 +221,7 @@ namespace build2 : &cast ( bs.root_scope ()->vars[same ? x_sys_lib_dirs - : var_pool[*t + ".sys_lib_dirs"]]); + : bs.ctx.var_pool[*t + ".sys_lib_dirs"]]); }; auto find_linfo = [top_li, t, cc, &bs, &l, &li] () @@ -474,7 +474,7 @@ namespace build2 if (xt == nullptr) { if (n.qualified ()) - xt = import_existing (pk); + xt = import_existing (s.ctx, pk); } if (xt == nullptr) @@ -494,20 +494,21 @@ namespace build2 // template ulock common:: - insert_library (T*& r, + insert_library (context& ctx, + T*& r, const string& name, const dir_path& d, optional ext, bool exist, tracer& trace) { - auto p (targets.insert_locked (T::static_type, - d, - dir_path (), - name, - move (ext), - true, // Implied. - trace)); + auto p (ctx.targets.insert_locked (T::static_type, + d, + dir_path (), + name, + move (ext), + true, // Implied. + trace)); assert (!exist || !p.second.owns_lock ()); r = &p.first.template as (); @@ -626,6 +627,8 @@ namespace build2 &name, ext, &p, &f, exist, &trace, this] (const dir_path& d) -> bool { + context& ctx (p.scope->ctx); + timestamp mt; // libs @@ -648,9 +651,10 @@ namespace build2 if (tclass == "windows") { libi* i (nullptr); - insert_library (i, name, d, se, exist, trace); + insert_library (ctx, i, name, d, se, exist, trace); - ulock l (insert_library (s, name, d, nullopt, exist, trace)); + ulock l ( + insert_library (ctx, s, name, d, nullopt, exist, trace)); if (!exist) { @@ -677,7 +681,7 @@ namespace build2 } else { - insert_library (s, name, d, se, exist, trace); + insert_library (ctx, s, name, d, se, exist, trace); s->mtime (mt); s->path (move (f)); @@ -697,7 +701,7 @@ namespace build2 if (mt != timestamp_nonexistent) { - insert_library (s, name, d, se, exist, trace); + insert_library (ctx, s, name, d, se, exist, trace); s->mtime (mt); s->path (move (f)); @@ -722,7 +726,7 @@ namespace build2 // Note that this target is outside any project which we treat // as out trees. // - insert_library (a, name, d, ae, exist, trace); + insert_library (ctx, a, name, d, ae, exist, trace); a->mtime (mt); a->path (move (f)); } @@ -760,14 +764,14 @@ namespace build2 if (na && !r.first.empty ()) { - insert_library (a, name, d, nullopt, exist, trace); + insert_library (ctx, a, name, d, nullopt, exist, trace); a->mtime (timestamp_unreal); a->path (empty_path); } if (ns && !r.second.empty ()) { - insert_library (s, name, d, nullopt, exist, trace); + insert_library (ctx, s, name, d, nullopt, exist, trace); s->mtime (timestamp_unreal); s->path (empty_path); } @@ -821,7 +825,8 @@ namespace build2 // Enter (or find) the lib{} target group. // lib* lt; - insert_library (lt, name, *pd, l ? p.tk.ext : nullopt, exist, trace); + insert_library ( + p.scope->ctx, lt, name, *pd, l ? p.tk.ext : nullopt, exist, trace); // Result. // diff --git a/build2/cc/common.hxx b/build2/cc/common.hxx index c58a7f3..b24eb7d 100644 --- a/build2/cc/common.hxx +++ b/build2/cc/common.hxx @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -278,7 +279,8 @@ namespace build2 template static ulock - insert_library (T*&, + insert_library (context&, + T*&, const string&, const dir_path&, optional, diff --git a/build2/cc/compile-rule.cxx b/build2/cc/compile-rule.cxx index 833fd44..9dede21 100644 --- a/build2/cc/compile-rule.cxx +++ b/build2/cc/compile-rule.cxx @@ -365,7 +365,9 @@ namespace build2 const variable& var ( com ? c_export_poptions - : (t == x ? x_export_poptions : var_pool[t + ".export.poptions"])); + : (t == x + ? x_export_poptions + : l.ctx.var_pool[t + ".export.poptions"])); append_options (args, l, var); }; @@ -418,7 +420,9 @@ namespace build2 const variable& var ( com ? c_export_poptions - : (t == x ? x_export_poptions : var_pool[t + ".export.poptions"])); + : (t == x + ? x_export_poptions + : l.ctx.var_pool[t + ".export.poptions"])); hash_options (cs, l, var); }; @@ -472,7 +476,9 @@ namespace build2 const variable& var ( com ? c_export_poptions - : (t == x ? x_export_poptions : var_pool[t + ".export.poptions"])); + : (t == x + ? x_export_poptions + : l.ctx.var_pool[t + ".export.poptions"])); append_prefixes (m, l, var); }; @@ -2161,7 +2167,7 @@ namespace build2 // small_vector tts; - const scope& bs (scopes.find (d)); + const scope& bs (t.ctx.scopes.find (d)); if (const scope* rs = bs.root_scope ()) { tts = map_extension (bs, n, e); @@ -2201,7 +2207,7 @@ namespace build2 // absolute path with a spelled-out extension to multiple targets. // for (const target_type* tt: tts) - if ((r = targets.find (*tt, d, out, n, e, trace)) != nullptr) + if ((r = t.ctx.targets.find (*tt, d, out, n, e, trace)) != nullptr) break; // Note: we can't do this because of the in-source builds where @@ -2887,7 +2893,7 @@ namespace build2 // See if this path is inside a project with an out-of- // tree build and is in the out directory tree. // - const scope& bs (scopes.find (d)); + const scope& bs (t.ctx.scopes.find (d)); if (bs.root_scope () != nullptr) { const dir_path& bp (bs.out_path ()); @@ -5101,7 +5107,7 @@ namespace build2 modules_sidebuild_dir /= x); - const scope* ps (&scopes.find (pd)); + const scope* ps (&rs.ctx.scopes.find (pd)); if (ps->out_path () != pd) { @@ -5112,7 +5118,7 @@ namespace build2 // Re-test again now that we are in exclusive phase (another thread // could have already created and loaded the subproject). // - ps = &scopes.find (pd); + ps = &rs.ctx.scopes.find (pd); if (ps->out_path () != pd) { @@ -5200,7 +5206,7 @@ namespace build2 // exists then we assume all this is already done (otherwise why would // someone have created such a target). // - if (const file* bt = targets.find ( + if (const file* bt = bs.ctx.targets.find ( tt, pd, dir_path (), // Always in the out tree. @@ -5237,13 +5243,14 @@ namespace build2 } } - auto p (targets.insert_locked (tt, - move (pd), - dir_path (), // Always in the out tree. - move (mf), - nullopt, // Use default extension. - true, // Implied. - trace)); + auto p (bs.ctx.targets.insert_locked ( + tt, + move (pd), + dir_path (), // Always in the out tree. + move (mf), + nullopt, // Use default extension. + true, // Implied. + trace)); file& bt (static_cast (p.first)); // Note that this is racy and someone might have created this target @@ -5295,7 +5302,7 @@ namespace build2 const target_type& tt (compile_types (li.type).hbmi); - if (const file* bt = targets.find ( + if (const file* bt = bs.ctx.targets.find ( tt, pd, dir_path (), // Always in the out tree. @@ -5307,13 +5314,14 @@ namespace build2 prerequisites ps; ps.push_back (prerequisite (ht)); - auto p (targets.insert_locked (tt, - move (pd), - dir_path (), // Always in the out tree. - move (mf), - nullopt, // Use default extension. - true, // Implied. - trace)); + auto p (bs.ctx.targets.insert_locked ( + tt, + move (pd), + dir_path (), // Always in the out tree. + move (mf), + nullopt, // Use default extension. + true, // Implied. + trace)); file& bt (static_cast (p.first)); // Note that this is racy and someone might have created this target diff --git a/build2/cc/init.cxx b/build2/cc/init.cxx index e22ece7..3ff59a1 100644 --- a/build2/cc/init.cxx +++ b/build2/cc/init.cxx @@ -77,7 +77,7 @@ namespace build2 // Enter variables. Note: some overridable, some not. // - auto& v (var_pool.rw (rs)); + auto& v (rs.ctx.var_pool.rw (rs)); auto v_t (variable_visibility::target); @@ -276,7 +276,8 @@ namespace build2 // Prepare configuration hints. They are only used on the first load // of bin.config so we only populate them on our first load. // - variable_map h; + variable_map h (rs.ctx); + if (first) { // Note that all these variables have already been registered. diff --git a/build2/cc/link-rule.cxx b/build2/cc/link-rule.cxx index bb91722..09109c2 100644 --- a/build2/cc/link-rule.cxx +++ b/build2/cc/link-rule.cxx @@ -165,14 +165,15 @@ namespace build2 // otherwise the above search would have returned the member // target. // - pt = search_existing (p.prerequisite.key (tt)); + pt = search_existing (t.ctx, p.prerequisite.key (tt)); } } else if (!p.is_a ()) { // See if we also/instead have a group. // - pg = search_existing (p.prerequisite.key (libul::static_type)); + pg = search_existing (t.ctx, + p.prerequisite.key (libul::static_type)); if (pt == nullptr) swap (pt, pg); @@ -1163,7 +1164,7 @@ namespace build2 bool u; if ((u = pt->is_a ()) || pt->is_a ()) { - const variable& var (var_pool["bin.whole"]); // @@ Cache. + const variable& var (t.ctx.var_pool["bin.whole"]); // @@ Cache. // See the bin module for the lookup semantics discussion. Note // that the variable is not overridable so we omit find_override() @@ -1473,7 +1474,7 @@ namespace build2 ? (exp ? c_export_loptions : c_loptions) : (t == x ? (exp ? x_export_loptions : x_loptions) - : var_pool[t + (exp ? ".export.loptions" : ".loptions")])); + : l.ctx.var_pool[t + (exp ? ".export.loptions" : ".loptions")])); append_options (d.args, *g, var); } @@ -1575,7 +1576,7 @@ namespace build2 ? (exp ? c_export_loptions : c_loptions) : (t == x ? (exp ? x_export_loptions : x_loptions) - : var_pool[t + (exp ? ".export.loptions" : ".loptions")])); + : l.ctx.var_pool[t + (exp ? ".export.loptions" : ".loptions")])); hash_options (d.cs, *g, var); } @@ -1966,7 +1967,7 @@ namespace build2 const string& cs ( cast ( rs[tsys == "win32-msvc" - ? var_pool["bin.ld.checksum"] + ? t.ctx.var_pool["bin.ld.checksum"] : x_checksum])); if (dd.expect (cs) != nullptr) diff --git a/build2/cc/module.cxx b/build2/cc/module.cxx index 36cdd1a..064d954 100644 --- a/build2/cc/module.cxx +++ b/build2/cc/module.cxx @@ -41,9 +41,13 @@ namespace build2 config::save_module (rs, x, 250); - const variable& config_c_poptions (var_pool["config.cc.poptions"]); - const variable& config_c_coptions (var_pool["config.cc.coptions"]); - const variable& config_c_loptions (var_pool["config.cc.loptions"]); + auto& vp (rs.ctx.var_pool.rw (rs)); + + // Must already exist. + // + const variable& config_c_poptions (vp["config.cc.poptions"]); + const variable& config_c_coptions (vp["config.cc.coptions"]); + const variable& config_c_loptions (vp["config.cc.loptions"]); // config.x // @@ -63,8 +67,6 @@ namespace build2 // if (!cc_loaded) { - auto& vp (var_pool.rw (rs)); - for (const char* const* pm (x_hinters); *pm != nullptr; ++pm) { string m (*pm); @@ -201,7 +203,7 @@ namespace build2 { // Prepare configuration hints. // - variable_map h; + variable_map h (rs.ctx); // Note that all these variables have already been registered. // @@ -545,7 +547,7 @@ namespace build2 // if (!cast_false (rs["cc.core.config.loaded"])) { - variable_map h; + variable_map h (rs.ctx); if (!ci.bin_pattern.empty ()) h.assign ("config.bin.pattern") = ci.bin_pattern; diff --git a/build2/cc/msvc.cxx b/build2/cc/msvc.cxx index 6125fdd..7d8c3f5 100644 --- a/build2/cc/msvc.cxx +++ b/build2/cc/msvc.cxx @@ -365,6 +365,7 @@ namespace build2 { // Pretty similar logic to search_library(). // + assert (p.scope != nullptr); const optional& ext (p.tk.ext); const string& name (*p.tk.name); @@ -403,7 +404,7 @@ namespace build2 // Enter the target. // T* t; - common::insert_library (t, name, d, e, exist, trace); + common::insert_library (p.scope->ctx, t, name, d, e, exist, trace); t->mtime (mt); t->path (move (f)); @@ -453,6 +454,8 @@ namespace build2 { tracer trace (x, "msvc_search_shared"); + assert (pk.scope != nullptr); + libs* s (nullptr); auto search = [&s, &ld, &d, &pk, exist, &trace] ( @@ -461,7 +464,9 @@ namespace build2 if (libi* i = msvc_search_library ( ld, d, pk, otype::s, pf, sf, exist, trace)) { - ulock l (insert_library (s, *pk.tk.name, d, nullopt, exist, trace)); + ulock l ( + insert_library ( + pk.scope->ctx, s, *pk.tk.name, d, nullopt, exist, trace)); if (!exist) { diff --git a/build2/cc/pkgconfig.cxx b/build2/cc/pkgconfig.cxx index c23b746..13cc752 100644 --- a/build2/cc/pkgconfig.cxx +++ b/build2/cc/pkgconfig.cxx @@ -1027,7 +1027,7 @@ namespace build2 // Parse modules and add them to the prerequisites. // - auto parse_modules = [&trace, &next, this] + auto parse_modules = [&trace, &next, &s, this] (const pkgconf& pc, prerequisites& ps) { string mstr (pc.variable ("cxx_modules")); @@ -1057,7 +1057,7 @@ namespace build2 // For now there are only C++ modules. // auto tl ( - targets.insert_locked ( + s.ctx.targets.insert_locked ( *x_mod, mp.directory (), dir_path (), diff --git a/build2/cc/utility.cxx b/build2/cc/utility.cxx index 3271f7c..ff807c9 100644 --- a/build2/cc/utility.cxx +++ b/build2/cc/utility.cxx @@ -72,7 +72,7 @@ namespace build2 // return phase == run_phase::match && !exist ? &search (x, tt, x.dir, x.out, x.name) - : search_existing (tt, x.dir, x.out, x.name); + : search_existing (x.ctx, tt, x.dir, x.out, x.name); } else { -- cgit v1.1