Merge topic 'output-converter'

8ddbd4c2 cmOutputConverter: remove unnecessary conversion
bdaadbdc cmOutputConverter: collapse ConvertToOutputForExisting functions
191fc3a0 cmOutputConverter: remove unused 'local' argument
b86007e3 cmOutputConverter: remove 'optional' argument
cde127b0 cmOutputConverter::Convert: invert condition
c23f89bc cmOutputConverter::Convert: make precondition explicit
This commit is contained in:
Brad King 2016-06-21 13:57:16 -04:00 committed by CMake Topic Stage
commit 8380f47cc9
4 changed files with 31 additions and 48 deletions

View File

@ -832,8 +832,8 @@ void cmLocalGenerator::InsertRuleLauncher(std::string& s,
std::string cmLocalGenerator::ConvertToIncludeReference(
std::string const& path, OutputFormat format, bool forceFullPaths)
{
return this->ConvertToOutputForExisting(
path, forceFullPaths ? FULL : START_OUTPUT, format);
static_cast<void>(forceFullPaths);
return this->ConvertToOutputForExisting(path, format);
}
std::string cmLocalGenerator::GetIncludeFlags(
@ -1503,7 +1503,7 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
for (std::vector<std::string>::const_iterator libDir = libDirs.begin();
libDir != libDirs.end(); ++libDir) {
std::string libpath =
this->ConvertToOutputForExisting(*libDir, START_OUTPUT, shellFormat);
this->ConvertToOutputForExisting(*libDir, shellFormat);
linkPath += " " + libPathFlag;
linkPath += libpath;
linkPath += libPathTerminator;

View File

@ -2068,19 +2068,18 @@ void cmLocalUnixMakefileGenerator3::CreateCDCommand(
// back because the shell keeps the working directory between
// commands.
std::string cmd = cd_cmd;
cmd += this->ConvertToOutputForExisting(tgtDir, relRetDir);
cmd += this->ConvertToOutputForExisting(tgtDir);
commands.insert(commands.begin(), cmd);
// Change back to the starting directory.
cmd = cd_cmd;
cmd += this->ConvertToOutputForExisting(relRetDir, tgtDir);
cmd += this->ConvertToOutputForExisting(relRetDir);
commands.push_back(cmd);
} else {
// On UNIX we must construct a single shell command to change
// directory and build because make resets the directory between
// each command.
std::string outputForExisting =
this->ConvertToOutputForExisting(tgtDir, relRetDir);
std::string outputForExisting = this->ConvertToOutputForExisting(tgtDir);
std::string prefix = cd_cmd + outputForExisting + " && ";
std::transform(commands.begin(), commands.end(), commands.begin(),
std::bind1st(std::plus<std::string>(), prefix));

View File

@ -27,14 +27,14 @@ cmOutputConverter::cmOutputConverter(cmState::Snapshot snapshot)
assert(this->StateSnapshot.IsValid());
}
std::string cmOutputConverter::ConvertToOutputForExistingCommon(
const std::string& remote, std::string const& result,
OutputFormat format) const
std::string cmOutputConverter::ConvertToOutputForExisting(
const std::string& remote, OutputFormat format) const
{
// If this is a windows shell, the result has a space, and the path
// already exists, we can use a short-path to reference it without a
// space.
if (this->GetState()->UseWindowsShell() && result.find(' ') != result.npos &&
if (this->GetState()->UseWindowsShell() &&
remote.find(' ') != std::string::npos &&
cmSystemTools::FileExists(remote.c_str())) {
std::string tmp;
if (cmSystemTools::GetShortPath(remote, tmp)) {
@ -42,31 +42,21 @@ std::string cmOutputConverter::ConvertToOutputForExistingCommon(
}
}
// Otherwise, leave it unchanged.
return result;
// Otherwise, perform standard conversion.
return this->ConvertToOutputFormat(remote, format);
}
std::string cmOutputConverter::ConvertToOutputForExisting(
const std::string& remote, RelativeRoot local, OutputFormat format) const
RelativeRoot remote, OutputFormat format) const
{
static_cast<void>(local);
// The relative root must have a path (i.e. not FULL or NONE)
assert(remote != FULL);
assert(remote != NONE);
// Perform standard conversion.
std::string result = this->ConvertToOutputFormat(remote, format);
// Consider short-path.
return this->ConvertToOutputForExistingCommon(remote, result, format);
}
std::string cmOutputConverter::ConvertToOutputForExisting(
RelativeRoot remote, const std::string& local, OutputFormat format) const
{
// Perform standard conversion.
std::string result = this->Convert(remote, local, format, true);
// Consider short-path.
const char* remotePath = this->GetRelativeRootPath(remote);
return this->ConvertToOutputForExistingCommon(remotePath, result, format);
assert(remotePath != 0);
return this->ConvertToOutputForExisting(remotePath, format);
}
const char* cmOutputConverter::GetRelativeRootPath(RelativeRoot relroot) const
@ -158,22 +148,23 @@ std::string cmOutputConverter::ConvertDirectorySeparatorsForShell(
std::string cmOutputConverter::Convert(RelativeRoot remote,
const std::string& local,
OutputFormat output,
bool optional) const
OutputFormat output) const
{
const char* remotePath = this->GetRelativeRootPath(remote);
// The relative root must have a path (i.e. not FULL or NONE)
assert(remote != FULL);
assert(remote != NONE);
const char* remotePath = this->GetRelativeRootPath(remote);
assert(remotePath != 0);
if (!local.empty() && !optional) {
std::vector<std::string> components;
cmSystemTools::SplitPath(local, components);
std::string result = this->ConvertToRelativePath(components, remotePath);
return this->ConvertToOutputFormat(result, output);
if (local.empty()) {
return this->ConvertToOutputFormat(remotePath, output);
}
return this->ConvertToOutputFormat(remotePath, output);
std::vector<std::string> components;
cmSystemTools::SplitPath(local, components);
std::string result = this->ConvertToRelativePath(components, remotePath);
return this->ConvertToOutputFormat(result, output);
}
static bool cmOutputConverterNotAbove(const char* a, const char* b)

View File

@ -58,8 +58,7 @@ public:
std::string Convert(const std::string& remote, RelativeRoot local,
OutputFormat output = UNCHANGED) const;
std::string Convert(RelativeRoot remote, const std::string& local,
OutputFormat output = UNCHANGED,
bool optional = false) const;
OutputFormat output = UNCHANGED) const;
std::string ConvertDirectorySeparatorsForShell(
const std::string& source) const;
@ -70,13 +69,11 @@ public:
///! for existing files convert to output path and short path if spaces
std::string ConvertToOutputForExisting(const std::string& remote,
RelativeRoot local = START_OUTPUT,
OutputFormat format = SHELL) const;
/** For existing path identified by RelativeRoot convert to output
path and short path if spaces. */
std::string ConvertToOutputForExisting(RelativeRoot remote,
const std::string& local = "",
OutputFormat format = SHELL) const;
void SetLinkScriptShell(bool linkScriptShell);
@ -162,10 +159,6 @@ public:
private:
cmState* GetState() const;
std::string ConvertToOutputForExistingCommon(const std::string& remote,
std::string const& result,
OutputFormat format) const;
static int Shell__CharIsWhitespace(char c);
static int Shell__CharNeedsQuotesOnUnix(char c);
static int Shell__CharNeedsQuotesOnWindows(char c);