From 5384724d937196e1e3f5c15fe443c0bff07896e6 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 19 Aug 2019 23:39:38 +0300 Subject: Make testscripts to ignore user's default options files --- bpkg/bpkg.cxx | 16 +++++++++++++--- bpkg/cfg-create.cxx | 6 +++--- bpkg/common.cli | 6 ++++++ bpkg/rep-create.cxx | 6 +++--- bpkg/rep-info.cxx | 6 +++--- bpkg/utility.hxx | 9 +++++++-- tests/common.testscript | 13 ++++++++++++- 7 files changed, 47 insertions(+), 15 deletions(-) diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx index 0da8c58..170a7fe 100644 --- a/bpkg/bpkg.cxx +++ b/bpkg/bpkg.cxx @@ -95,7 +95,7 @@ namespace bpkg return default_options_files { {path ("bpkg.options"), path (string ("bpkg-") + cmd + ".options")}, - nullopt /* start_dir */}; + nullopt /* start */}; } // Merge the default options and the command line options. Fail if options @@ -234,15 +234,25 @@ init (const common_options& co, if (!o.no_default_options ()) // Command line option. try { + bpkg::optional extra; + if (o.default_options_specified ()) + extra = o.default_options (); + o = merge_options ( load_default_options ( nullopt /* sys_dir */, path::home_directory (), + extra, options_files (cmd, o, args), - [&trace, &verbosity] (const path& f, bool remote) + [&trace, &verbosity] (const path& f, bool r, bool o) { if (verbosity () >= 3) - trace << "loading " << (remote ? "remote " : "local ") << f; + { + if (o) + trace << "treating " << f << " as " << (r ? "remote" : "local"); + else + trace << "loading " << (r ? "remote " : "local ") << f; + } }), o); } diff --git a/bpkg/cfg-create.cxx b/bpkg/cfg-create.cxx index 1bc1a57..affc0b0 100644 --- a/bpkg/cfg-create.cxx +++ b/bpkg/cfg-create.cxx @@ -180,18 +180,18 @@ namespace bpkg // Use the configuration parent directory as a start directory. // - optional start_dir; + optional start; // Let cfg_create() complain later for the root directory used as a // configuration directory. // dir_path d (normalize (o.directory (), "configuration")); if (!d.root ()) - start_dir = d.directory (); + start = d.directory (); return default_options_files { {path ("bpkg.options"), path ("bpkg-cfg-create.options")}, - move (start_dir)}; + move (start)}; } cfg_create_options diff --git a/bpkg/common.cli b/bpkg/common.cli index 9b5df37..8af8726 100644 --- a/bpkg/common.cli +++ b/bpkg/common.cli @@ -367,6 +367,12 @@ namespace bpkg to specify more than one options file." } + dir_path --default-options + { + "", + "The directory to load additional default options files from." + } + bool --no-default-options { "Don't load default options files." diff --git a/bpkg/rep-create.cxx b/bpkg/rep-create.cxx index f0df1c0..98bf7f8 100644 --- a/bpkg/rep-create.cxx +++ b/bpkg/rep-create.cxx @@ -265,7 +265,7 @@ namespace bpkg // Use the repository directory as a start directory. // - optional start_dir; + optional start; // Let rep_create() complain later for invalid repository directory. // @@ -273,13 +273,13 @@ namespace bpkg { dir_path d (!args.empty () ? args[0] : "."); if (!d.empty ()) - start_dir = move (normalize (d, "repository")); + start = move (normalize (d, "repository")); } catch (const invalid_path&) {} return default_options_files { {path ("bpkg.options"), path ("bpkg-rep-create.options")}, - move (start_dir)}; + move (start)}; } rep_create_options diff --git a/bpkg/rep-info.cxx b/bpkg/rep-info.cxx index eeb93fe..086a142 100644 --- a/bpkg/rep-info.cxx +++ b/bpkg/rep-info.cxx @@ -384,7 +384,7 @@ namespace bpkg // If bpkg-rep-info operates in the configuration directory, then use it // as a search start directory. // - optional start_dir; + optional start; // Let rep_info() complain later for invalid configuration directory. // @@ -398,13 +398,13 @@ namespace bpkg d = current_dir; if (!d.empty ()) - start_dir = move (normalize (d, "configuration")); + start = move (normalize (d, "configuration")); } catch (const invalid_path&) {} return default_options_files { {path ("bpkg.options"), path ("bpkg-rep-info.options")}, - move (start_dir)}; + move (start)}; } rep_info_options diff --git a/bpkg/utility.hxx b/bpkg/utility.hxx index 1e82f44..2332587 100644 --- a/bpkg/utility.hxx +++ b/bpkg/utility.hxx @@ -14,9 +14,9 @@ #include -#include // casecmp(), reverse_iterate(), etc - +#include // casecmp(), reverse_iterate(), etc #include +#include #include #include @@ -53,6 +53,11 @@ namespace bpkg using butl::auto_rmfile; using butl::auto_rmdir; + // + // + using butl::load_default_options; + using butl::merge_default_options; + // Empty string and path. // extern const string empty_string; diff --git a/tests/common.testscript b/tests/common.testscript index 6a7bad2..802b2e5 100644 --- a/tests/common.testscript +++ b/tests/common.testscript @@ -9,7 +9,18 @@ # to one that may or may not be found via PATH). # build = $recall($build.path) -test.options += --build $build + +# Disable loading the user's default options files (that may affect the test +# commands execution) for bpkg and build2. +# +options_guard = $~/.build2 ++mkdir $options_guard + ++echo '--no-default-options' >=$options_guard/b.options ++echo '--no-default-options' >=$options_guard/bpkg.options + +test.options += --default-options $options_guard \ +--build $build --build-option "--default-options=$options_guard" # Helper commands that can be used by tests to prepare the testing environment # or validate an outcome of the command being tested. They are likely to get -- cgit v1.1