From a9602bb41e562ae48332e5fd54577868e9d23e06 Mon Sep 17 00:00:00 2001 From: Josef Angstenberger Date: Sat, 1 Aug 2020 02:58:26 +0200 Subject: file(GENERATE): Refactor inputFileName calculation --- Source/cmGeneratorExpressionEvaluationFile.cxx | 21 +++++++++++++++------ Source/cmGeneratorExpressionEvaluationFile.h | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index 1107adb..e421c51 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -125,12 +125,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg) if (this->InputIsContent) { inputContent = this->Input; } else { - std::string inputFileName = this->Input; - if (cmSystemTools::FileIsFullPath(inputFileName)) { - inputFileName = cmSystemTools::CollapseFullPath(inputFileName); - } else { - inputFileName = this->FixRelativePath(inputFileName, PathForInput, lg); - } + const std::string inputFileName = this->GetInputFileName(lg); lg->GetMakefile()->AddCMakeDependFile(inputFileName); cmSystemTools::GetPermissions(inputFileName.c_str(), perm); cmsys::ifstream fin(inputFileName.c_str()); @@ -174,6 +169,20 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg) } } +std::string cmGeneratorExpressionEvaluationFile::GetInputFileName( + cmLocalGenerator* lg) +{ + std::string inputFileName = this->Input; + + if (cmSystemTools::FileIsFullPath(inputFileName)) { + inputFileName = cmSystemTools::CollapseFullPath(inputFileName); + } else { + inputFileName = this->FixRelativePath(inputFileName, PathForInput, lg); + } + + return inputFileName; +} + std::string cmGeneratorExpressionEvaluationFile::FixRelativePath( std::string const& relativePath, PathRole role, cmLocalGenerator* lg) { diff --git a/Source/cmGeneratorExpressionEvaluationFile.h b/Source/cmGeneratorExpressionEvaluationFile.h index c3bc4c8..eb1e03d 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.h +++ b/Source/cmGeneratorExpressionEvaluationFile.h @@ -38,6 +38,7 @@ private: cmCompiledGeneratorExpression* inputExpression, std::map& outputFiles, mode_t perm); + std::string GetInputFileName(cmLocalGenerator* lg); enum PathRole { PathForInput, -- cgit v0.12 From 2dc2732f679d160ea954bf8903e5b7626096a2e8 Mon Sep 17 00:00:00 2001 From: Josef Angstenberger Date: Sat, 1 Aug 2020 02:58:44 +0200 Subject: file(GENERATE): Refactor outputFileName calculation --- Source/cmGeneratorExpressionEvaluationFile.cxx | 24 ++++++++++++++++-------- Source/cmGeneratorExpressionEvaluationFile.h | 3 +++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index e421c51..667b4e6 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -54,17 +54,10 @@ void cmGeneratorExpressionEvaluationFile::Generate( } } - std::string outputFileName = this->OutputFileExpr->Evaluate( - lg, config, nullptr, nullptr, nullptr, lang); + const std::string outputFileName = this->GetOutputFileName(lg, config, lang); const std::string& outputContent = inputExpression->Evaluate(lg, config, nullptr, nullptr, nullptr, lang); - if (cmSystemTools::FileIsFullPath(outputFileName)) { - outputFileName = cmSystemTools::CollapseFullPath(outputFileName); - } else { - outputFileName = this->FixRelativePath(outputFileName, PathForOutput, lg); - } - auto it = outputFiles.find(outputFileName); if (it != outputFiles.end()) { @@ -183,6 +176,21 @@ std::string cmGeneratorExpressionEvaluationFile::GetInputFileName( return inputFileName; } +std::string cmGeneratorExpressionEvaluationFile::GetOutputFileName( + cmLocalGenerator* lg, const std::string& config, const std::string& lang) +{ + std::string outputFileName = this->OutputFileExpr->Evaluate( + lg, config, nullptr, nullptr, nullptr, lang); + + if (cmSystemTools::FileIsFullPath(outputFileName)) { + outputFileName = cmSystemTools::CollapseFullPath(outputFileName); + } else { + outputFileName = this->FixRelativePath(outputFileName, PathForOutput, lg); + } + + return outputFileName; +} + std::string cmGeneratorExpressionEvaluationFile::FixRelativePath( std::string const& relativePath, PathRole role, cmLocalGenerator* lg) { diff --git a/Source/cmGeneratorExpressionEvaluationFile.h b/Source/cmGeneratorExpressionEvaluationFile.h index eb1e03d..a258a2d 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.h +++ b/Source/cmGeneratorExpressionEvaluationFile.h @@ -39,6 +39,9 @@ private: std::map& outputFiles, mode_t perm); std::string GetInputFileName(cmLocalGenerator* lg); + std::string GetOutputFileName(cmLocalGenerator* lg, + const std::string& config, + const std::string& lang); enum PathRole { PathForInput, -- cgit v0.12 From 04fbd7566a67a773d17901b9bb3a9979efd3cdb4 Mon Sep 17 00:00:00 2001 From: Josef Angstenberger Date: Sat, 1 Aug 2020 03:21:42 +0200 Subject: file(GENERATE): Fix missing check for policy CMP0070 In commit 82be694c7a (file(GENERATE): Add policy CMP0070 to define relative path behavior, 2017-06-08, v3.10.0-rc1~534^2), one path calculation was forgotten. Because of this the path name according to the old behavior was added to the list of CMake generated files. Fixes: #21038 --- Source/cmGeneratorExpressionEvaluationFile.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index 667b4e6..6647e62 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -94,8 +94,7 @@ void cmGeneratorExpressionEvaluationFile::CreateOutputFile( gg->GetEnabledLanguages(enabledLanguages); for (std::string const& le : enabledLanguages) { - std::string name = this->OutputFileExpr->Evaluate(lg, config, nullptr, - nullptr, nullptr, le); + std::string const name = this->GetOutputFileName(lg, config, le); cmSourceFile* sf = lg->GetMakefile()->GetOrCreateSource( name, false, cmSourceFileLocationKind::Known); // Tell TraceDependencies that the file is not expected to exist -- cgit v0.12 From 1977f7833b222c0e5b2fa09ad1ac2f85cf9416ea Mon Sep 17 00:00:00 2001 From: Josef Angstenberger Date: Sun, 9 Aug 2020 15:44:58 +0200 Subject: file(GENERATE): Update existing tests Add the additional CMP0070 warning as expected stderr. The warning occurs twice because the output file name is evaluated multiple times. --- Tests/RunCMake/File_Generate/CMP0070-WARN-stderr.txt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Tests/RunCMake/File_Generate/CMP0070-WARN-stderr.txt b/Tests/RunCMake/File_Generate/CMP0070-WARN-stderr.txt index dbabaa9..a7a231b 100644 --- a/Tests/RunCMake/File_Generate/CMP0070-WARN-stderr.txt +++ b/Tests/RunCMake/File_Generate/CMP0070-WARN-stderr.txt @@ -1,4 +1,18 @@ -^CMake Warning \(dev\) in CMakeLists.txt: +^(CMake Warning \(dev\) in CMakeLists.txt: + Policy CMP0070 is not set: Define file\(GENERATE\) behavior for relative + paths. Run "cmake --help-policy CMP0070" for policy details. Use the + cmake_policy command to set the policy and suppress this warning. + + file\(GENERATE\) given relative OUTPUT path: + + relative-output-WARN.txt + + This is not defined behavior unless CMP0070 is set to NEW. For + compatibility with older versions of CMake, the previous undefined behavior + will be used. +This warning is for project developers. Use -Wno-dev to suppress it. ++)+ +CMake Warning \(dev\) in CMakeLists.txt: Policy CMP0070 is not set: Define file\(GENERATE\) behavior for relative paths. Run "cmake --help-policy CMP0070" for policy details. Use the cmake_policy command to set the policy and suppress this warning. -- cgit v0.12 From 462b6d83e8c1113296ae52202ab664508f7865a7 Mon Sep 17 00:00:00 2001 From: Josef Angstenberger Date: Sun, 9 Aug 2020 18:48:58 +0200 Subject: file(GENERATE): Test source properties Output files get the source property `GENERATED` which is indirectly checked by adding them to a library. For a missing file that is not generated CMake will abort. With the new behavior according CMP0070 relative files are generated into the binary directory. --- Tests/RunCMake/File_Generate/RunCMakeTest.cmake | 4 ++++ .../SourceProperty-CMP0070-NEW-result.txt | 1 + .../SourceProperty-CMP0070-NEW-stderr.txt | 11 +++++++++++ .../File_Generate/SourceProperty-CMP0070-NEW.cmake | 8 ++++++++ .../SourceProperty-CMP0070-OLD-result.txt | 1 + .../SourceProperty-CMP0070-OLD-stderr.txt | 23 ++++++++++++++++++++++ .../File_Generate/SourceProperty-CMP0070-OLD.cmake | 8 ++++++++ .../File_Generate/SourceProperty-stderr.txt | 10 ++++++++++ Tests/RunCMake/File_Generate/SourceProperty.cmake | 14 +++++++++++++ 9 files changed, 80 insertions(+) create mode 100644 Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW-result.txt create mode 100644 Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW-stderr.txt create mode 100644 Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW.cmake create mode 100644 Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD-result.txt create mode 100644 Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD-stderr.txt create mode 100644 Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD.cmake create mode 100644 Tests/RunCMake/File_Generate/SourceProperty-stderr.txt create mode 100644 Tests/RunCMake/File_Generate/SourceProperty.cmake diff --git a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake index 5987417..770fc6e 100644 --- a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake +++ b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake @@ -4,6 +4,10 @@ run_cmake(CMP0070-NEW) run_cmake(CMP0070-OLD) run_cmake(CMP0070-WARN) +run_cmake(SourceProperty) +run_cmake(SourceProperty-CMP0070-NEW) +run_cmake(SourceProperty-CMP0070-OLD) + run_cmake(CommandConflict) if(RunCMake_GENERATOR_IS_MULTI_CONFIG) run_cmake(OutputConflict) diff --git a/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW-result.txt b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW-stderr.txt b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW-stderr.txt new file mode 100644 index 0000000..2c385c4 --- /dev/null +++ b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW-stderr.txt @@ -0,0 +1,11 @@ +^CMake Error at SourceProperty-CMP0070-NEW.cmake:[0-9]+ \(add_library\): + Cannot find source file: + +.*\/relative-output-NEW\.c + + Tried extensions \.c \.C.* +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) + + +CMake Generate step failed. Build files cannot be regenerated correctly.$ diff --git a/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW.cmake b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW.cmake new file mode 100644 index 0000000..d2b3e0c --- /dev/null +++ b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-NEW.cmake @@ -0,0 +1,8 @@ +enable_language(C) +add_library(foo) + +cmake_policy(SET CMP0070 NEW) +file(GENERATE OUTPUT relative-output-NEW.c CONTENT "") +target_sources(foo PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/relative-output-NEW.c" +) diff --git a/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD-result.txt b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD-stderr.txt b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD-stderr.txt new file mode 100644 index 0000000..fcb53a7 --- /dev/null +++ b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD-stderr.txt @@ -0,0 +1,23 @@ +^CMake Deprecation Warning at SourceProperty-CMP0070-OLD.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0070 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) + + +CMake Error at SourceProperty-CMP0070-OLD.cmake:[0-9]+ \(add_library\): + Cannot find source file: + +.*\/relative-output-OLD\.c + + Tried extensions \.c \.C.* +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) + + +CMake Generate step failed. Build files cannot be regenerated correctly.$ diff --git a/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD.cmake b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD.cmake new file mode 100644 index 0000000..48eae1e --- /dev/null +++ b/Tests/RunCMake/File_Generate/SourceProperty-CMP0070-OLD.cmake @@ -0,0 +1,8 @@ +enable_language(C) +add_library(foo) + +cmake_policy(SET CMP0070 OLD) +file(GENERATE OUTPUT relative-output-OLD.c CONTENT "") +target_sources(foo PRIVATE + "${CMAKE_CURRENT_BINARY_DIR}/relative-output-OLD.c" +) diff --git a/Tests/RunCMake/File_Generate/SourceProperty-stderr.txt b/Tests/RunCMake/File_Generate/SourceProperty-stderr.txt new file mode 100644 index 0000000..47ec651 --- /dev/null +++ b/Tests/RunCMake/File_Generate/SourceProperty-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at SourceProperty.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0070 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/File_Generate/SourceProperty.cmake b/Tests/RunCMake/File_Generate/SourceProperty.cmake new file mode 100644 index 0000000..231c670 --- /dev/null +++ b/Tests/RunCMake/File_Generate/SourceProperty.cmake @@ -0,0 +1,14 @@ +enable_language(C) +add_library(SourceProperty) + +cmake_policy(SET CMP0070 OLD) +file(GENERATE OUTPUT relative-output-OLD.c CONTENT "") +target_sources(SourceProperty PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/relative-output-OLD.c" +) + +cmake_policy(SET CMP0070 NEW) +file(GENERATE OUTPUT relative-output-NEW.c CONTENT "") +target_sources(SourceProperty PRIVATE + "${CMAKE_CURRENT_BINARY_DIR}/relative-output-NEW.c" +) -- cgit v0.12