Convert: Replace trivial conversion with new method

This commit is contained in:
Stephen Kelly 2016-08-27 13:44:56 +02:00
parent 08be47cf93
commit 563ac22a16
13 changed files with 57 additions and 36 deletions

View File

@ -238,8 +238,8 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
// written by the original local generator for this directory // written by the original local generator for this directory
// convert the dependencies to paths relative to the home output // convert the dependencies to paths relative to the home output
// directory. We must do the same here. // directory. We must do the same here.
std::string obj_i = std::string obj_i = this->LocalGenerator->ConvertToRelativePath(
this->LocalGenerator->Convert(obj, cmOutputConverter::HOME_OUTPUT); obj, cmOutputConverter::HOME_OUTPUT);
std::string obj_m = this->LocalGenerator->ConvertToOutputFormat( std::string obj_m = this->LocalGenerator->ConvertToOutputFormat(
obj_i, cmOutputConverter::MAKERULE); obj_i, cmOutputConverter::MAKERULE);
internalDepends << obj_i << std::endl; internalDepends << obj_i << std::endl;

View File

@ -193,15 +193,15 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
stamp += ".mod.stamp"; stamp += ".mod.stamp";
fcStream << "\n"; fcStream << "\n";
fcStream << " \"" fcStream << " \""
<< this->LocalGenerator->Convert( << this->LocalGenerator->ConvertToRelativePath(
mod_lower, cmOutputConverter::START_OUTPUT) mod_lower, cmOutputConverter::START_OUTPUT)
<< "\"\n"; << "\"\n";
fcStream << " \"" fcStream << " \""
<< this->LocalGenerator->Convert( << this->LocalGenerator->ConvertToRelativePath(
mod_upper, cmOutputConverter::START_OUTPUT) mod_upper, cmOutputConverter::START_OUTPUT)
<< "\"\n"; << "\"\n";
fcStream << " \"" fcStream << " \""
<< this->LocalGenerator->Convert( << this->LocalGenerator->ConvertToRelativePath(
stamp, cmOutputConverter::START_OUTPUT) stamp, cmOutputConverter::START_OUTPUT)
<< "\"\n"; << "\"\n";
} }
@ -317,8 +317,8 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj,
const char* src = info.Source.c_str(); const char* src = info.Source.c_str();
// Write the include dependencies to the output stream. // Write the include dependencies to the output stream.
std::string obj_i = std::string obj_i = this->LocalGenerator->ConvertToRelativePath(
this->LocalGenerator->Convert(obj, cmOutputConverter::HOME_OUTPUT); obj, cmOutputConverter::HOME_OUTPUT);
std::string obj_m = this->LocalGenerator->ConvertToOutputFormat( std::string obj_m = this->LocalGenerator->ConvertToOutputFormat(
obj_i, cmOutputConverter::MAKERULE); obj_i, cmOutputConverter::MAKERULE);
internalDepends << obj_i << std::endl; internalDepends << obj_i << std::endl;

View File

