From fd84f510f8f22244853115782af58cad5884934b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 9 Jan 2020 14:40:44 -0500 Subject: cmLocalGenerator: simplify the current source dir query --- Source/cmLocalGenerator.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 18f82dd..f9d8e55 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2003,8 +2003,7 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName, // Treat the name as relative to the source directory in which it // was given. - dep = cmStrCat(this->StateSnapshot.GetDirectory().GetCurrentSource(), '/', - inName); + dep = cmStrCat(this->GetCurrentSourceDirectory(), '/', inName); return true; } -- cgit v0.12 From fd0ba705ce37f54eb88f17e257e5a57e823351bb Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 9 Jan 2020 10:14:38 -0500 Subject: add_custom_command: check if a relative path should be an in-source path This still is broken for dependencies on generated paths where they get generated to the source directory rather than the build directory however, but there's no way to determine that is the case. Fixes: #20194 --- Source/cmCustomCommandGenerator.cxx | 4 ---- Source/cmLocalGenerator.cxx | 7 +++++++ Tests/CustomCommand/CMakeLists.txt | 8 ++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index a595007..34f815f 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -8,7 +8,6 @@ #include -#include "cmAlgorithms.h" #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmGeneratorExpression.h" @@ -30,9 +29,6 @@ void AppendPaths(const std::vector& inputs, cmExpandedList(cge->Evaluate(lg, config)); for (std::string& it : result) { cmSystemTools::ConvertToUnixSlashes(it); - if (cmContains(it, '/') && !cmSystemTools::FileIsFullPath(it)) { - it = cmStrCat(lg->GetMakefile()->GetCurrentBinaryDirectory(), '/', it); - } if (cmSystemTools::FileIsFullPath(it)) { it = cmSystemTools::CollapseFullPath( it, lg->GetMakefile()->GetHomeOutputDirectory()); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f9d8e55..6b282ab 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2004,6 +2004,13 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName, // Treat the name as relative to the source directory in which it // was given. dep = cmStrCat(this->GetCurrentSourceDirectory(), '/', inName); + + // If the in-source path does not exist, assume it instead lives in the + // binary directory. + if (!cmSystemTools::FileExists(dep)) { + dep = cmStrCat(this->GetCurrentBinaryDirectory(), '/', inName); + } + return true; } diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt index 70e8476..86c74ba 100644 --- a/Tests/CustomCommand/CMakeLists.txt +++ b/Tests/CustomCommand/CMakeLists.txt @@ -549,3 +549,11 @@ add_custom_command( ) add_custom_target(depends_on_path ALL DEPENDS "depends_on_path.txt") + +add_custom_command( + OUTPUT "depends_on_in_source_path.txt" + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/main.cxx" in_source_path.txt + DEPENDS main.cxx +) + +add_custom_target(depends_on_in_source_path ALL DEPENDS "depends_on_in_source_path.txt") -- cgit v0.12 From ec479f101f7113d21efd15257461e337ddc4f8b4 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 9 Jan 2020 16:40:22 -0500 Subject: cmLocalGenerator: collapse the path after construction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The path may contain `..` or `.` components naïvely, so compute them out before letting the generator handle them. --- Source/cmLocalGenerator.cxx | 2 ++ Tests/CustomCommand/CMakeLists.txt | 1 + 2 files changed, 3 insertions(+) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 6b282ab..4f1f582 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2011,6 +2011,8 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName, dep = cmStrCat(this->GetCurrentBinaryDirectory(), '/', inName); } + dep = cmSystemTools::CollapseFullPath(dep, this->GetBinaryDirectory()); + return true; } diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt index 86c74ba..d43cdba 100644 --- a/Tests/CustomCommand/CMakeLists.txt +++ b/Tests/CustomCommand/CMakeLists.txt @@ -535,6 +535,7 @@ set_property(SOURCE "${gen_file}" PROPERTY SYMBOLIC ON) add_custom_target(command_expand_lists ALL DEPENDS "${gen_file}") set_property(TARGET command_expand_lists PROPERTY CMPARGS "${cmp_args}") +# This also tests that `./` is squeezed out of the resulting path. set(depends_path "./depended_upon_path.txt") add_custom_command( -- cgit v0.12 From db4780d58408aa592fdfd4524ebdea83c4c8e898 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 15 Jan 2020 15:35:49 -0500 Subject: cmGeneratorTarget: search for relative paths to the binary directory Dependencies in the form `./somepath.txt` are not found otherwise because we only match on last-path-component searches and `.` never shows up in a full path as a full component. --- Source/cmGeneratorTarget.cxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index b3fb132..b18d8bf 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -2713,6 +2713,17 @@ void cmTargetTraceDependencies::FollowName(std::string const& name) if (i == this->NameMap.end() || i->first != name) { // Check if we know how to generate this file. cmSourcesWithOutput sources = this->Makefile->GetSourcesWithOutput(name); + // If we failed to find a target or source and we have a relative path, it + // might be a valid source if made relative to the current binary + // directory. + if (!sources.Target && !sources.Source && + !cmSystemTools::FileIsFullPath(name)) { + auto fullname = + cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/', name); + fullname = cmSystemTools::CollapseFullPath( + fullname, this->Makefile->GetHomeOutputDirectory()); + sources = this->Makefile->GetSourcesWithOutput(fullname); + } i = this->NameMap.emplace_hint(i, name, sources); } if (cmTarget* t = i->second.Target) { -- cgit v0.12 From e23475dc730b0ced1ba36b0ae091afcf27b06435 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 16 Jan 2020 09:38:32 -0500 Subject: Tests/CustomCommand: fix custom command line to actually make its output --- Tests/CustomCommand/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt index d43cdba..b784bc0 100644 --- a/Tests/CustomCommand/CMakeLists.txt +++ b/Tests/CustomCommand/CMakeLists.txt @@ -553,7 +553,7 @@ add_custom_target(depends_on_path ALL DEPENDS "depends_on_path.txt") add_custom_command( OUTPUT "depends_on_in_source_path.txt" - COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/main.cxx" in_source_path.txt + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/main.cxx" depends_on_in_source_path.txt DEPENDS main.cxx ) -- cgit v0.12 From ba3a417dce45c6aa4f93d520ef0546b20f13fad9 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 16 Jan 2020 09:38:49 -0500 Subject: Tests/CustomCommand: add a test for depending on a `./path` --- Tests/CustomCommand/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt index b784bc0..196fea3 100644 --- a/Tests/CustomCommand/CMakeLists.txt +++ b/Tests/CustomCommand/CMakeLists.txt @@ -558,3 +558,11 @@ add_custom_command( ) add_custom_target(depends_on_in_source_path ALL DEPENDS "depends_on_in_source_path.txt") + +add_custom_command( + OUTPUT "depends_on_in_rel_source_path.txt" + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/main.cxx" depends_on_in_rel_source_path.txt + DEPENDS ./main.cxx +) + +add_custom_target(depends_on_in_rel_source_path ALL DEPENDS "depends_on_in_rel_source_path.txt") -- cgit v0.12