Merge topic 'symlink-build-under-source'

d33b12d84b Add support for build tree symlink inside source tree
43416c48ed cmOutputConverter: Always set relative path top source and binary together
de766bc7e0 Xcode: Fix support for source tree symlink inside build tree
55db2cf1e5 Makefiles: Fix "make depend" with add_custom_command DEPFILE

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !7020
This commit is contained in:
Brad King
2022-03-01 13:47:10 +00:00
committed by Kitware Robot
7 changed files with 73 additions and 43 deletions

View File

@@ -2495,8 +2495,7 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
snapshot.GetDirectory().SetCurrentBinary(dir_cur_bld);
auto mfd = cm::make_unique<cmMakefile>(this, snapshot);
auto lgd = this->CreateLocalGenerator(mfd.get());
lgd->SetRelativePathTopSource(dir_top_src);
lgd->SetRelativePathTopBinary(dir_top_bld);
lgd->SetRelativePathTop(dir_top_src, dir_top_bld);
this->Makefiles.push_back(std::move(mfd));
this->LocalGenerators.push_back(std::move(lgd));
}

View File

@@ -4695,10 +4695,12 @@ std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(
std::string cmGlobalXCodeGenerator::RelativeToSource(const std::string& p)
{
// We force conversion because Xcode breakpoints do not work unless
// they are in a file named relative to the source tree.
return cmSystemTools::ForceToRelativePath(
this->CurrentRootGenerator->GetCurrentSourceDirectory(), p);
std::string const& rootSrc =
this->CurrentRootGenerator->GetCurrentSourceDirectory();
if (cmSystemTools::IsSubDirectory(p, rootSrc)) {
return cmSystemTools::ForceToRelativePath(rootSrc, p);
}
return p;
}
std::string cmGlobalXCodeGenerator::RelativeToBinary(const std::string& p)

View File

@@ -1508,13 +1508,12 @@ bool cmLocalUnixMakefileGenerator3::ScanDependencies(
}
// Setup relative path top directories.
if (cmValue relativePathTopSource =
mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_SOURCE")) {
this->SetRelativePathTopSource(*relativePathTopSource);
}
if (cmValue relativePathTopBinary =
mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_BINARY")) {
this->SetRelativePathTopBinary(*relativePathTopBinary);
cmValue relativePathTopSource =
mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_SOURCE");
cmValue relativePathTopBinary =
mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_BINARY");
if (relativePathTopSource && relativePathTopBinary) {
this->SetRelativePathTop(*relativePathTopSource, *relativePathTopBinary);
}
} else {
cmSystemTools::Error("Directory Information file not found");
@@ -1849,7 +1848,7 @@ void cmLocalUnixMakefileGenerator3::ClearDependencies(cmMakefile* mf,
cmSystemTools::Touch(DepTimestamp.GenericString(), true);
// clear the dependencies files generated by the compiler
std::vector<std::string> dependencies = cmExpandedList(depsFiles);
std::vector<std::string> dependencies = cmExpandedList(depsFiles, true);
cmDependsCompiler depsManager;
depsManager.SetVerbose(verbose);
depsManager.ClearDependencies(dependencies);

View File

@@ -34,6 +34,7 @@ cmOutputConverter::cmOutputConverter(cmStateSnapshot const& snapshot)
assert(this->StateSnapshot.IsValid());
this->ComputeRelativePathTopSource();
this->ComputeRelativePathTopBinary();
this->ComputeRelativePathTopRelation();
}
void cmOutputConverter::ComputeRelativePathTopSource()
@@ -69,6 +70,22 @@ void cmOutputConverter::ComputeRelativePathTopBinary()
this->RelativePathTopBinary = snapshot.GetDirectory().GetCurrentBinary();
}
void cmOutputConverter::ComputeRelativePathTopRelation()
{
if (cmSystemTools::ComparePath(this->RelativePathTopSource,
this->RelativePathTopBinary)) {
this->RelativePathTopRelation = TopRelation::InSource;
} else if (cmSystemTools::IsSubDirectory(this->RelativePathTopBinary,
this->RelativePathTopSource)) {
this->RelativePathTopRelation = TopRelation::BinInSrc;
} else if (cmSystemTools::IsSubDirectory(this->RelativePathTopSource,
this->RelativePathTopBinary)) {
this->RelativePathTopRelation = TopRelation::SrcInBin;
} else {
this->RelativePathTopRelation = TopRelation::Separate;
}
}
std::string const& cmOutputConverter::GetRelativePathTopSource() const
{
return this->RelativePathTopSource;
@@ -79,27 +96,45 @@ std::string const& cmOutputConverter::GetRelativePathTopBinary() const
return this->RelativePathTopBinary;
}
void cmOutputConverter::SetRelativePathTopSource(std::string const& top)
void cmOutputConverter::SetRelativePathTop(std::string const& topSource,
std::string const& topBinary)
{
this->RelativePathTopSource = top;
}
void cmOutputConverter::SetRelativePathTopBinary(std::string const& top)
{
this->RelativePathTopBinary = top;
this->RelativePathTopSource = topSource;
this->RelativePathTopBinary = topBinary;
this->ComputeRelativePathTopRelation();
}
std::string cmOutputConverter::MaybeRelativeTo(
std::string const& local_path, std::string const& remote_path) const
{
bool bothInBinary =
PathEqOrSubDir(local_path, this->RelativePathTopBinary) &&
bool localInBinary = PathEqOrSubDir(local_path, this->RelativePathTopBinary);
bool remoteInBinary =
PathEqOrSubDir(remote_path, this->RelativePathTopBinary);
bool bothInSource =
PathEqOrSubDir(local_path, this->RelativePathTopSource) &&
bool localInSource = PathEqOrSubDir(local_path, this->RelativePathTopSource);
bool remoteInSource =
PathEqOrSubDir(remote_path, this->RelativePathTopSource);
switch (this->RelativePathTopRelation) {
case TopRelation::Separate:
// Checks are independent.
break;
case TopRelation::BinInSrc:
localInSource = localInSource && !localInBinary;
remoteInSource = remoteInSource && !remoteInBinary;
break;
case TopRelation::SrcInBin:
localInBinary = localInBinary && !localInSource;
remoteInBinary = remoteInBinary && !remoteInSource;
break;
case TopRelation::InSource:
// Checks are identical.
break;
};
bool const bothInBinary = localInBinary && remoteInBinary;
bool const bothInSource = localInSource && remoteInSource;
if (bothInBinary || bothInSource) {
return cmSystemTools::ForceToRelativePath(local_path, remote_path);
}

View File

@@ -29,8 +29,8 @@ public:
std::string const& GetRelativePathTopSource() const;
std::string const& GetRelativePathTopBinary() const;
void SetRelativePathTopSource(std::string const& top);
void SetRelativePathTopBinary(std::string const& top);
void SetRelativePathTop(std::string const& topSource,
std::string const& topBinary);
enum OutputFormat
{
@@ -147,8 +147,17 @@ private:
// safely by the build tools.
std::string RelativePathTopSource;
std::string RelativePathTopBinary;
enum class TopRelation
{
Separate,
BinInSrc,
SrcInBin,
InSource,
};
TopRelation RelativePathTopRelation = TopRelation::Separate;
void ComputeRelativePathTopSource();
void ComputeRelativePathTopBinary();
void ComputeRelativePathTopRelation();
std::string MaybeRelativeTo(std::string const& local_path,
std::string const& remote_path) const;
};

View File

@@ -1286,8 +1286,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
// FIXME: With advanced add_subdirectory usage, these are
// not necessarily the same as the generator originally used.
// We should pass all these directories through an info file.
lgd->SetRelativePathTopSource(homeDir);
lgd->SetRelativePathTopBinary(homeOutDir);
lgd->SetRelativePathTop(homeDir, homeOutDir);
// Actually scan dependencies.
return lgd->UpdateDependencies(depInfo, verbose, color) ? 0 : 2;
@@ -1569,8 +1568,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
// FIXME: With advanced add_subdirectory usage, these are
// not necessarily the same as the generator originally used.
// We should pass all these directories through an info file.
lgd->SetRelativePathTopSource(homeDir);
lgd->SetRelativePathTopBinary(homeOutDir);
lgd->SetRelativePathTop(homeDir, homeOutDir);
return cmTransformDepfile(format, *lgd, args[8], args[9]) ? 0 : 2;
}

View File

@@ -76,18 +76,6 @@ function (run_symlink_test case src bin src_from_bin bin_from_src)
run_symlink_test_case("${case}" -S "../${name}/${src}" -B "../${name}/${bin}")
# Verify paths passed to compiler.
if(case MATCHES "^(different|asymmetric)-bin_in_src$")
# FIXME: Some generators compute incorrect relative paths.
message(STATUS "${case}-exe - SKIPPED")
message(STATUS "${case}-exe-build - SKIPPED")
return()
endif()
if(case MATCHES "^(different|asymmetric)-src_in_bin$" AND RunCMake_GENERATOR STREQUAL "Xcode")
# FIXME: The Xcode generator computes an incorrect relative path.
message(STATUS "${case}-exe - SKIPPED")
message(STATUS "${case}-exe-build - SKIPPED")
return()
endif()
unset(RunCMake_TEST_VARIANT_DESCRIPTION)
run_symlink_test_case("${case}-exe" -S "${src}" -B "${bin}")
if (RunCMake_GENERATOR MATCHES "Xcode")