diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2019-08-19 23:41:49 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2019-08-22 12:52:58 +0300 |
commit | a37431f8109cb67937ad5356e8209a7151ad5a61 (patch) | |
tree | ff0f37fbf7d1bb9a36a9349a67676d9d145bdee4 | |
parent | 1508c382589fe62b7d8829c9cd23ba5ab4bdf913 (diff) |
Make testscripts to ignore user's default options files
-rw-r--r-- | bdep/bdep.cxx | 20 | ||||
-rw-r--r-- | bdep/common.cli | 6 | ||||
-rw-r--r-- | bdep/help.cxx | 2 | ||||
-rw-r--r-- | bdep/new.cxx | 18 | ||||
-rw-r--r-- | bdep/sync.cxx | 9 | ||||
-rw-r--r-- | bdep/utility.cxx | 13 | ||||
-rw-r--r-- | bdep/utility.hxx | 12 | ||||
-rw-r--r-- | tests/common.testscript | 24 |
8 files changed, 82 insertions, 22 deletions
diff --git a/bdep/bdep.cxx b/bdep/bdep.cxx index c8fe18b..1faac39 100644 --- a/bdep/bdep.cxx +++ b/bdep/bdep.cxx @@ -219,15 +219,25 @@ init (const common_options& co, if (!o.no_default_options ()) // Command line option. try { + bdep::optional<dir_path> extra; + if (o.default_options_specified ()) + extra = o.default_options (); + o = merge_options ( load_default_options<O, cli::argv_file_scanner, cli::unknown_mode> ( nullopt /* sys_dir */, - path::home_directory (), + 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); } @@ -236,10 +246,6 @@ init (const common_options& co, fail << "unable to load default options files: " << e.first << ": " << e.second; } - catch (const system_error& e) - { - fail << "unable to obtain home directory: " << e; - } // Global initializations. // diff --git a/bdep/common.cli b/bdep/common.cli index c08d873..4dd18b0 100644 --- a/bdep/common.cli +++ b/bdep/common.cli @@ -213,6 +213,12 @@ namespace bdep to specify more than one options file." } + dir_path --default-options + { + "<dir>", + "The directory to load additional default options files from." + } + bool --no-default-options { "Don't load default options files." diff --git a/bdep/help.cxx b/bdep/help.cxx index e37c65d..fe64c2a 100644 --- a/bdep/help.cxx +++ b/bdep/help.cxx @@ -71,7 +71,7 @@ namespace bdep return default_options_files { {path ("bdep.options"), path ("bdep-help.options")}, - nullopt /* start_dir */}; + nullopt /* start */}; } help_options diff --git a/bdep/new.cxx b/bdep/new.cxx index 160a9ce..3a79486 100644 --- a/bdep/new.cxx +++ b/bdep/new.cxx @@ -2148,7 +2148,7 @@ namespace bdep // Note that we will not validate the command arguments and let cmd_new() // complain later in case of an error. // - optional<dir_path> start_dir; + optional<dir_path> start; auto output_parent_dir = [&o] () { @@ -2157,29 +2157,29 @@ namespace bdep if (o.package () || o.subdirectory ()) { - start_dir = + start = o.output_dir_specified () ? output_parent_dir () : o.directory_specified () ? normalize (o.directory (), "project") : current_directory (); // Get the actual project directory. // - project_package pp (find_project_package (*start_dir, + project_package pp (find_project_package (*start, true /* ignore_not_found */)); if (!pp.project.empty ()) - start_dir = move (pp.project); + start = move (pp.project); else if (!o.no_checks ()) - start_dir = nullopt; // Let cmd_new() fail. + start = nullopt; // Let cmd_new() fail. } else // New project. { - start_dir = o.output_dir_specified () - ? output_parent_dir () - : current_directory (); + start = o.output_dir_specified () + ? output_parent_dir () + : current_directory (); } - default_options_files r {{path ("bdep.options")}, move (start_dir)}; + default_options_files r {{path ("bdep.options")}, move (start)}; auto add = [&r] (const string& n) { diff --git a/bdep/sync.cxx b/bdep/sync.cxx index 26781eb..7599148 100644 --- a/bdep/sync.cxx +++ b/bdep/sync.cxx @@ -870,8 +870,8 @@ namespace bdep default_options_files r {{path ("bdep.options")}, nullopt}; // Add bdep-sync-implicit.options for an implicit sync and - // bdep-sync.options otherwise. Omit the search start dir in the former - // case. + // bdep-sync.options otherwise. In the former case try to find a common + // start directory using the configuration directories. // auto add = [&r] (const string& n) { @@ -881,12 +881,14 @@ namespace bdep if (o.implicit () || o.hook_specified ()) { add ("sync-implicit"); + + r.start = default_options_start (home_directory (), o.config ()); } else { add ("sync"); - r.start_dir = find_project (o); + r.start = find_project (o); } return r; @@ -913,6 +915,7 @@ namespace bdep forbid ("--directory|-d", o.directory_specified ()); forbid ("--implicit", o.implicit ()); forbid ("--hook", o.hook_specified ()); + forbid ("--config|-c", o.config_specified ()); }); } } diff --git a/bdep/utility.cxx b/bdep/utility.cxx index 148610b..5a547eb 100644 --- a/bdep/utility.cxx +++ b/bdep/utility.cxx @@ -95,6 +95,19 @@ namespace bdep } } + dir_path + home_directory () + { + try + { + return dir_path::home_directory (); + } + catch (const system_error& e) + { + fail << "unable to obtain home directory: " << e << endf; + } + } + dir_path& normalize (dir_path& d, const char* what) { diff --git a/bdep/utility.hxx b/bdep/utility.hxx index 7f02b3c..c4cdef5 100644 --- a/bdep/utility.hxx +++ b/bdep/utility.hxx @@ -14,10 +14,11 @@ #include <libbutl/ft/lang.hxx> -#include <libbutl/utility.mxx> // casecmp(), reverse_iterate(), etc +#include <libbutl/utility.mxx> // casecmp(), reverse_iterate(), etc #include <libbutl/prompt.mxx> #include <libbutl/fdstream.mxx> #include <libbutl/filesystem.mxx> +#include <libbutl/default-options.mxx> #include <libbutl/manifest-parser.mxx> // manifest_parser::filter_function #include <libbutl/manifest-serializer.mxx> // manifest_serializer::filter_function @@ -67,6 +68,12 @@ namespace bdep using butl::auto_rmfile; using butl::auto_rmdir; + // <libbutl/default-options.mxx> + // + using butl::load_default_options; + using butl::merge_default_options; + using butl::default_options_start; + // Empty string and path. // extern const string empty_string; @@ -119,6 +126,9 @@ namespace bdep dir_path current_directory (); + dir_path + home_directory (); + // Normalize a directory path. Also make the relative path absolute using // the current directory. // diff --git a/tests/common.testscript b/tests/common.testscript index 1914625..2340491 100644 --- a/tests/common.testscript +++ b/tests/common.testscript @@ -13,7 +13,29 @@ # produced or updated by a command being tested. # build = $recall($build.path) -test.options += --build $build + +# Disable loading the user's default options files (that may affect the test +# commands execution) for bdep, 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 ++echo '--no-default-options' >=$options_guard/bdep.options + +test.options += --default-options $options_guard \ +--build $build --build-option "--default-options=$options_guard" \ +--bpkg-option "--default-options=$options_guard" \ +--bpkg-option "--build-option=--default-options=$options_guard" + +build = $build --default-options $options_guard + ++cat <<"EOI" >=$options_guard/bdep-sync-implicit.options +--build-option "--default-options=$options_guard" +--bpkg-option "--default-options=$options_guard" +--bpkg-option "--build-option=--default-options=$options_guard" +EOI # Check that git version is the minimum supported one or above. The lowest # common denominator for bdep commands is 2.1.0. |