diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2021-10-29 13:50:41 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2021-10-29 14:54:02 (GMT) |
commit | 7d52d48a329d6a1c456b48f63c980cce799f3a9c (patch) | |
tree | 5f924910ba27f6b9445a9c6eac14a755305175af /Source | |
parent | 4572c40df58465b17ca4ed29e7e741725c00db7f (diff) | |
download | CMake-7d52d48a329d6a1c456b48f63c980cce799f3a9c.zip CMake-7d52d48a329d6a1c456b48f63c980cce799f3a9c.tar.gz CMake-7d52d48a329d6a1c456b48f63c980cce799f3a9c.tar.bz2 |
cmCTestRunTest: get the default value from the environment
This only works due to some assumptions about how the `ENVIRONMENT`
property is processed. Comments have been added to notify anyone
modifying the behavior about where to look.
Fixes: #22819
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CTest/cmCTestRunTest.cxx | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 2d1562a..9d2cef6 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -782,6 +782,9 @@ bool cmCTestRunTest::ForkProcess( std::ostringstream envMeasurement; if (environment && !environment->empty()) { + // Environment modification works on the assumption that the environment is + // actually modified here. If another strategy is used, there will need to + // be updates below in `apply_diff`. cmSystemTools::AppendEnv(*environment); for (auto const& var : *environment) { envMeasurement << var << std::endl; @@ -800,7 +803,20 @@ bool cmCTestRunTest::ForkProcess( auto apply_diff = [&env_application](const std::string& name, std::function<void(std::string&)> const& apply) { - std::string output = env_application[name].value_or(std::string{}); + cm::optional<std::string> old_value = env_application[name]; + std::string output; + if (old_value) { + output = *old_value; + } else { + // This only works because the environment is actually modified above + // (`AppendEnv`). If CTest ever just creates an environment block + // directly, that block will need to be queried for the subprocess' + // value instead. + const char* curval = cmSystemTools::GetEnv(name); + if (curval) { + output = curval; + } + } apply(output); env_application[name] = output; }; |