@ -904,8 +904,8 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) { it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) {
const std::vector<cmGeneratorTarget*> targets = const std::vector<cmGeneratorTarget*> targets =
(*it)->GetGeneratorTargets(); (*it)->GetGeneratorTargets();
std::string subdir = (*it)->Convert((*it)->GetCurrentBinaryDirectory(), std::string subdir = (*it)->ConvertToRelativePath(
cmOutputConverter::HOME_OUTPUT); (*it)->GetCurrentBinaryDirectory(), cmOutputConverter::HOME_OUTPUT);
if (subdir == ".") { if (subdir == ".") {
subdir = ""; subdir = "";
} }

View File

@ -2547,8 +2547,8 @@ void cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
// Shorten the output name (in expected use case). // Shorten the output name (in expected use case).
cmOutputConverter converter(this->GetMakefiles()[0]->GetStateSnapshot()); cmOutputConverter converter(this->GetMakefiles()[0]->GetStateSnapshot());
std::string fname = std::string fname = converter.ConvertToRelativePath(
converter.Convert(outputs[0], cmOutputConverter::HOME_OUTPUT); outputs[0], cmOutputConverter::HOME_OUTPUT);
// Associate the hash with this output. // Associate the hash with this output.
this->RuleHashes[fname] = hash; this->RuleHashes[fname] = hash;

View File

@ -747,7 +747,8 @@ std::string cmGlobalNinjaGenerator::ConvertToNinjaPath(const std::string& path)
{ {
cmLocalNinjaGenerator* ng = cmLocalNinjaGenerator* ng =
static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]); static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]);
std::string convPath = ng->Convert(path, cmOutputConverter::HOME_OUTPUT); std::string convPath =
ng->ConvertToRelativePath(path, cmOutputConverter::HOME_OUTPUT);
convPath = this->NinjaOutputPath(convPath); convPath = this->NinjaOutputPath(convPath);
#ifdef _WIN32 #ifdef _WIN32
std::replace(convPath.begin(), convPath.end(), '/', '\\'); std::replace(convPath.begin(), convPath.end(), '/', '\\');
@ -760,7 +761,8 @@ std::string cmGlobalNinjaGenerator::ConvertToNinjaFolderRule(
{ {
cmLocalNinjaGenerator* ng = cmLocalNinjaGenerator* ng =
static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]); static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]);
std::string convPath = ng->Convert(path + "/all", cmOutputConverter::HOME); std::string convPath =
ng->ConvertToRelativePath(path + "/all", cmOutputConverter::HOME);
convPath = this->NinjaOutputPath(convPath); convPath = this->NinjaOutputPath(convPath);
#ifdef _WIN32 #ifdef _WIN32
std::replace(convPath.begin(), convPath.end(), '/', '\\'); std::replace(convPath.begin(), convPath.end(), '/', '\\');

View File

