From 5035f4ef68922ac758b1e4734e67d73c9228010b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 22 Aug 2019 14:38:57 +0200 Subject: Introduce notion of build context All non-const global state is now in class context and we can now have multiple independent builds going on at the same time. --- libbuild2/install/functions.cxx | 4 ++-- libbuild2/install/init.cxx | 17 ++++++++++------- libbuild2/install/operation.cxx | 2 ++ libbuild2/install/rule.cxx | 24 +++++++++++++++--------- libbuild2/install/utility.hxx | 4 ++-- 5 files changed, 31 insertions(+), 20 deletions(-) (limited to 'libbuild2/install') diff --git a/libbuild2/install/functions.cxx b/libbuild2/install/functions.cxx index f067918..6052dd9 100644 --- a/libbuild2/install/functions.cxx +++ b/libbuild2/install/functions.cxx @@ -14,9 +14,9 @@ namespace build2 namespace install { void - functions () + functions (function_map& m) { - function_family f ("install"); + function_family f (m, "install"); // Resolve potentially relative install.* value to an absolute directory // based on (other) install.* values visible from the calling scope. diff --git a/libbuild2/install/init.cxx b/libbuild2/install/init.cxx index 060007b..d2321b5 100644 --- a/libbuild2/install/init.cxx +++ b/libbuild2/install/init.cxx @@ -62,7 +62,7 @@ namespace build2 vn += name; } vn += var; - const variable& vr (var_pool.rw (r).insert (move (vn), true)); + const variable& vr (r.ctx.var_pool.rw (r).insert (move (vn), true)); l = dv != nullptr ? config::required (r, vr, *dv, override).first @@ -79,7 +79,7 @@ namespace build2 vn = "install."; vn += name; vn += var; - const variable& vr (var_pool.rw (r).insert (move (vn))); + const variable& vr (r.ctx.var_pool.rw (r).insert (move (vn))); value& v (r.assign (vr)); @@ -122,11 +122,12 @@ namespace build2 // This one doesn't have config.* value (only set in a buildfile). // if (!global) - var_pool.rw (r).insert (string ("install.") + n + ".subdirs"); + r.ctx.var_pool.rw (r).insert ( + string ("install.") + n + ".subdirs"); } void - functions (); // functions.cxx + functions (function_map&); // functions.cxx bool boot (scope& rs, const location&, unique_ptr&) @@ -134,11 +135,13 @@ namespace build2 tracer trace ("install::boot"); l5 ([&]{trace << "for " << rs;}); + context& ctx (rs.ctx); + // Register install function family if this is the first instance of the // install modules. // - if (!function_family::defined ("install")) - functions (); + if (!function_family::defined (ctx.functions, "install")) + functions (ctx.functions); // Register our operations. // @@ -192,7 +195,7 @@ namespace build2 // Enter module variables. // - auto& vp (var_pool.rw (rs)); + auto& vp (rs.ctx.var_pool.rw (rs)); // Note that the set_dir() calls below enter some more. // diff --git a/libbuild2/install/operation.cxx b/libbuild2/install/operation.cxx index 1135ad6..a2ad7d0 100644 --- a/libbuild2/install/operation.cxx +++ b/libbuild2/install/operation.cxx @@ -4,6 +4,8 @@ #include +#include + using namespace std; using namespace butl; diff --git a/libbuild2/install/rule.cxx b/libbuild2/install/rule.cxx index 48a404b..7cee10e 100644 --- a/libbuild2/install/rule.cxx +++ b/libbuild2/install/rule.cxx @@ -698,6 +698,8 @@ namespace build2 const dir_path& d, bool verbose = true) { + context& ctx (rs.ctx); + // Here is the problem: if this is a dry-run, then we will keep showing // the same directory creation commands over and over again (because we // don't actually create them). There are two alternative ways to solve @@ -708,7 +710,7 @@ namespace build2 // with uninstall since the directories won't be empty (because we don't // actually uninstall any files). // - if (dry_run) + if (ctx.dry_run) return; dir_path chd (chroot_path (rs, d)); @@ -741,7 +743,7 @@ namespace build2 cstrings args; string reld ( - cast ((*global_scope)["build.host.class"]) == "windows" + cast (ctx.global_scope["build.host.class"]) == "windows" ? msys_path (chd) : relative (chd).string ()); @@ -780,12 +782,14 @@ namespace build2 const path& f, bool verbose) { + context& ctx (rs.ctx); + path relf (relative (f)); dir_path chd (chroot_path (rs, base.dir)); string reld ( - cast ((*global_scope)["build.host.class"]) == "windows" + cast (ctx.global_scope["build.host.class"]) == "windows" ? msys_path (chd) : relative (chd).string ()); @@ -818,7 +822,7 @@ namespace build2 else if (verb && verbose) text << "install " << t; - if (!dry_run) + if (!ctx.dry_run) run (pp, args); } @@ -829,6 +833,8 @@ namespace build2 const path& link, uint16_t verbosity) { + context& ctx (rs.ctx); + path rell (relative (chroot_path (rs, base.dir))); rell /= link; @@ -859,7 +865,7 @@ namespace build2 text << "install " << rell << " -> " << target; } - if (!dry_run) + if (!ctx.dry_run) run (pp, args); #else // The -f part. @@ -877,7 +883,7 @@ namespace build2 text << "install " << rell << " -> " << target; } - if (!dry_run) + if (!ctx.dry_run) try { // We have to go the roundabout way by adding directory to the target @@ -1014,7 +1020,7 @@ namespace build2 { // See install_d() for the rationale. // - if (dry_run) + if (rs.ctx.dry_run) return false; dir_path chd (chroot_path (rs, d)); @@ -1150,7 +1156,7 @@ namespace build2 if (verb >= verbosity && verb >= 2) text << "rm " << relf; - if (!dry_run) + if (!rs.ctx.dry_run) { try { @@ -1179,7 +1185,7 @@ namespace build2 if (verb >= verbosity && verb >= 2) print_process (args); - if (!dry_run) + if (!rs.ctx.dry_run) run (pp, args); } diff --git a/libbuild2/install/utility.hxx b/libbuild2/install/utility.hxx index 13fcceb..24c82d8 100644 --- a/libbuild2/install/utility.hxx +++ b/libbuild2/install/utility.hxx @@ -24,7 +24,7 @@ namespace build2 { auto r ( s.target_vars[tt]["*"].insert ( - var_pool.rw (s).insert ("install"))); + s.ctx.var_pool.rw (s).insert ("install"))); if (r.second) // Already set by the user? r.first.get () = path_cast (move (d)); @@ -42,7 +42,7 @@ namespace build2 { auto r ( s.target_vars[tt]["*"].insert ( - var_pool.rw (s).insert ("install.mode"))); + s.ctx.var_pool.rw (s).insert ("install.mode"))); if (r.second) // Already set by the user? r.first.get () = move (m); -- cgit v1.1