diff options
25 files changed, 89 insertions, 86 deletions
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index a1df271..0414817 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -198,7 +198,7 @@ std::string cmCommonTargetGenerator::GetManifests() manifests.reserve(manifest_srcs.size()); for (cmSourceFile const* manifest_src : manifest_srcs) { manifests.push_back(this->LocalCommonGenerator->ConvertToOutputFormat( - this->LocalCommonGenerator->ConvertToRelativePath( + this->LocalCommonGenerator->MaybeConvertToRelativePath( this->LocalCommonGenerator->GetWorkingDirectory(), manifest_src->GetFullPath()), cmOutputConverter::SHELL)); diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx index 072d116..dcf9cdf 100644 --- a/Source/cmDependsC.cxx +++ b/Source/cmDependsC.cxx @@ -100,7 +100,8 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources, // Compute a path to the object file to write to the internal depend file. // Any existing content of the internal depend file has already been // loaded in ValidDeps with this path as a key. - std::string obj_i = this->LocalGenerator->ConvertToRelativePath(binDir, obj); + std::string obj_i = + this->LocalGenerator->MaybeConvertToRelativePath(binDir, obj); if (this->ValidDeps != nullptr) { std::map<std::string, DependencyVector>::const_iterator tmpIt = @@ -234,7 +235,8 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources, for (std::string const& dep : dependencies) { makeDepends << obj_m << ": " << cmSystemTools::ConvertToOutputPath( - this->LocalGenerator->ConvertToRelativePath(binDir, dep)) + this->LocalGenerator->MaybeConvertToRelativePath(binDir, + dep)) << std::endl; internalDepends << " " << dep << std::endl; } diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 5833631..30067b7 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -899,7 +899,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) { const std::vector<cmGeneratorTarget*>& targets = lgen->GetGeneratorTargets(); - std::string subdir = lgen->ConvertToRelativePath( + std::string subdir = lgen->MaybeConvertToRelativePath( this->HomeOutputDirectory, lgen->GetCurrentBinaryDirectory()); if (subdir == ".") { subdir.clear(); diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 19605e4..3a65ecc 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -150,7 +150,8 @@ void cmGhsMultiTargetGenerator::WriteTargetSpecifics(std::ostream& fout, if (this->TagType != GhsMultiGpj::SUBPROJECT) { // set target binary file destination outpath = this->GeneratorTarget->GetDirectory(config); - outpath = this->LocalGenerator->ConvertToRelativePath(rootpath, outpath); + outpath = + this->LocalGenerator->MaybeConvertToRelativePath(rootpath, outpath); fout << " :binDirRelative=\"" << outpath << "\"" << std::endl; fout << " -o \"" << this->TargetNameReal << "\"" << std::endl; } @@ -550,7 +551,7 @@ void cmGhsMultiTargetGenerator::WriteReferences(std::ostream& fout) std::string tpath = t->LocalGenerator->GetCurrentBinaryDirectory(); std::string rootpath = this->LocalGenerator->GetCurrentBinaryDirectory(); std::string outpath = - this->LocalGenerator->ConvertToRelativePath(rootpath, tpath) + "/" + + this->LocalGenerator->MaybeConvertToRelativePath(rootpath, tpath) + "/" + tname + "REF" + cmGlobalGhsMultiGenerator::FILE_EXTENSION; fout << outpath; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 2d36315..fff99b8 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -33,7 +33,6 @@ #include "cmMSVC60LinkLineComputer.h" #include "cmMakefile.h" #include "cmMessageType.h" -#include "cmOutputConverter.h" #include "cmPolicies.h" #include "cmSourceFile.h" #include "cmState.h" @@ -2804,8 +2803,9 @@ void cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs, } // Shorten the output name (in expected use case). - cmOutputConverter converter(this->GetMakefiles()[0]->GetStateSnapshot()); - std::string fname = converter.ConvertToRelativePath( + cmStateDirectory cmDir = + this->GetMakefiles()[0]->GetStateSnapshot().GetDirectory(); + std::string fname = cmDir.ConvertToRelPathIfNotContained( this->GetMakefiles()[0]->GetState()->GetBinaryDirectory(), outputs[0]); // Associate the hash with this output. diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index 557efec..ff4c3a3 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -297,7 +297,7 @@ void cmGlobalGhsMultiGenerator::WriteSubProjects( if (projName && projType) { cmLocalGenerator* lg = target->GetLocalGenerator(); std::string dir = lg->GetCurrentBinaryDirectory(); - dir = root->ConvertToRelativePath(rootBinaryDir, dir.c_str()); + dir = root->MaybeConvertToRelativePath(rootBinaryDir, dir.c_str()); if (dir == ".") { dir.clear(); } else { diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 23dbd76..8f09566 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -861,7 +861,7 @@ std::string const& cmGlobalNinjaGenerator::ConvertToNinjaPath( cmLocalNinjaGenerator* ng = static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]); std::string const& bin_dir = ng->GetState()->GetBinaryDirectory(); - std::string convPath = ng->ConvertToRelativePath(bin_dir, path); + std::string convPath = ng->MaybeConvertToRelativePath(bin_dir, path); convPath = this->NinjaOutputPath(convPath); #ifdef _WIN32 std::replace(convPath.begin(), convPath.end(), '/', '\\'); diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 52bb046..9d176c3 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -325,7 +325,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile() << "set(CMAKE_MAKEFILE_DEPENDS\n" << " \"CMakeCache.txt\"\n"; for (std::string const& f : lfiles) { - cmakefileStream << " \"" << lg->ConvertToRelativePath(currentBinDir, f) + cmakefileStream << " \"" + << lg->MaybeConvertToRelativePath(currentBinDir, f) << "\"\n"; } cmakefileStream << " )\n\n"; @@ -339,9 +340,11 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile() cmakefileStream << "# The corresponding makefile is:\n" << "set(CMAKE_MAKEFILE_OUTPUTS\n" << " \"" - << lg->ConvertToRelativePath(currentBinDir, makefileName) + << lg->MaybeConvertToRelativePath(currentBinDir, + makefileName) << "\"\n" - << " \"" << lg->ConvertToRelativePath(currentBinDir, check) + << " \"" + << lg->MaybeConvertToRelativePath(currentBinDir, check) << "\"\n"; cmakefileStream << " )\n\n"; @@ -354,7 +357,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile() const std::vector<std::string>& outfiles = lg->GetMakefile()->GetOutputFiles(); for (std::string const& outfile : outfiles) { - cmakefileStream << " \"" << lg->ConvertToRelativePath(binDir, outfile) + cmakefileStream << " \"" + << lg->MaybeConvertToRelativePath(binDir, outfile) << "\"\n"; } @@ -365,7 +369,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile() tmpStr = lg->GetCurrentBinaryDirectory(); tmpStr += cmake::GetCMakeFilesDirectory(); tmpStr += "/CMakeDirectoryInformation.cmake"; - cmakefileStream << " \"" << lg->ConvertToRelativePath(binDir, tmpStr) + cmakefileStream << " \"" + << lg->MaybeConvertToRelativePath(binDir, tmpStr) << "\"\n"; } cmakefileStream << " )\n\n"; @@ -474,7 +479,7 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRules2( // Begin the directory-level rules section. std::string dir = - cmSystemTools::ConvertToOutputPath(lg->ConvertToRelativePath( + cmSystemTools::ConvertToOutputPath(lg->MaybeConvertToRelativePath( lg->GetBinaryDirectory(), lg->GetCurrentBinaryDirectory())); lg->WriteDivider(ruleFileStream); ruleFileStream << "# Directory level rules for directory " << dir << "\n\n"; @@ -526,9 +531,9 @@ void cmGlobalUnixMakefileGenerator3::GenerateBuildCommand( if (fast) { tname += "/fast"; } - cmOutputConverter conv(mf->GetStateSnapshot()); tname = - conv.ConvertToRelativePath(mf->GetState()->GetBinaryDirectory(), tname); + mf->GetStateSnapshot().GetDirectory().ConvertToRelPathIfNotContained( + mf->GetState()->GetBinaryDirectory(), tname); cmSystemTools::ConvertToOutputSlashes(tname); makeCommand.push_back(std::move(tname)); } diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index cae46e1..c267a7b 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -367,7 +367,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( if (vcprojName) { cmLocalGenerator* lg = target->GetLocalGenerator(); std::string dir = lg->GetCurrentBinaryDirectory(); - dir = root->ConvertToRelativePath(rootBinaryDir, dir.c_str()); + dir = root->MaybeConvertToRelativePath(rootBinaryDir, dir.c_str()); if (dir == ".") { dir.clear(); // msbuild cannot handle ".\" prefix } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 80ccd73..3d6f36e 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3570,7 +3570,7 @@ std::string cmGlobalXCodeGenerator::RelativeToSource(const char* p) std::string cmGlobalXCodeGenerator::RelativeToBinary(const char* p) { - return this->CurrentLocalGenerator->ConvertToRelativePath( + return this->CurrentLocalGenerator->MaybeConvertToRelativePath( cmSystemTools::JoinPath(this->ProjectOutputDirectoryComponents), p); } diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 9aa1f32..aa53552 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -5,8 +5,8 @@ #include "cmListFileLexer.h" #include "cmMessageType.h" #include "cmMessenger.h" -#include "cmOutputConverter.h" #include "cmState.h" +#include "cmStateDirectory.h" #include "cmSystemTools.h" #include <assert.h> @@ -390,9 +390,8 @@ void cmListFileBacktrace::PrintTitle(std::ostream& out) const } cmListFileContext lfc = this->TopEntry->Context; cmStateSnapshot bottom = this->GetBottom(); - cmOutputConverter converter(bottom); if (!bottom.GetState()->GetIsInTryCompile()) { - lfc.FilePath = converter.ConvertToRelativePath( + lfc.FilePath = bottom.GetDirectory().ConvertToRelPathIfNotContained( bottom.GetState()->GetSourceDirectory(), lfc.FilePath); } out << (lfc.Line ? " at " : " in ") << lfc; @@ -409,7 +408,6 @@ void cmListFileBacktrace::PrintCallStack(std::ostream& out) const bool first = true; cmStateSnapshot bottom = this->GetBottom(); - cmOutputConverter converter(bottom); for (Entry const* cur = this->TopEntry->Parent.get(); !cur->IsBottom(); cur = cur->Parent.get()) { if (cur->Context.Name.empty()) { @@ -423,7 +421,7 @@ void cmListFileBacktrace::PrintCallStack(std::ostream& out) const } cmListFileContext lfc = cur->Context; if (!bottom.GetState()->GetIsInTryCompile()) { - lfc.FilePath = converter.ConvertToRelativePath( + lfc.FilePath = bottom.GetDirectory().ConvertToRelPathIfNotContained( bottom.GetState()->GetSourceDirectory(), lfc.FilePath); } out << " " << lfc << "\n"; diff --git a/Source/cmLocalCommonGenerator.cxx b/Source/cmLocalCommonGenerator.cxx index 7ce2c82..ad89335 100644 --- a/Source/cmLocalCommonGenerator.cxx +++ b/Source/cmLocalCommonGenerator.cxx @@ -47,7 +47,7 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags( target->GetFortranModuleDirectory(this->WorkingDirectory); if (!mod_dir.empty()) { mod_dir = this->ConvertToOutputFormat( - this->ConvertToRelativePath(this->WorkingDirectory, mod_dir), + this->MaybeConvertToRelativePath(this->WorkingDirectory, mod_dir), cmOutputConverter::SHELL); } else { mod_dir = diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 97e684b..89ad96d 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -316,7 +316,7 @@ void cmLocalGenerator::GenerateTestFiles() for (cmStateSnapshot const& i : children) { // TODO: Use add_subdirectory instead? std::string outP = i.GetDirectory().GetCurrentBinary(); - outP = this->ConvertToRelativePath(parentBinDir, outP); + outP = this->MaybeConvertToRelativePath(parentBinDir, outP); outP = cmOutputConverter::EscapeForCMake(outP); fout << "subdirs(" << outP << ")" << std::endl; } @@ -2294,7 +2294,7 @@ std::string cmLocalGenerator::ConstructComment( std::string currentBinaryDir = this->GetCurrentBinaryDirectory(); for (std::string const& o : ccg.GetOutputs()) { comment += sep; - comment += this->ConvertToRelativePath(currentBinaryDir, o); + comment += this->MaybeConvertToRelativePath(currentBinaryDir, o); sep = ", "; } return comment; @@ -2551,15 +2551,15 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget( std::string const& fullPath = source.GetFullPath(); // Try referencing the source relative to the source tree. - std::string relFromSource = - this->ConvertToRelativePath(this->GetCurrentSourceDirectory(), fullPath); + std::string relFromSource = this->MaybeConvertToRelativePath( + this->GetCurrentSourceDirectory(), fullPath); assert(!relFromSource.empty()); bool relSource = !cmSystemTools::FileIsFullPath(relFromSource); bool subSource = relSource && relFromSource[0] != '.'; // Try referencing the source relative to the binary tree. - std::string relFromBinary = - this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), fullPath); + std::string relFromBinary = this->MaybeConvertToRelativePath( + this->GetCurrentBinaryDirectory(), fullPath); assert(!relFromBinary.empty()); bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary); bool subBinary = relBinary && relFromBinary[0] != '.'; @@ -2658,6 +2658,13 @@ std::string const& cmLocalGenerator::GetCurrentSourceDirectory() const return this->StateSnapshot.GetDirectory().GetCurrentSource(); } +std::string cmLocalGenerator::MaybeConvertToRelativePath( + std::string const& local_path, std::string const& remote_path) const +{ + return this->StateSnapshot.GetDirectory().ConvertToRelPathIfNotContained( + local_path, remote_path); +} + std::string cmLocalGenerator::GetTargetDirectory( const cmGeneratorTarget* /*unused*/) const { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index dc54314..4be3905 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -302,6 +302,16 @@ public: std::string const& GetCurrentSourceDirectory() const; /** + * Convert the given remote path to a relative path with respect to + * the given local path. Both paths must use forward slashes and not + * already be escaped or quoted. + * The conversion is skipped if the paths are not both in the source + * or both in the binary tree. + */ + std::string MaybeConvertToRelativePath(std::string const& local_path, + std::string const& remote_path) const; + + /** * Generate a macOS application bundle Info.plist file. */ void GenerateAppleInfoPList(cmGeneratorTarget* target, diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index a8647b1..f252045 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -54,7 +54,7 @@ void cmLocalNinjaGenerator::Generate() { // Compute the path to use when referencing the current output // directory from the top output directory. - this->HomeRelativeOutputPath = this->ConvertToRelativePath( + this->HomeRelativeOutputPath = this->MaybeConvertToRelativePath( this->GetBinaryDirectory(), this->GetCurrentBinaryDirectory()); if (this->HomeRelativeOutputPath == ".") { this->HomeRelativeOutputPath.clear(); @@ -141,7 +141,8 @@ std::string cmLocalNinjaGenerator::ConvertToIncludeReference( format); } return this->ConvertToOutputFormat( - this->ConvertToRelativePath(this->GetBinaryDirectory(), path), format); + this->MaybeConvertToRelativePath(this->GetBinaryDirectory(), path), + format); } // Private methods. @@ -584,8 +585,8 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher( if (!outputs.empty()) { output = outputs[0]; if (ccg.GetWorkingDirectory().empty()) { - output = - this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), output); + output = this->MaybeConvertToRelativePath( + this->GetCurrentBinaryDirectory(), output); } output = this->ConvertToOutputFormat(output, cmOutputConverter::SHELL); } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index e590e52..1d4793a 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -2088,12 +2088,3 @@ void cmLocalUnixMakefileGenerator3::CreateCDCommand( [&prefix](std::string const& s) { return prefix + s; }); } } - -std::string cmLocalUnixMakefileGenerator3::MaybeConvertToRelativePath( - std::string const& base, std::string const& path) -{ - if (!this->GetStateSnapshot().GetDirectory().ContainsBoth(base, path)) { - return path; - } - return cmSystemTools::ForceToRelativePath(base, path); -} diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index ee6b37b..b256fdc 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -183,9 +183,6 @@ public: // Eclipse generator. void GetIndividualFileTargets(std::vector<std::string>& targets); - std::string MaybeConvertToRelativePath(std::string const& base, - std::string const& path); - protected: void WriteLocalMakefile(); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 677d033..cd97dc4 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -803,8 +803,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( target->GetProperty("Fortran_MODULE_DIRECTORY"); std::string modDir; if (target_mod_dir) { - modDir = this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), - target_mod_dir); + modDir = this->MaybeConvertToRelativePath( + this->GetCurrentBinaryDirectory(), target_mod_dir); } else { modDir = "."; } @@ -1306,7 +1306,7 @@ void cmLocalVisualStudio7GeneratorInternals::OutputLibraries( for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) { if (l->IsPath) { std::string rel = - lg->ConvertToRelativePath(currentBinDir, l->Value.c_str()); + lg->MaybeConvertToRelativePath(currentBinDir, l->Value.c_str()); fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " "; } else if (!l->Target || l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { @@ -1332,7 +1332,7 @@ void cmLocalVisualStudio7GeneratorInternals::OutputObjects( i != objs.end(); ++i) { if (!(*i)->GetObjectLibrary().empty()) { std::string const& objFile = (*i)->GetFullPath(); - std::string rel = lg->ConvertToRelativePath(currentBinDir, objFile); + std::string rel = lg->MaybeConvertToRelativePath(currentBinDir, objFile); fout << sep << lg->ConvertToXMLOutputPath(rel.c_str()); sep = " "; } @@ -1358,7 +1358,7 @@ void cmLocalVisualStudio7Generator::OutputLibraryDirectories( // Switch to a relative path specification if it is shorter. if (cmSystemTools::FileIsFullPath(dir.c_str())) { std::string rel = - this->ConvertToRelativePath(currentBinDir, dir.c_str()); + this->MaybeConvertToRelativePath(currentBinDir, dir.c_str()); if (rel.size() < dir.size()) { dir = rel; } diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index 2237da7..660729c 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -210,9 +210,10 @@ std::string cmLocalVisualStudioGenerator::ConstructScript( } if (workingDirectory.empty()) { - script += this->ConvertToOutputFormat( - this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), cmd), - cmOutputConverter::SHELL); + script += + this->ConvertToOutputFormat(this->MaybeConvertToRelativePath( + this->GetCurrentBinaryDirectory(), cmd), + cmOutputConverter::SHELL); } else { script += this->ConvertToOutputFormat(cmd.c_str(), SHELL); } diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx index 011c7d8..7d88b08 100644 --- a/Source/cmOutputConverter.cxx +++ b/Source/cmOutputConverter.cxx @@ -10,7 +10,6 @@ #include <vector> #include "cmState.h" -#include "cmStateDirectory.h" #include "cmSystemTools.h" cmOutputConverter::cmOutputConverter(cmStateSnapshot const& snapshot) @@ -72,17 +71,6 @@ std::string cmOutputConverter::ConvertDirectorySeparatorsForShell( return result; } -std::string cmOutputConverter::ConvertToRelativePath( - std::string const& local_path, std::string const& remote_path) const -{ - if (!this->StateSnapshot.GetDirectory().ContainsBoth(local_path, - remote_path)) { - return remote_path; - } - - return cmSystemTools::ForceToRelativePath(local_path, remote_path); -} - static bool cmOutputConverterIsShellOperator(const std::string& str) { static std::set<std::string> shellOperators; diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h index 5a4f879..6438c7b 100644 --- a/Source/cmOutputConverter.h +++ b/Source/cmOutputConverter.h @@ -91,16 +91,6 @@ public: }; static FortranFormat GetFortranFormat(const char* value); - /** - * Convert the given remote path to a relative path with respect to - * the given local path. Both paths must use forward slashes and not - * already be escaped or quoted. - * The conversion is skipped if the paths are not both in the source - * or both in the binary tree. - */ - std::string ConvertToRelativePath(std::string const& local_path, - std::string const& remote_path) const; - private: cmState* GetState() const; diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index 40f694c..6752743 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -155,6 +155,15 @@ bool cmStateDirectory::ContainsBoth(std::string const& local_path, return bothInBinary || bothInSource; } +std::string cmStateDirectory::ConvertToRelPathIfNotContained( + std::string const& local_path, std::string const& remote_path) const +{ + if (!this->ContainsBoth(local_path, remote_path)) { + return remote_path; + } + return cmSystemTools::ForceToRelativePath(local_path, remote_path); +} + cmStateDirectory::cmStateDirectory( cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator iter, const cmStateSnapshot& snapshot) diff --git a/Source/cmStateDirectory.h b/Source/cmStateDirectory.h index c4b18ad..6956594 100644 --- a/Source/cmStateDirectory.h +++ b/Source/cmStateDirectory.h @@ -35,6 +35,9 @@ public: bool ContainsBoth(std::string const& local_path, std::string const& remote_path) const; + std::string ConvertToRelPathIfNotContained( + std::string const& local_path, std::string const& remote_path) const; + cmStringRange GetIncludeDirectoriesEntries() const; cmBacktraceRange GetIncludeDirectoriesEntryBacktraces() const; void AppendIncludeDirectoriesEntry(std::string const& vec, diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index fe48934..93cdd46 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -19,7 +19,6 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmMessenger.h" -#include "cmOutputConverter.h" #include "cmProperty.h" #include "cmSourceFile.h" #include "cmSourceFileLocation.h" @@ -747,11 +746,12 @@ void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const const char* sigString = (sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain"); s << "The uses of the " << sigString << " signature are here:\n"; - cmOutputConverter converter(this->GetMakefile()->GetStateSnapshot()); + cmStateDirectory cmDir = + this->GetMakefile()->GetStateSnapshot().GetDirectory(); for (auto const& cmd : this->TLLCommands) { if (cmd.first == sig) { cmListFileContext lfc = cmd.second; - lfc.FilePath = converter.ConvertToRelativePath( + lfc.FilePath = cmDir.ConvertToRelPathIfNotContained( this->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath); s << " * " << lfc << std::endl; } diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index ac4a4f5..9d7dd07 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3584,8 +3584,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions( this->LocalGenerator->GetCurrentBinaryDirectory(); for (cmComputeLinkInformation::Item const& l : libs) { if (l.IsPath && cmVS10IsTargetsFile(l.Value)) { - std::string path = - this->LocalGenerator->ConvertToRelativePath(currentBinDir, l.Value); + std::string path = this->LocalGenerator->MaybeConvertToRelativePath( + currentBinDir, l.Value); ConvertToWindowsSlash(path); this->AddTargetsFileAndConfigPair(path, config); } @@ -3668,8 +3668,8 @@ void cmVisualStudio10TargetGenerator::AddLibraries( } if (l.IsPath) { - std::string path = - this->LocalGenerator->ConvertToRelativePath(currentBinDir, l.Value); + std::string path = this->LocalGenerator->MaybeConvertToRelativePath( + currentBinDir, l.Value); ConvertToWindowsSlash(path); if (cmVS10IsTargetsFile(l.Value)) { vsTargetVec.push_back(path); |