diff options
author | Brad King <brad.king@kitware.com> | 2017-11-27 13:51:10 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2017-11-27 13:51:35 (GMT) |
commit | 0c1912e3e58bebe9eb7c6dcac7a478dc607dba66 (patch) | |
tree | 752993eb08fdc42731d2d635c596ad4572cef5d0 /Source | |
parent | b1d3fb7fba735d829c2cd655830161871827d82e (diff) | |
parent | fe2c2b0ffb567ca7d51036c69845091f70736a50 (diff) | |
download | CMake-0c1912e3e58bebe9eb7c6dcac7a478dc607dba66.zip CMake-0c1912e3e58bebe9eb7c6dcac7a478dc607dba66.tar.gz CMake-0c1912e3e58bebe9eb7c6dcac7a478dc607dba66.tar.bz2 |
Merge topic 'serverFixTestDiscovery'
fe2c2b0f server: ctestInfo fix to return all tests
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1479
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmMakefile.cxx | 17 | ||||
-rw-r--r-- | Source/cmMakefile.h | 10 | ||||
-rw-r--r-- | Source/cmServerDictionary.h | 1 | ||||
-rw-r--r-- | Source/cmServerProtocol.cxx | 91 | ||||
-rw-r--r-- | Source/cmTestGenerator.cxx | 10 | ||||
-rw-r--r-- | Source/cmTestGenerator.h | 5 |
6 files changed, 49 insertions, 85 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 0855e79..9678a66 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3335,13 +3335,6 @@ cmGlobalGenerator* cmMakefile::GetGlobalGenerator() const return this->GlobalGenerator; } -void cmMakefile::GetTestNames(std::vector<std::string>& testNames) -{ - for (const auto& iter : Tests) { - testNames.push_back(iter.first); - } -} - #ifdef CMAKE_BUILD_WITH_CMAKE cmVariableWatch* cmMakefile::GetVariableWatch() const { @@ -3677,6 +3670,16 @@ cmTest* cmMakefile::GetTest(const std::string& testName) const return nullptr; } +void cmMakefile::GetTests(const std::string& config, + std::vector<cmTest*>& tests) +{ + for (auto generator : this->GetTestGenerators()) { + if (generator->TestsForConfig(config)) { + tests.push_back(generator->GetTest()); + } + } +} + void cmMakefile::AddCMakeDependFilesFromUser() { std::vector<std::string> deps; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 7c27aef..5e87393 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -617,11 +617,6 @@ public: cmGlobalGenerator* GetGlobalGenerator() const; /** - * Get all the test names this makefile knows about - */ - void GetTestNames(std::vector<std::string>& testNames); - - /** * Get all the source files this makefile knows about */ const std::vector<cmSourceFile*>& GetSourceFiles() const @@ -644,6 +639,11 @@ public: cmTest* GetTest(const std::string& testName) const; /** + * Get all tests that run under the given configuration. + */ + void GetTests(const std::string& config, std::vector<cmTest*>& tests); + + /** * Return a location of a file in cmake or custom modules directory */ std::string GetModulesFile(const char* name) const; diff --git a/Source/cmServerDictionary.h b/Source/cmServerDictionary.h index 8cd5e14..9008783 100644 --- a/Source/cmServerDictionary.h +++ b/Source/cmServerDictionary.h @@ -91,7 +91,6 @@ static const std::string kWATCHED_DIRECTORIES_KEY = "watchedDirectories"; static const std::string kWATCHED_FILES_KEY = "watchedFiles"; static const std::string kHAS_INSTALL_RULE = "hasInstallRule"; static const std::string kINSTALL_PATHS = "installPaths"; -static const std::string kHAS_ENABLED_TESTS = "hasEnabledTests"; static const std::string kCTEST_NAME = "ctestName"; static const std::string kCTEST_COMMAND = "ctestCommand"; static const std::string kCTEST_INFO = "ctestInfo"; diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index aae0a9d..7a7080b 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -771,10 +771,10 @@ static void DumpBacktraceRange(Json::Value& result, const std::string& type, } } -static Json::Value DumpCTestInfo(const std::string& name, cmTest* testInfo) +static Json::Value DumpCTestInfo(cmTest* testInfo) { Json::Value result = Json::objectValue; - result[kCTEST_NAME] = name; + result[kCTEST_NAME] = testInfo->GetName(); // Concat command entries together. After the first should be the arguments // for the command @@ -801,76 +801,17 @@ static Json::Value DumpCTestInfo(const std::string& name, cmTest* testInfo) return result; } -static Json::Value DumpCTestTarget(cmGeneratorTarget* target, - const std::string& config) +static void DumpMakefileTests(cmMakefile* mf, const std::string& config, + Json::Value* result) { - cmLocalGenerator* lg = target->GetLocalGenerator(); - const cmState* state = lg->GetState(); - - const cmStateEnums::TargetType type = target->GetType(); - const std::string typeName = state->GetTargetTypeName(type); - - Json::Value ttl = Json::arrayValue; - ttl.append("EXECUTABLE"); - ttl.append("STATIC_LIBRARY"); - ttl.append("SHARED_LIBRARY"); - ttl.append("MODULE_LIBRARY"); - ttl.append("OBJECT_LIBRARY"); - ttl.append("UTILITY"); - ttl.append("INTERFACE_LIBRARY"); - - if (!hasString(ttl, typeName) || target->IsImported()) { - return Json::Value(); - } - - Json::Value result = Json::objectValue; - result[kNAME_KEY] = target->GetName(); - result[kTYPE_KEY] = typeName; - - if (type == cmStateEnums::INTERFACE_LIBRARY) { - return result; - } - result[kFULL_NAME_KEY] = target->GetFullName(config); - - if (target->Makefile->IsOn("CMAKE_TESTING_ENABLED")) { - result[kHAS_ENABLED_TESTS] = true; - std::vector<std::string> CTestNames; - - Json::Value testInfo = Json::arrayValue; - std::vector<std::string> testNames; - target->Makefile->GetTestNames(testNames); - for (auto& name : testNames) { - auto test = target->Makefile->GetTest(name); - if (test != nullptr) { - testInfo.append(DumpCTestInfo(name, test)); - } - } - result[kCTEST_INFO] = testInfo; - } - - return result; -} - -static Json::Value DumpCTestTargetsList( - const std::vector<cmLocalGenerator*>& generators, const std::string& config) -{ - Json::Value result = Json::arrayValue; - - std::vector<cmGeneratorTarget*> targetList; - for (const auto& lgIt : generators) { - auto list = lgIt->GetGeneratorTargets(); - targetList.insert(targetList.end(), list.begin(), list.end()); - } - std::sort(targetList.begin(), targetList.end()); - - for (cmGeneratorTarget* target : targetList) { - Json::Value tmp = DumpCTestTarget(target, config); + std::vector<cmTest*> tests; + mf->GetTests(config, tests); + for (auto test : tests) { + Json::Value tmp = DumpCTestInfo(test); if (!tmp.isNull()) { - result.append(tmp); + result->append(tmp); } } - - return result; } static Json::Value DumpCTestProjectList(const cmake* cm, @@ -884,11 +825,17 @@ static Json::Value DumpCTestProjectList(const cmake* cm, Json::Value pObj = Json::objectValue; pObj[kNAME_KEY] = projectIt.first; - // All Projects must have at least one local generator - assert(!projectIt.second.empty()); + Json::Value tests = Json::arrayValue; - // Project structure information: - pObj[kTARGETS_KEY] = DumpCTestTargetsList(projectIt.second, config); + // Gather tests for every generator + for (const auto& lg : projectIt.second) { + // Make sure they're generated. + lg->GenerateTestFiles(); + cmMakefile* mf = lg->GetMakefile(); + DumpMakefileTests(mf, config, &tests); + } + + pObj[kCTEST_INFO] = tests; result.append(pObj); } diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index 78ca6bc..b548359 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -34,6 +34,16 @@ void cmTestGenerator::Compute(cmLocalGenerator* lg) this->LG = lg; } +bool cmTestGenerator::TestsForConfig(const std::string& config) +{ + return this->GeneratesForConfig(config); +} + +cmTest* cmTestGenerator::GetTest() const +{ + return this->Test; +} + void cmTestGenerator::GenerateScriptConfigs(std::ostream& os, Indent indent) { // Create the tests. diff --git a/Source/cmTestGenerator.h b/Source/cmTestGenerator.h index 1ca61c2..73d05a3 100644 --- a/Source/cmTestGenerator.h +++ b/Source/cmTestGenerator.h @@ -30,6 +30,11 @@ public: void Compute(cmLocalGenerator* lg); + /** Test if this generator installs the test for a given configuration. */ + bool TestsForConfig(const std::string& config); + + cmTest* GetTest() const; + protected: void GenerateScriptConfigs(std::ostream& os, Indent indent) override; void GenerateScriptActions(std::ostream& os, Indent indent) override; |