summaryrefslogtreecommitdiffstats
path: root/Source/cmCTest.cxx
diff options
context:
space:
mode:
authorAsit Dhal <dhal.asitk@gmail.com>2020-12-16 16:14:26 (GMT)
committerAsit Dhal <dhal.asitk@gmail.com>2020-12-17 04:01:03 (GMT)
commitdbcf86d24d9e0d762e97e3a4b492739f99816c13 (patch)
tree33514dd1556487d9518f2d122c25d951cd16cedf /Source/cmCTest.cxx
parent0f61fac6f028214d64ef6a407c6b98d4503ee2fe (diff)
downloadCMake-dbcf86d24d9e0d762e97e3a4b492739f99816c13.zip
CMake-dbcf86d24d9e0d762e97e3a4b492739f99816c13.tar.gz
CMake-dbcf86d24d9e0d762e97e3a4b492739f99816c13.tar.bz2
Ctest: Support build tree on command line
Fixes: #21268
Diffstat (limited to 'Source/cmCTest.cxx')
-rw-r--r--Source/cmCTest.cxx35
1 files changed, 33 insertions, 2 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 8479458..014ce4e 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -4,6 +4,7 @@
#include <algorithm>
#include <cctype>
+#include <cerrno>
#include <chrono>
#include <cstdio>
#include <cstdlib>
@@ -179,6 +180,7 @@ struct cmCTest::Private
// information for the --build-and-test options
std::string BinaryDir;
+ std::string TestDir;
std::string NotesFiles;
@@ -2059,6 +2061,13 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
i++;
this->SetNotesFiles(args[i]);
return true;
+ } else if (this->CheckArgument(arg, "--test-dir"_s)) {
+ if (i >= args.size() - 1) {
+ errormsg = "'--test-dir' requires an argument";
+ return false;
+ }
+ i++;
+ this->Impl->TestDir = std::string(args[i]);
}
cm::string_view noTestsPrefix = "--no-tests=";
@@ -2467,8 +2476,26 @@ int cmCTest::ExecuteTests()
handler->SetVerbose(this->Impl->Verbose);
handler->SetSubmitIndex(this->Impl->SubmitIndex);
}
- std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
- if (!this->Initialize(cwd.c_str(), nullptr)) {
+
+ const std::string currDir = cmSystemTools::GetCurrentWorkingDirectory();
+ std::string workDir = currDir;
+ if (!this->Impl->TestDir.empty()) {
+ workDir = cmSystemTools::CollapseFullPath(this->Impl->TestDir);
+ }
+
+ if (currDir != workDir) {
+ cmCTestLog(this, OUTPUT,
+ "Internal ctest changing into directory: " << workDir
+ << std::endl);
+ if (cmSystemTools::ChangeDirectory(workDir) != 0) {
+ auto msg = "Failed to change working directory to \"" + workDir +
+ "\" : " + std::strerror(errno) + "\n";
+ cmCTestLog(this, ERROR_MESSAGE, msg);
+ return 1;
+ }
+ }
+
+ if (!this->Initialize(workDir.c_str(), nullptr)) {
res = 12;
cmCTestLog(this, ERROR_MESSAGE,
"Problem initializing the dashboard." << std::endl);
@@ -2476,6 +2503,10 @@ int cmCTest::ExecuteTests()
res = this->ProcessSteps();
}
this->Finalize();
+
+ if (currDir != workDir) {
+ cmSystemTools::ChangeDirectory(currDir);
+ }
}
if (res != 0) {
cmCTestLog(this, DEBUG,