From 818a3883a45e8242eee919806828a3ed801d52e1 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 1 Nov 2018 15:06:41 +0300 Subject: Change worker current directory to package directory for test operation Note that this is not uncommon for ported to build2 third-party packages to expect that tests should run in the project root directory. --- bbot/worker/worker.cxx | 43 ++++++++++++++++++++++++++++++++++++------- tests/integration/testscript | 2 +- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/bbot/worker/worker.cxx b/bbot/worker/worker.cxx index b32dbed..1b567b3 100644 --- a/bbot/worker/worker.cxx +++ b/bbot/worker/worker.cxx @@ -52,16 +52,29 @@ namespace bbot } static dir_path -change_wd (const dir_path& d, bool create = false) +change_wd (tracer& t, string* log, const dir_path& d, bool create = false) try { if (create) + { + if (verb >= 3) + t << "mkdir -p " << d; + + if (log != nullptr) + *log += "mkdir -p " + d.representation () + '\n'; + try_mkdir_p (d); + } dir_path r (dir_path::current_directory ()); - dir_path::current_directory (d); + if (verb >= 3) + t << "cd " << d; + + if (log != nullptr) + *log += "cd " + d.representation () + '\n'; + dir_path::current_directory (d); return r; } catch (const system_error& e) @@ -472,7 +485,7 @@ build (size_t argc, const char* argv[]) if (!r.status) break; - rwd = change_wd (build_dir); + rwd = change_wd (trace, &r.log, build_dir); // bpkg add // @@ -564,6 +577,14 @@ build (size_t argc, const char* argv[]) { operation_result& r (add_result ("test")); + // Lets change the working directory to the package directory to help + // ported to build2 third-party packages a bit. Note that this is not + // uncommon for them to expect that tests should run in the project root + // directory. + // + dir_path d (tm.name.string () + '-' + tm.version.string ()); + dir_path rwd (change_wd (trace, &r.log, d)); + // bpkg test // // bpkg.test.test @@ -571,6 +592,7 @@ build (size_t argc, const char* argv[]) r.status |= run_bpkg ( trace, r.log, wre, "test", + "-d", "..", step_args (config_args, step_id::bpkg_test_test), step_args (env_args, step_id::bpkg_test_test), tm.name.string ()); @@ -579,6 +601,8 @@ build (size_t argc, const char* argv[]) break; rm.status |= r.status; + + change_wd (trace, &r.log, rwd); } // Install the package, optionally test the installation and uninstall @@ -637,7 +661,7 @@ build (size_t argc, const char* argv[]) { operation_result& r (add_result ("test-installed")); - change_wd (rwd); + change_wd (trace, &r.log, rwd); string mods; // build2 create meta-operation parameters. @@ -722,7 +746,7 @@ build (size_t argc, const char* argv[]) rm.status |= r.status; - change_wd (build_dir); + change_wd (trace, &r.log, build_dir); } // Uninstall. @@ -756,7 +780,7 @@ build (size_t argc, const char* argv[]) assert (rm.status == result_status::abort); if (!rwd.empty ()) - change_wd (rwd); + change_wd (trace, nullptr /* log */, rwd); // Upload the result. // @@ -954,6 +978,8 @@ int bbot:: main (int argc, char* argv[]) try { + tracer trace ("main"); + // This is a little hack to make our baseutils for Windows work when called // with absolute path. In a nutshell, MSYS2's exec*p() doesn't search in the // parent's executable directory, only in PATH. And since we are running @@ -1051,7 +1077,10 @@ try // Sort out the build directory. // if (ops.build_specified ()) - change_wd (ops.build (), true); // Create if does not exist. + change_wd (trace, + nullptr /* log */, + ops.build (), + true /* create */); // Sort out the environment directory. // diff --git a/tests/integration/testscript b/tests/integration/testscript index 43f77a2..7d7d7d9 100644 --- a/tests/integration/testscript +++ b/tests/integration/testscript @@ -52,7 +52,7 @@ pkg = libhello ver = 1.0.0 #rep_url = https://build2.org/pkg/1/hello/stable #rfp = FF:DF:7D:38:67:4E:C3:82:65:7E:EE:1F:D4:80:EC:56:C4:33:5B:65:3F:9B:29:9A:30:56:B9:77:B9:F2:01:94 -rep_url = https://hello.stage.build2.org/1/stable/ +rep_url = https://stage.build2.org/1 rep_type = pkg rfp = yes -- cgit v1.1