diff options
author | Brad King <brad.king@kitware.com> | 2018-12-12 13:30:35 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-12-12 13:30:45 (GMT) |
commit | 71e74b4ae453473d597ce5a53e2e8e7641dc832a (patch) | |
tree | 0791d5c9155d97a8f5a2ff3b0f84ca956ecdd993 | |
parent | a23ac516b3ccdba9efb22f19edcb7cd676a510b4 (diff) | |
parent | fe9a16c80fe921d2db66c0699b4197f85a281e7e (diff) | |
download | CMake-71e74b4ae453473d597ce5a53e2e8e7641dc832a.zip CMake-71e74b4ae453473d597ce5a53e2e8e7641dc832a.tar.gz CMake-71e74b4ae453473d597ce5a53e2e8e7641dc832a.tar.bz2 |
Merge topic 'fix-configure-line-number'
fe9a16c80f cmMakefile: Fix @CMAKE_CURRENT_LIST_LINE@ for ExpandVariablesInStringNew
dda4755b46 cmMakefile: Fix ConfigureString not passing filename and line
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2675
-rw-r--r-- | Source/cmMakefile.cxx | 22 | ||||
-rw-r--r-- | Tests/CMakeTests/StringTest.cmake.in | 2 | ||||
-rw-r--r-- | Tests/CMakeTests/StringTestScript.cmake | 25 |
3 files changed, 44 insertions, 5 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5ad8ef6..5cd6ba5 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2727,6 +2727,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( cmState* state = this->GetCMakeInstance()->GetState(); + static const std::string lineVar = "CMAKE_CURRENT_LIST_LINE"; do { char inc = *in; switch (inc) { @@ -2739,7 +2740,6 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( const char* value = nullptr; std::string varresult; std::string svalue; - static const std::string lineVar = "CMAKE_CURRENT_LIST_LINE"; switch (var.domain) { case NORMAL: if (filename && lookup == lineVar) { @@ -2889,7 +2889,14 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( "abcdefghijklmnopqrstuvwxyz" "0123456789/_.+-")) { std::string variable(in + 1, nextAt - in - 1); - std::string varresult = this->GetSafeDefinition(variable); + + std::string varresult; + if (filename && variable == lineVar) { + varresult = std::to_string(line); + } else { + varresult = this->GetSafeDefinition(variable); + } + if (escapeQuotes) { varresult = cmSystemTools::EscapeQuotes(varresult); } @@ -3648,8 +3655,15 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output, } // Perform variable replacements. - this->ExpandVariablesInString(output, escapeQuotes, true, atOnly, nullptr, - -1, true, true); + const char* filename = nullptr; + long lineNumber = -1; + if (!this->Backtrace.Empty()) { + const auto& currentTrace = this->Backtrace.Top(); + filename = currentTrace.FilePath.c_str(); + lineNumber = currentTrace.Line; + } + this->ExpandVariablesInString(output, escapeQuotes, true, atOnly, filename, + lineNumber, true, true); } int cmMakefile::ConfigureFile(const char* infile, const char* outfile, diff --git a/Tests/CMakeTests/StringTest.cmake.in b/Tests/CMakeTests/StringTest.cmake.in index 566f4b1..154afa7 100644 --- a/Tests/CMakeTests/StringTest.cmake.in +++ b/Tests/CMakeTests/StringTest.cmake.in @@ -81,7 +81,7 @@ check_cmake_test(String # Execute each test listed in StringTestScript.cmake: # set(scriptname "@CMAKE_CURRENT_SOURCE_DIR@/StringTestScript.cmake") -set(number_of_tests_expected 70) +set(number_of_tests_expected 74) include("@CMAKE_CURRENT_SOURCE_DIR@/ExecuteScriptTests.cmake") execute_all_script_tests(${scriptname} number_of_tests_executed) diff --git a/Tests/CMakeTests/StringTestScript.cmake b/Tests/CMakeTests/StringTestScript.cmake index 44d5653..e069897 100644 --- a/Tests/CMakeTests/StringTestScript.cmake +++ b/Tests/CMakeTests/StringTestScript.cmake @@ -1,5 +1,18 @@ message(STATUS "testname='${testname}'") +function(test_configure_line_number EXPRESSION POLICY) + cmake_policy(PUSH) + cmake_policy(SET CMP0053 ${POLICY}) + string(CONFIGURE + "${EXPRESSION}" v) # line should indicate string() call + math(EXPR vplus3 "${v} + 3") + if(NOT ${CMAKE_CURRENT_LIST_LINE} EQUAL ${vplus3}) + message(SEND_ERROR "Couldn't configure CMAKE_CURRENT_LIST_LINE, evaluated into '${v}'") + endif() + message(STATUS "v='${v}'") + cmake_policy(POP) +endfunction() + if(testname STREQUAL empty) # fail string() @@ -32,6 +45,18 @@ elseif(testname STREQUAL configure_escape_quotes) # pass string(CONFIGURE "this is @testname@" v ESCAPE_QUOTES) message(STATUS "v='${v}'") +elseif(testname STREQUAL configure_line_number_CMP0053_old) # pass + test_configure_line_number("\${CMAKE_CURRENT_LIST_LINE}" OLD) + +elseif(testname STREQUAL configure_line_number_CMP0053_new) # pass + test_configure_line_number("\${CMAKE_CURRENT_LIST_LINE}" NEW) + +elseif(testname STREQUAL configure_line_number_CMP0053_old_use_at) # pass + test_configure_line_number("\@CMAKE_CURRENT_LIST_LINE\@" OLD) + +elseif(testname STREQUAL configure_line_number_CMP0053_new_use_at) # pass + test_configure_line_number("\@CMAKE_CURRENT_LIST_LINE\@" NEW) + elseif(testname STREQUAL configure_bogus) # fail string(CONFIGURE "this is @testname@" v ESCAPE_QUOTES BOGUS) |