@ -311,11 +311,14 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
cmakefileStream cmakefileStream
<< "# The top level Makefile was generated from the following files:\n" << "# The top level Makefile was generated from the following files:\n"
<< "set(CMAKE_MAKEFILE_DEPENDS\n" << "set(CMAKE_MAKEFILE_DEPENDS\n"
<< " \"" << lg->Convert(cache, cmOutputConverter::START_OUTPUT) << "\"\n"; << " \""
<< lg->ConvertToRelativePath(cache, cmOutputConverter::START_OUTPUT)
<< "\"\n";
for (std::vector<std::string>::const_iterator i = lfiles.begin(); for (std::vector<std::string>::const_iterator i = lfiles.begin();
i != lfiles.end(); ++i) { i != lfiles.end(); ++i) {
cmakefileStream << " \"" cmakefileStream << " \""
<< lg->Convert(*i, cmOutputConverter::START_OUTPUT) << lg->ConvertToRelativePath(
*i, cmOutputConverter::START_OUTPUT)
<< "\"\n"; << "\"\n";
} }
cmakefileStream << " )\n\n"; cmakefileStream << " )\n\n";
@ -329,10 +332,12 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
cmakefileStream << "# The corresponding makefile is:\n" cmakefileStream << "# The corresponding makefile is:\n"
<< "set(CMAKE_MAKEFILE_OUTPUTS\n" << "set(CMAKE_MAKEFILE_OUTPUTS\n"
<< " \"" << " \""
<< lg->Convert(makefileName, cmOutputConverter::START_OUTPUT) << lg->ConvertToRelativePath(makefileName,
cmOutputConverter::START_OUTPUT)
<< "\"\n" << "\"\n"
<< " \"" << " \""
<< lg->Convert(check, cmOutputConverter::START_OUTPUT) << lg->ConvertToRelativePath(check,
cmOutputConverter::START_OUTPUT)
<< "\"\n"; << "\"\n";
cmakefileStream << " )\n\n"; cmakefileStream << " )\n\n";
@ -345,7 +350,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
for (std::vector<std::string>::const_iterator k = outfiles.begin(); for (std::vector<std::string>::const_iterator k = outfiles.begin();
k != outfiles.end(); ++k) { k != outfiles.end(); ++k) {
cmakefileStream << " \"" cmakefileStream << " \""
<< lg->Convert(*k, cmOutputConverter::HOME_OUTPUT) << lg->ConvertToRelativePath(
*k, cmOutputConverter::HOME_OUTPUT)
<< "\"\n"; << "\"\n";
} }
@ -358,7 +364,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
tmpStr += cmake::GetCMakeFilesDirectory(); tmpStr += cmake::GetCMakeFilesDirectory();
tmpStr += "/CMakeDirectoryInformation.cmake"; tmpStr += "/CMakeDirectoryInformation.cmake";
cmakefileStream << " \"" cmakefileStream << " \""
<< lg->Convert(tmpStr, cmOutputConverter::HOME_OUTPUT) << lg->ConvertToRelativePath(
tmpStr, cmOutputConverter::HOME_OUTPUT)
<< "\"\n"; << "\"\n";
} }
cmakefileStream << " )\n\n"; cmakefileStream << " )\n\n";
@ -519,7 +526,7 @@ void cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
tname += "/fast"; tname += "/fast";
} }
cmOutputConverter conv(mf->GetStateSnapshot()); cmOutputConverter conv(mf->GetStateSnapshot());
tname = conv.Convert(tname, cmOutputConverter::HOME_OUTPUT); tname = conv.ConvertToRelativePath(tname, cmOutputConverter::HOME_OUTPUT);
cmSystemTools::ConvertToOutputSlashes(tname); cmSystemTools::ConvertToOutputSlashes(tname);
makeCommand.push_back(tname); makeCommand.push_back(tname);
if (this->Makefiles.empty()) { if (this->Makefiles.empty()) {

View File

@ -385,7 +385,8 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
if (vcprojName) { if (vcprojName) {
cmLocalGenerator* lg = target->GetLocalGenerator(); cmLocalGenerator* lg = target->GetLocalGenerator();
std::string dir = lg->GetCurrentBinaryDirectory(); std::string dir = lg->GetCurrentBinaryDirectory();
dir = root->Convert(dir.c_str(), cmOutputConverter::START_OUTPUT); dir = root->ConvertToRelativePath(dir.c_str(),
cmOutputConverter::START_OUTPUT);
if (dir == ".") { if (dir == ".") {
dir = ""; // msbuild cannot handle ".\" prefix dir = ""; // msbuild cannot handle ".\" prefix
} }

View File

@ -402,7 +402,8 @@ void cmListFileBacktrace::PrintTitle(std::ostream& out) const
cmOutputConverter converter(this->Bottom); cmOutputConverter converter(this->Bottom);
cmListFileContext lfc = *this->Cur; cmListFileContext lfc = *this->Cur;
if (!this->Bottom.GetState()->GetIsInTryCompile()) { if (!this->Bottom.GetState()->GetIsInTryCompile()) {
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); lfc.FilePath =
converter.ConvertToRelativePath(lfc.FilePath, cmOutputConverter::HOME);
} }
out << (lfc.Line ? " at " : " in ") << lfc; out << (lfc.Line ? " at " : " in ") << lfc;
} }
@ -427,7 +428,8 @@ void cmListFileBacktrace::PrintCallStack(std::ostream& out) const
} }
cmListFileContext lfc = *i; cmListFileContext lfc = *i;
if (!this->Bottom.GetState()->GetIsInTryCompile()) { if (!this->Bottom.GetState()->GetIsInTryCompile()) {
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); lfc.FilePath =
converter.ConvertToRelativePath(lfc.FilePath, cmOutputConverter::HOME);
} }
out << " " << lfc << "\n"; out << " " << lfc << "\n";
} }

View File

