Simplify absolute path conversions using CollapseFullPath full signature

This commit is contained in:
Brad King 2020-03-18 14:22:11 -04:00
parent 12b39aef75
commit 25f48761fa
7 changed files with 19 additions and 51 deletions

View File

@ -2327,12 +2327,9 @@ bool HandleLockCommand(std::vector<std::string> const& args,
path += "/cmake.lock"; path += "/cmake.lock";
} }
if (!cmsys::SystemTools::FileIsFullPath(path)) {
path = status.GetMakefile().GetCurrentSourceDirectory() + "/" + path;
}
// Unify path (remove '//', '/../', ...) // Unify path (remove '//', '/../', ...)
path = cmSystemTools::CollapseFullPath(path); path = cmSystemTools::CollapseFullPath(
path, status.GetMakefile().GetCurrentSourceDirectory());
// Create file and directories if needed // Create file and directories if needed
std::string parentDir = cmSystemTools::GetParentDirectory(path); std::string parentDir = cmSystemTools::GetParentDirectory(path);

View File

@ -7,7 +7,6 @@
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h" #include "cmMessageType.h"
#include "cmPolicies.h" #include "cmPolicies.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
namespace { namespace {
@ -37,14 +36,8 @@ bool cmGetDirectoryPropertyCommand(std::vector<std::string> const& args,
"DIRECTORY argument provided without subsequent arguments"); "DIRECTORY argument provided without subsequent arguments");
return false; return false;
} }
std::string sd = *i; std::string sd = cmSystemTools::CollapseFullPath(
// make sure the start dir is a full path *i, status.GetMakefile().GetCurrentSourceDirectory());
if (!cmSystemTools::FileIsFullPath(sd)) {
sd = cmStrCat(status.GetMakefile().GetCurrentSourceDirectory(), '/', *i);
}
// The local generators are associated with collapsed paths.
sd = cmSystemTools::CollapseFullPath(sd);
// lookup the makefile from the directory name // lookup the makefile from the directory name
dir = status.GetMakefile().GetGlobalGenerator()->FindMakefile(sd); dir = status.GetMakefile().GetGlobalGenerator()->FindMakefile(sd);

View File

@ -256,14 +256,8 @@ bool HandleDirectoryMode(cmExecutionStatus& status, const std::string& name,
if (!name.empty()) { if (!name.empty()) {
// Construct the directory name. Interpret relative paths with // Construct the directory name. Interpret relative paths with
// respect to the current directory. // respect to the current directory.
std::string dir = name; std::string dir = cmSystemTools::CollapseFullPath(
if (!cmSystemTools::FileIsFullPath(dir)) { name, status.GetMakefile().GetCurrentSourceDirectory());
dir =
cmStrCat(status.GetMakefile().GetCurrentSourceDirectory(), '/', name);
}
// The local generators are associated with collapsed paths.
dir = cmSystemTools::CollapseFullPath(dir);
// Lookup the generator. // Lookup the generator.
mf = status.GetMakefile().GetGlobalGenerator()->FindMakefile(dir); mf = status.GetMakefile().GetGlobalGenerator()->FindMakefile(dir);

View File

@ -144,7 +144,8 @@ std::string cmLocalNinjaGenerator::ConvertToIncludeReference(
bool forceFullPaths) bool forceFullPaths)
{ {
if (forceFullPaths) { if (forceFullPaths) {
return this->ConvertToOutputFormat(cmSystemTools::CollapseFullPath(path), return this->ConvertToOutputFormat(
cmSystemTools::CollapseFullPath(path, this->GetCurrentBinaryDirectory()),
format); format);
} }
return this->ConvertToOutputFormat( return this->ConvertToOutputFormat(

View File

@ -1245,8 +1245,10 @@ void cmMakefileTargetGenerator::GenerateCustomRuleFile(
// Setup implicit dependency scanning. // Setup implicit dependency scanning.
for (auto const& idi : ccg.GetCC().GetImplicitDepends()) { for (auto const& idi : ccg.GetCC().GetImplicitDepends()) {
std::string objFullPath = cmSystemTools::CollapseFullPath(outputs[0]); std::string objFullPath = cmSystemTools::CollapseFullPath(
std::string srcFullPath = cmSystemTools::CollapseFullPath(idi.second); outputs[0], this->LocalGenerator->GetCurrentBinaryDirectory());
std::string srcFullPath = cmSystemTools::CollapseFullPath(
idi.second, this->LocalGenerator->GetCurrentBinaryDirectory());
this->LocalGenerator->AddImplicitDepends(this->GeneratorTarget, idi.first, this->LocalGenerator->AddImplicitDepends(this->GeneratorTarget, idi.first,
objFullPath, srcFullPath); objFullPath, srcFullPath);
} }

View File

@ -235,14 +235,8 @@ bool HandleDirectoryMode(cmExecutionStatus& status,
if (!names.empty()) { if (!names.empty()) {
// Construct the directory name. Interpret relative paths with // Construct the directory name. Interpret relative paths with
// respect to the current directory. // respect to the current directory.
std::string dir = *names.begin(); std::string dir = cmSystemTools::CollapseFullPath(
if (!cmSystemTools::FileIsFullPath(dir)) { *names.begin(), status.GetMakefile().GetCurrentSourceDirectory());
dir = cmStrCat(status.GetMakefile().GetCurrentSourceDirectory(), '/',
*names.begin());
}
// The local generators are associated with collapsed paths.
dir = cmSystemTools::CollapseFullPath(dir);
mf = status.GetMakefile().GetGlobalGenerator()->FindMakefile(dir); mf = status.GetMakefile().GetGlobalGenerator()->FindMakefile(dir);
if (!mf) { if (!mf) {

View File

@ -30,18 +30,6 @@ std::vector<std::string> tokenizePath(const std::string& path)
return cmTokenize(path, "\\/"); return cmTokenize(path, "\\/");
} }
std::string getFullFilePath(const std::string& currentPath,
const std::string& path)
{
std::string fullPath = path;
if (!cmSystemTools::FileIsFullPath(path)) {
fullPath = cmStrCat(currentPath, '/', path);
}
return cmSystemTools::CollapseFullPath(fullPath);
}
std::set<std::string> getSourceGroupFilesPaths( std::set<std::string> getSourceGroupFilesPaths(
const std::string& root, const std::vector<std::string>& files) const std::string& root, const std::vector<std::string>& files)
{ {
@ -124,7 +112,8 @@ bool addFilesToItsSourceGroups(const std::string& root,
errorMsg = "Could not create source group for file: " + sgFilesPath; errorMsg = "Could not create source group for file: " + sgFilesPath;
return false; return false;
} }
const std::string fullPath = getFullFilePath(root, sgFilesPath); const std::string fullPath =
cmSystemTools::CollapseFullPath(sgFilesPath, root);
sg->AddGroupFile(fullPath); sg->AddGroupFile(fullPath);
} }
} }
@ -255,10 +244,8 @@ bool cmSourceGroupCommand(std::vector<std::string> const& args,
parsedArguments[kFilesOptionName]; parsedArguments[kFilesOptionName];
for (auto const& filesArg : filesArguments) { for (auto const& filesArg : filesArguments) {
std::string src = filesArg; std::string src = filesArg;
if (!cmSystemTools::FileIsFullPath(src)) { src =
src = cmStrCat(mf.GetCurrentSourceDirectory(), '/', filesArg); cmSystemTools::CollapseFullPath(src, mf.GetCurrentSourceDirectory());
}
src = cmSystemTools::CollapseFullPath(src);
sg->AddGroupFile(src); sg->AddGroupFile(src);
} }
} }