Commit 60c06620 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'cmoutputconverter-simplify'

b6a957c9

 cmOutputConverter: move ConvertToRelativePath to cmStateDirectory.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !2831
parents 90ac5e63 b6a957c9
......@@ -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));
......
......@@ -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;
}
......
......@@ -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();
......
......@@ -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;
......
......@@ -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"
......@@ -2794,8 +2793,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.
......
......@@ -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 {
......
......@@ -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(), '/', '\\');
......
......@@ -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 += "/CMakeFiles";
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));
}
......
......@@ -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
}
......
......@@ -3581,7 +3581,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);
}
......
......@@ -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";
......
......@@ -46,7 +46,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 =
......
......@@ -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;
}
......@@ -2321,7 +2321,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;
......@@ -2578,15 +2578,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] != '.';
......@@ -2685,6 +2685,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
{
......
......@@ -325,6 +325,16 @@ public:
std::string const& GetCurrentBinaryDirectory() const;
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.
*/
......
......@@ -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();
......@@ -139,7 +139,8 @@ std::string cmLocalNinjaGenerator::ConvertToIncludeReference(
format);
}
return this->ConvertToOutputFormat(
this->ConvertToRelativePath(this->GetBinaryDirectory(), path), format);
this->MaybeConvertToRelativePath(this->GetBinaryDirectory(), path),
format);
}
// Private methods.
......@@ -582,8 +583,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);
}
......
......@@ -2079,12 +2079,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);
}
......@@ -184,9 +184,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();
......
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment