From 07388f83b69739116c8364e9443f10158fcdc912 Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Sun, 29 Nov 2015 12:39:03 +0000 Subject: [PATCH] Refactor the -W options parser to be generic. Refactor the -Wdev and -Wno-dev options parser to use a generic -W parser that follows the GCC pattern, excluding support for -Werror=TYPE and -Wno-error=TYPE formats for now. --- Source/cmake.cxx | 104 +++++++++++++----- Source/cmake.h | 14 +-- Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 13 ++- .../CommandLine/W_bad-arg1-result.txt | 1 + .../CommandLine/W_bad-arg1-stderr.txt | 2 + .../CommandLine/W_bad-arg2-result.txt | 1 + .../CommandLine/W_bad-arg2-stderr.txt | 2 + 7 files changed, 101 insertions(+), 36 deletions(-) create mode 100644 Tests/RunCMake/CommandLine/W_bad-arg1-result.txt create mode 100644 Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/W_bad-arg2-result.txt create mode 100644 Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 521313001..e6433bd6b 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -127,8 +127,6 @@ cmake::cmake() this->WarnUnused = false; this->WarnUnusedCli = true; this->CheckSystemVars = false; - this->SuppressDevWarnings = false; - this->DoSuppressDevWarnings = false; this->DebugOutput = false; this->DebugTryCompile = false; this->ClearBuildSystem = false; @@ -274,15 +272,51 @@ bool cmake::SetCacheArgs(const std::vector& args) return false; } } - else if(arg.find("-Wno-dev",0) == 0) + else if(cmHasLiteralPrefix(arg, "-W")) { - this->SuppressDevWarnings = true; - this->DoSuppressDevWarnings = true; - } - else if(arg.find("-Wdev",0) == 0) - { - this->SuppressDevWarnings = false; - this->DoSuppressDevWarnings = true; + std::string entry = arg.substr(2); + if (entry.empty()) + { + ++i; + if (i < args.size()) + { + entry = args[i]; + } + else + { + cmSystemTools::Error("-W must be followed with [no-]."); + return false; + } + } + + std::string name; + bool foundNo = false; + unsigned int nameStartPosition = 0; + + if (entry.find("no-", nameStartPosition) == 0) + { + foundNo = true; + nameStartPosition += 3; + } + + name = entry.substr(nameStartPosition); + if (name.empty()) + { + cmSystemTools::Error("No warning name provided."); + return false; + } + + if (!foundNo) + { + // -W + this->DiagLevels[name] = std::max(this->DiagLevels[name], + DIAG_WARN); + } + else + { + // -Wno + this->DiagLevels[name] = DIAG_IGNORE; + } } else if(arg.find("-U",0) == 0) { @@ -618,11 +652,7 @@ void cmake::SetArgs(const std::vector& args, // skip for now i++; } - else if(arg.find("-Wno-dev",0) == 0) - { - // skip for now - } - else if(arg.find("-Wdev",0) == 0) + else if(arg.find("-W",0) == 0) { // skip for now } @@ -1231,25 +1261,28 @@ int cmake::HandleDeleteCacheVariables(const std::string& var) int cmake::Configure() { - if(this->DoSuppressDevWarnings) + DiagLevel diagLevel; + + if (this->DiagLevels.count("dev") == 1) { - if(this->SuppressDevWarnings) + + diagLevel = this->DiagLevels["dev"]; + if (diagLevel == DIAG_IGNORE) { - this-> - AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE", - "Suppress Warnings that are meant for" - " the author of the CMakeLists.txt files.", - cmState::INTERNAL); + this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE", + "Suppress Warnings that are meant for" + " the author of the CMakeLists.txt files.", + cmState::INTERNAL); } - else + else if (diagLevel == DIAG_WARN) { - this-> - AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE", - "Suppress Warnings that are meant for" - " the author of the CMakeLists.txt files.", - cmState::INTERNAL); + this->AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE", + "Suppress Warnings that are meant for" + " the author of the CMakeLists.txt files.", + cmState::INTERNAL); } } + int ret = this->ActualConfigure(); const char* delCacheVars = this->State ->GetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_"); @@ -2805,6 +2838,21 @@ void cmake::RunCheckForUnusedVariables() #endif } +void cmake::SetSuppressDevWarnings(bool b) +{ + // equivalent to -Wno-dev + if (b) + { + this->DiagLevels["dev"] = DIAG_IGNORE; + } + // equivalent to -Wdev + else + { + this->DiagLevels["dev"] = std::max(this->DiagLevels["dev"], + DIAG_WARN); + } +} + bool cmake::GetSuppressDevWarnings(cmMakefile const* mf) { /* diff --git a/Source/cmake.h b/Source/cmake.h index 45ac28ebd..1bd6d4d0f 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -68,6 +68,11 @@ class cmake DEPRECATION_WARNING }; + enum DiagLevel + { + DIAG_IGNORE, + DIAG_WARN + }; /** \brief Describes the working modes of cmake */ enum WorkingMode @@ -303,11 +308,7 @@ class cmake std::string const& GetCMakeEditCommand() const { return this->CMakeEditCommand; } - void SetSuppressDevWarnings(bool v) - { - this->SuppressDevWarnings = v; - this->DoSuppressDevWarnings = true; - } + void SetSuppressDevWarnings(bool v); /* * Get the state of the suppression of developer (author) warnings. * Returns false, by default, if developer warnings should be shown, true @@ -359,8 +360,7 @@ protected: cmGlobalGenerator *GlobalGenerator; cmCacheManager *CacheManager; - bool SuppressDevWarnings; - bool DoSuppressDevWarnings; + std::map DiagLevels; std::string GeneratorPlatform; std::string GeneratorToolset; diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 8eaaa0810..d4f399c56 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -129,13 +129,24 @@ set(RunCMake_TEST_OPTIONS -Wno-dev) run_cmake(Wno-dev) unset(RunCMake_TEST_OPTIONS) -set(RunCMake_TEST_OPTIONS -Wno-dev -Wdev) +set(RunCMake_TEST_OPTIONS -Wdev) run_cmake(Wdev) unset(RunCMake_TEST_OPTIONS) # Dev warnings should be on by default run_cmake(Wdev) +# Conflicting -W options should honor the last value +set(RunCMake_TEST_OPTIONS -Wno-dev -Wdev) +run_cmake(Wdev) +unset(RunCMake_TEST_OPTIONS) +set(RunCMake_TEST_OPTIONS -Wdev -Wno-dev) +run_cmake(Wno-dev) +unset(RunCMake_TEST_OPTIONS) + +run_cmake_command(W_bad-arg1 ${CMAKE_COMMAND} -W) +run_cmake_command(W_bad-arg2 ${CMAKE_COMMAND} -Wno-) + set(RunCMake_TEST_OPTIONS --debug-output) run_cmake(debug-output) unset(RunCMake_TEST_OPTIONS) diff --git a/Tests/RunCMake/CommandLine/W_bad-arg1-result.txt b/Tests/RunCMake/CommandLine/W_bad-arg1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CommandLine/W_bad-arg1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt b/Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt new file mode 100644 index 000000000..0c0f61347 --- /dev/null +++ b/Tests/RunCMake/CommandLine/W_bad-arg1-stderr.txt @@ -0,0 +1,2 @@ +CMake Error: -W must be followed with \[no-\]. +CMake Error: Problem processing arguments. Aborting. diff --git a/Tests/RunCMake/CommandLine/W_bad-arg2-result.txt b/Tests/RunCMake/CommandLine/W_bad-arg2-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CommandLine/W_bad-arg2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt b/Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt new file mode 100644 index 000000000..cc643df95 --- /dev/null +++ b/Tests/RunCMake/CommandLine/W_bad-arg2-stderr.txt @@ -0,0 +1,2 @@ +CMake Error: No warning name provided. +CMake Error: Problem processing arguments. Aborting.