From 95aa319c1548fc81dfd018adc5ae8ec8db2e2f9c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 28 Aug 2023 15:57:14 +0300 Subject: Add support for bbot.sys-install:config.install.root variable --- bbot/worker/worker.cxx | 94 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 23 deletions(-) (limited to 'bbot') diff --git a/bbot/worker/worker.cxx b/bbot/worker/worker.cxx index 985d77e..d7222b4 100644 --- a/bbot/worker/worker.cxx +++ b/bbot/worker/worker.cxx @@ -505,6 +505,26 @@ log_step_id (tracer& t, string& log, step_id id) log += '\n'; } +// Add the specified string to the log as a comment. Unless the string is +// empty (e.g., a blank line to separate comments), also trace it. +// +static void +log_comment (tracer& t, string& log, const string& s) +{ + if (!s.empty ()) + l3 ([&]{t << s;}); + + log += comment_begin; + + if (!s.empty ()) + { + log += ' '; + log += s; + } + + log += '\n'; +} + // Run the worker script command. Name is used for logging and diagnostics // only. Match lines read from the command's stderr against the regular // expressions and return the warning result status (instead of success) in @@ -2104,14 +2124,24 @@ build (size_t argc, const char* argv[]) // first entry in the PATH environment variable, except for build system // modules which supposedly don't install any executables. // + // Note that normally the config.install.root is expected to be prefixed + // with the bpkg.target.create or, as a fallback, b.create or bpkg.create + // step ids. However, for testing of the relocatable installations it can + // be desirable to extract the archive distribution package content at the + // bbot.sys-install.tar.extract step into a different installation + // directory. If that's the case, then this directory needs to also be + // specified as bbot.sys-install:config.install.root. If specified, this + // directory will be preferred as a base for forming the bin/ directory + // path. + // optional install_bin; - auto config_install_root = [&step_args, &tgt_args] () -> optional + auto config_install_root = [&step_args, &tgt_args] + (step_id s, + optional f1 = nullopt, + optional f2 = nullopt) + -> optional { - step_id s (step_id::bpkg_target_create); - step_id f1 (step_id::b_create); - step_id f2 (step_id::bpkg_create); - size_t n (19); auto space = [] (char c) {return c == ' ' || c == '\t';}; @@ -2140,7 +2170,9 @@ build (size_t argc, const char* argv[]) { if (!module_pkg) { - install_root = config_install_root (); + install_root = config_install_root (step_id::bpkg_target_create, + step_id::b_create, + step_id::bpkg_create); if (install_root) install_bin = *install_root / dir_path ("bin"); @@ -3261,24 +3293,17 @@ build (size_t argc, const char* argv[]) s += " - "; s += name; - l3 ([&]{trace << s;}); - - r.log += comment_begin; - r.log += ' '; - r.log += s; - r.log += '\n'; + log_comment (trace, r.log, s); }; - r.log += comment_begin; - r.log += '\n'; + log_comment (trace, r.log, ""); log (target_uuid, "target"); log (host_uuid, "host"); log (module_uuid, "module"); log (install_uuid, "install"); - r.log += comment_begin; - r.log += '\n'; + log_comment (trace, r.log, ""); } }); @@ -4346,6 +4371,30 @@ build (size_t argc, const char* argv[]) // else if (*bindist == step_id::bpkg_bindist_archive) { + // If the bbot.sys-install:config.install.root variable is + // specified, then make sure the directory it refers to exists by + // the time we run `tar -xf`, so that this command doesn't fail + // trying to extract into a non-existent directory. Note that we do + // that regardless whether the package is a build system module or + // not. + // + optional ir ( + config_install_root (step_id::bbot_sys_install)); + + if (ir) + mk_p (trace, &r.log, *ir); + + if (!module_pkg) + { + if (!ir) + ir = config_install_root (step_id::bpkg_target_create, + step_id::b_create, + step_id::bpkg_create); + + if (ir) + install_bin = *ir / dir_path ("bin"); + } + for (const char* f: pfs) { // [sudo] tar -xf @@ -4404,12 +4453,6 @@ build (size_t argc, const char* argv[]) fail_unreached_breakpoint (r); break; } - - if (!module_pkg) - { - if (optional ir = config_install_root ()) - install_bin = *ir / dir_path ("bin"); - } } // // Fail if the breakpoint refers to a @@ -4509,7 +4552,12 @@ build (size_t argc, const char* argv[]) // beginning of the PATH environment variable value, so the // installed executables are found first. // - string paths ("PATH=" + install_bin->string ()); + const string& ib (install_bin->string ()); + + log_comment (trace, r.log, + "add " + ib + " to PATH environment variable"); + + string paths ("PATH=" + ib); if (optional s = getenv ("PATH")) { -- cgit v1.1