diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmOutputConverter.cxx | 46 | ||||
-rw-r--r-- | Source/cmOutputConverter.h | 9 |
2 files changed, 51 insertions, 4 deletions
diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx index 3d61743f35..e62e0cd328 100644 --- a/Source/cmOutputConverter.cxx +++ b/Source/cmOutputConverter.cxx @@ -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; @@ -84,19 +101,40 @@ void cmOutputConverter::SetRelativePathTop(std::string const& topSource, { 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); } diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h index 290809fd92..d19bccc186 100644 --- a/Source/cmOutputConverter.h +++ b/Source/cmOutputConverter.h @@ -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; }; |