@ -176,7 +176,7 @@ void cmLocalGenerator::GenerateTestFiles()
// TODO: Use add_subdirectory instead? // TODO: Use add_subdirectory instead?
fout << "subdirs("; fout << "subdirs(";
std::string outP = children[i].GetDirectory().GetCurrentBinary(); std::string outP = children[i].GetDirectory().GetCurrentBinary();
fout << this->Convert(outP, START_OUTPUT); fout << this->ConvertToRelativePath(outP, START_OUTPUT);
fout << ")" << std::endl; fout << ")" << std::endl;
} }
} }
@ -2237,7 +2237,8 @@ std::string cmLocalGenerator::ConstructComment(
for (std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin(); for (std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin();
o != ccg.GetOutputs().end(); ++o) { o != ccg.GetOutputs().end(); ++o) {
comment += sep; comment += sep;
comment += this->Convert(*o, cmOutputConverter::START_OUTPUT); comment +=
this->ConvertToRelativePath(*o, cmOutputConverter::START_OUTPUT);
sep = ", "; sep = ", ";
} }
return comment; return comment;
@ -2505,13 +2506,14 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
const char* fullPath = source.GetFullPath().c_str(); const char* fullPath = source.GetFullPath().c_str();
// Try referencing the source relative to the source tree. // Try referencing the source relative to the source tree.
std::string relFromSource = this->Convert(fullPath, START); std::string relFromSource = this->ConvertToRelativePath(fullPath, START);
assert(!relFromSource.empty()); assert(!relFromSource.empty());
bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str()); bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
bool subSource = relSource && relFromSource[0] != '.'; bool subSource = relSource && relFromSource[0] != '.';
// Try referencing the source relative to the binary tree. // Try referencing the source relative to the binary tree.
std::string relFromBinary = this->Convert(fullPath, START_OUTPUT); std::string relFromBinary =
this->ConvertToRelativePath(fullPath, START_OUTPUT);
assert(!relFromBinary.empty()); assert(!relFromBinary.empty());
bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str()); bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
bool subBinary = relBinary && relFromBinary[0] != '.'; bool subBinary = relBinary && relFromBinary[0] != '.';

View File

