aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-10-07 17:24:11 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-10-07 17:24:11 +0300
commit7bfa864c65a2b6d2ad41f1edc8d18d57ffb3f968 (patch)
treecb36d6b4e63140bc7f7b691ee8388975e7441521
parentaaa67b496c2abf1816aeadc83beac5ea8e2f681f (diff)
Add support for BDEP_DEF_OPT environment variable
-rw-r--r--bdep/bdep.cli6
-rw-r--r--bdep/bdep.cxx24
2 files changed, 27 insertions, 3 deletions
diff --git a/bdep/bdep.cli b/bdep/bdep.cli
index 7c77958..45163e4 100644
--- a/bdep/bdep.cli
+++ b/bdep/bdep.cli
@@ -514,5 +514,11 @@ namespace bdep
"\h|EXIT STATUS|
Non-zero exit status is returned in case of an error.
+
+ \h|ENVIRONMENT|
+
+ The \cb{BDEP_DEF_OPT} environment variable is used to suppress loading of
+ default options files in nested \cb{bdep} invocations. Its values are
+ \cb{false} or \cb{0} to suppress and \cb{true} or \cb{1} to load.
"
}
diff --git a/bdep/bdep.cxx b/bdep/bdep.cxx
index 17d5f7d..14a36ba 100644
--- a/bdep/bdep.cxx
+++ b/bdep/bdep.cxx
@@ -152,6 +152,9 @@ init (const common_options& co,
bool keep_sep,
bool tmp)
{
+ using bdep::optional;
+ using bdep::getenv;
+
tracer trace ("init");
O o;
@@ -211,14 +214,23 @@ init (const common_options& co,
: o.V () ? 3 : o.v () ? 2 : o.quiet () ? 0 : 1;
};
- // Handle default options files.
+ // Load the default options files, unless --no-default-options is specified
+ // on the command line or the BDEP_DEF_OPT environment variable is set to a
+ // value other than 'true' or '1'.
+ //
+ optional<string> env_def (getenv ("BDEP_DEF_OPT"));
+
+ // False if --no-default-options is specified on the command line. Note that
+ // we cache the flag since it can be overridden by a default options file.
//
+ bool cmd_def (!o.no_default_options ());
+
// Note: don't need to use group_scaner (no arguments in options files).
//
- if (!o.no_default_options ()) // Command line option.
+ if (cmd_def && (!env_def || *env_def == "true" || *env_def == "1"))
try
{
- bdep::optional<dir_path> extra;
+ optional<dir_path> extra;
if (o.default_options_specified ())
extra = o.default_options ();
@@ -246,6 +258,12 @@ init (const common_options& co,
<< e.second;
}
+ // Propagate disabling of the default options files to the potential nested
+ // invocations.
+ //
+ if (!cmd_def && (!env_def || *env_def != "0"))
+ setenv ("BDEP_DEF_OPT", "0");
+
// Global initializations.
//