@ -41,7 +41,7 @@ void cmLocalNinjaGenerator::Generate()
{ {
// Compute the path to use when referencing the current output // Compute the path to use when referencing the current output
// directory from the top output directory. // directory from the top output directory.
this->HomeRelativeOutputPath = this->Convert( this->HomeRelativeOutputPath = this->ConvertToRelativePath(
this->GetCurrentBinaryDirectory(), cmOutputConverter::HOME_OUTPUT); this->GetCurrentBinaryDirectory(), cmOutputConverter::HOME_OUTPUT);
if (this->HomeRelativeOutputPath == ".") { if (this->HomeRelativeOutputPath == ".") {
this->HomeRelativeOutputPath = ""; this->HomeRelativeOutputPath = "";

View File

@ -140,7 +140,7 @@ void cmLocalUnixMakefileGenerator3::ComputeHomeRelativeOutputPath()
{ {
// Compute the path to use when referencing the current output // Compute the path to use when referencing the current output
// directory from the top output directory. // directory from the top output directory.
this->HomeRelativeOutputPath = this->Convert( this->HomeRelativeOutputPath = this->ConvertToRelativePath(
this->GetCurrentBinaryDirectory(), cmOutputConverter::HOME_OUTPUT); this->GetCurrentBinaryDirectory(), cmOutputConverter::HOME_OUTPUT);
if (this->HomeRelativeOutputPath == ".") { if (this->HomeRelativeOutputPath == ".") {
this->HomeRelativeOutputPath = ""; this->HomeRelativeOutputPath = "";
@ -966,7 +966,8 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
// working directory will be the start-output directory. // working directory will be the start-output directory.
bool had_slash = cmd.find('/') != cmd.npos; bool had_slash = cmd.find('/') != cmd.npos;
if (workingDir.empty()) { if (workingDir.empty()) {
cmd = this->Convert(cmd, cmOutputConverter::START_OUTPUT); cmd =
this->ConvertToRelativePath(cmd, cmOutputConverter::START_OUTPUT);
} }
bool has_slash = cmd.find('/') != cmd.npos; bool has_slash = cmd.find('/') != cmd.npos;
if (had_slash && !has_slash) { if (had_slash && !has_slash) {
@ -1851,7 +1852,8 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
for (std::vector<std::string>::iterator i = includes.begin(); for (std::vector<std::string>::iterator i = includes.begin();
i != includes.end(); ++i) { i != includes.end(); ++i) {
cmakefileStream << " \"" cmakefileStream << " \""
<< this->Convert(*i, cmOutputConverter::HOME_OUTPUT) << this->ConvertToRelativePath(
*i, cmOutputConverter::HOME_OUTPUT)
<< "\"\n"; << "\"\n";
} }
cmakefileStream << " )\n"; cmakefileStream << " )\n";
@ -1915,7 +1917,8 @@ std::string cmLocalUnixMakefileGenerator3::GetRecursiveMakeCall(
// Add the target. // Add the target.
if (!tgt.empty()) { if (!tgt.empty()) {
// The make target is always relative to the top of the build tree. // The make target is always relative to the top of the build tree.
std::string tgt2 = this->Convert(tgt, cmOutputConverter::HOME_OUTPUT); std::string tgt2 =
this->ConvertToRelativePath(tgt, cmOutputConverter::HOME_OUTPUT);
// The target may have been written with windows paths. // The target may have been written with windows paths.
cmSystemTools::ConvertToOutputSlashes(tgt2); cmSystemTools::ConvertToOutputSlashes(tgt2);

View File

@ -312,8 +312,10 @@ void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()(
output += "/"; output += "/";
output += cmSystemTools::GetFilenameName(input); output += cmSystemTools::GetFilenameName(input);
this->Generator->CleanFiles.push_back( this->Generator->CleanFiles.push_back(
this->Generator->Convert(output, cmOutputConverter::START_OUTPUT)); this->Generator->LocalGenerator->ConvertToRelativePath(
output = this->Generator->Convert(output, cmOutputConverter::HOME_OUTPUT); output, cmOutputConverter::START_OUTPUT));
output = this->Generator->LocalGenerator->ConvertToRelativePath(
output, cmOutputConverter::HOME_OUTPUT);
// Create a rule to copy the content into the bundle. // Create a rule to copy the content into the bundle.
std::vector<std::string> depends; std::vector<std::string> depends;
@ -1171,7 +1173,8 @@ void cmMakefileTargetGenerator::WriteObjectsVariable(
for (std::vector<std::string>::const_iterator i = for (std::vector<std::string>::const_iterator i =
this->ExternalObjects.begin(); this->ExternalObjects.begin();
i != this->ExternalObjects.end(); ++i) { i != this->ExternalObjects.end(); ++i) {
object = this->Convert(*i, cmOutputConverter::START_OUTPUT); object = this->LocalGenerator->ConvertToRelativePath(
*i, cmOutputConverter::START_OUTPUT);
*this->BuildFileStream << " " << lineContinue << "\n" *this->BuildFileStream << " " << lineContinue << "\n"
<< this->Makefile->GetSafeDefinition( << this->Makefile->GetSafeDefinition(
"CMAKE_OBJECT_NAME"); "CMAKE_OBJECT_NAME");

View File

@ -602,7 +602,8 @@ void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const
it != this->TLLCommands.end(); ++it) { it != this->TLLCommands.end(); ++it) {
if (it->first == sig) { if (it->first == sig) {
cmListFileContext lfc = it->second; cmListFileContext lfc = it->second;
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); lfc.FilePath =
converter.ConvertToRelativePath(lfc.FilePath, cmOutputConverter::HOME);
s << " * " << lfc << std::endl; s << " * " << lfc << std::endl;
} }
} }