Merge topic 'cleanup-Convert'

6afd35b9 cmState: remove unused code
8d47a20f cmOutputConverter: use new ConvertToRelativePath signature internally
149af87b cmOutputConverter: split ConvertToRelativePath
This commit is contained in:
Brad King 2016-09-19 08:55:27 -04:00 committed by CMake Topic Stage
commit 419ad05101
4 changed files with 73 additions and 75 deletions

View File

@ -54,21 +54,19 @@ std::string cmOutputConverter::ConvertToRelativePath(
switch (relative) { switch (relative) {
case HOME: case HOME:
result = this->ConvertToRelativePath( result = this->ConvertToRelativePath(
this->GetState()->GetSourceDirectoryComponents(), source); this->GetState()->GetSourceDirectory(), source);
break; break;
case START: case START:
result = this->ConvertToRelativePath( result = this->ConvertToRelativePath(
this->StateSnapshot.GetDirectory().GetCurrentSourceComponents(), this->StateSnapshot.GetDirectory().GetCurrentSource(), source);
source);
break; break;
case HOME_OUTPUT: case HOME_OUTPUT:
result = this->ConvertToRelativePath( result = this->ConvertToRelativePath(
this->GetState()->GetBinaryDirectoryComponents(), source); this->GetState()->GetBinaryDirectory(), source);
break; break;
case START_OUTPUT: case START_OUTPUT:
result = this->ConvertToRelativePath( result = this->ConvertToRelativePath(
this->StateSnapshot.GetDirectory().GetCurrentBinaryComponents(), this->StateSnapshot.GetDirectory().GetCurrentBinary(), source);
source);
break; break;
} }
return result; return result;
@ -128,41 +126,67 @@ std::string cmOutputConverter::ConvertToRelativePath(
const std::vector<std::string>& local, const std::string& in_remote, const std::vector<std::string>& local, const std::string& in_remote,
bool force) const bool force) const
{ {
// The path should never be quoted. std::string local_path = cmSystemTools::JoinPath(local);
assert(in_remote[0] != '\"'); return force ? this->ForceToRelativePath(local_path, in_remote)
: this->ConvertToRelativePath(local_path, in_remote);
}
std::string cmOutputConverter::ConvertToRelativePath(
std::string const& local_path, std::string const& remote_path) const
{
// The paths should never be quoted.
assert(local_path[0] != '\"');
assert(remote_path[0] != '\"');
// The local path should never have a trailing slash. // The local path should never have a trailing slash.
assert(!local.empty() && !(local[local.size() - 1] == "")); assert(local_path.empty() || local_path[local_path.size() - 1] != '/');
// If the path is already relative then just return the path. // If the path is already relative then just return the path.
if (!cmSystemTools::FileIsFullPath(in_remote.c_str())) { if (!cmSystemTools::FileIsFullPath(remote_path.c_str())) {
return in_remote; return remote_path;
} }
if (!force) { // Skip conversion if the path and local are not both in the source
// Skip conversion if the path and local are not both in the source // or both in the binary tree.
// or both in the binary tree. if (!((cmOutputConverterNotAbove(
std::string local_path = cmSystemTools::JoinPath(local); local_path.c_str(),
if (!((cmOutputConverterNotAbove( this->StateSnapshot.GetDirectory().GetRelativePathTopBinary()) &&
local_path.c_str(), cmOutputConverterNotAbove(
this->StateSnapshot.GetDirectory().GetRelativePathTopBinary()) && remote_path.c_str(),
cmOutputConverterNotAbove( this->StateSnapshot.GetDirectory().GetRelativePathTopBinary())) ||
in_remote.c_str(), (cmOutputConverterNotAbove(
this->StateSnapshot.GetDirectory().GetRelativePathTopBinary())) || local_path.c_str(),
(cmOutputConverterNotAbove( this->StateSnapshot.GetDirectory().GetRelativePathTopSource()) &&
local_path.c_str(), cmOutputConverterNotAbove(
this->StateSnapshot.GetDirectory().GetRelativePathTopSource()) && remote_path.c_str(),
cmOutputConverterNotAbove(in_remote.c_str(), this->StateSnapshot.GetDirectory().GetRelativePathTopSource())))) {
this->StateSnapshot.GetDirectory() return remote_path;
.GetRelativePathTopSource())))) { }
return in_remote;
} return this->ForceToRelativePath(local_path, remote_path);
}
std::string cmOutputConverter::ForceToRelativePath(
std::string const& local_path, std::string const& remote_path)
{
// The paths should never be quoted.
assert(local_path[0] != '\"');
assert(remote_path[0] != '\"');
// The local path should never have a trailing slash.
assert(local_path.empty() || local_path[local_path.size() - 1] != '/');
// If the path is already relative then just return the path.
if (!cmSystemTools::FileIsFullPath(remote_path.c_str())) {
return remote_path;
} }
// Identify the longest shared path component between the remote // Identify the longest shared path component between the remote
// path and the local path. // path and the local path.
std::vector<std::string> local;
cmSystemTools::SplitPath(local_path, local);
std::vector<std::string> remote; std::vector<std::string> remote;
cmSystemTools::SplitPath(in_remote, remote); cmSystemTools::SplitPath(remote_path, remote);
unsigned int common = 0; unsigned int common = 0;
while (common < remote.size() && common < local.size() && while (common < remote.size() && common < local.size() &&
cmSystemTools::ComparePath(remote[common], local[common])) { cmSystemTools::ComparePath(remote[common], local[common])) {
@ -171,7 +195,7 @@ std::string cmOutputConverter::ConvertToRelativePath(
// If no part of the path is in common then return the full path. // If no part of the path is in common then return the full path.
if (common == 0) { if (common == 0) {
return in_remote; return remote_path;
} }
// If the entire path is in common then just return a ".". // If the entire path is in common then just return a ".".

View File

@ -145,6 +145,24 @@ public:
const std::string& in_remote, const std::string& in_remote,
bool force = false) const; bool force = false) 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 ConvertToRelativePath(std::string const& local_path,
std::string const& remote_path) 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.
*/
static std::string ForceToRelativePath(std::string const& local_path,
std::string const& remote_path);
private: private:
cmState* GetState() const; cmState* GetState() const;

View File

@ -77,8 +77,6 @@ struct cmState::BuildsystemDirectoryStateType
std::string Location; std::string Location;
std::string OutputLocation; std::string OutputLocation;
std::vector<std::string> CurrentSourceDirectoryComponents;
std::vector<std::string> CurrentBinaryDirectoryComponents;
// The top-most directories for relative path conversion. Both the // The top-most directories for relative path conversion. Both the
// source and destination location of a relative path conversion // source and destination location of a relative path conversion
// must be underneath one of these directories (both under source or // must be underneath one of these directories (both under source or
@ -591,10 +589,6 @@ void cmState::SetSourceDirectory(std::string const& sourceDirectory)
{ {
this->SourceDirectory = sourceDirectory; this->SourceDirectory = sourceDirectory;
cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory); cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
cmSystemTools::SplitPath(
cmSystemTools::CollapseFullPath(this->SourceDirectory),
this->SourceDirectoryComponents);
} }
const char* cmState::GetSourceDirectory() const const char* cmState::GetSourceDirectory() const
@ -602,19 +596,10 @@ const char* cmState::GetSourceDirectory() const
return this->SourceDirectory.c_str(); return this->SourceDirectory.c_str();
} }
std::vector<std::string> const& cmState::GetSourceDirectoryComponents() const
{
return this->SourceDirectoryComponents;
}
void cmState::SetBinaryDirectory(std::string const& binaryDirectory) void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
{ {
this->BinaryDirectory = binaryDirectory; this->BinaryDirectory = binaryDirectory;
cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory); cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
cmSystemTools::SplitPath(
cmSystemTools::CollapseFullPath(this->BinaryDirectory),
this->BinaryDirectoryComponents);
} }
void cmState::SetWindowsShell(bool windowsShell) void cmState::SetWindowsShell(bool windowsShell)
@ -692,11 +677,6 @@ const char* cmState::GetBinaryDirectory() const
return this->BinaryDirectory.c_str(); return this->BinaryDirectory.c_str();
} }
std::vector<std::string> const& cmState::GetBinaryDirectoryComponents() const
{
return this->BinaryDirectoryComponents;
}
void cmState::Directory::ComputeRelativePathTopSource() void cmState::Directory::ComputeRelativePathTopSource()
{ {
// Relative path conversion inside the source tree is not used to // Relative path conversion inside the source tree is not used to
@ -978,8 +958,6 @@ void cmState::Directory::SetCurrentSource(std::string const& dir)
cmSystemTools::ConvertToUnixSlashes(loc); cmSystemTools::ConvertToUnixSlashes(loc);
loc = cmSystemTools::CollapseFullPath(loc); loc = cmSystemTools::CollapseFullPath(loc);
cmSystemTools::SplitPath(
loc, this->DirectoryState->CurrentSourceDirectoryComponents);
this->ComputeRelativePathTopSource(); this->ComputeRelativePathTopSource();
this->Snapshot_.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", loc); this->Snapshot_.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", loc);
@ -997,8 +975,6 @@ void cmState::Directory::SetCurrentBinary(std::string const& dir)
cmSystemTools::ConvertToUnixSlashes(loc); cmSystemTools::ConvertToUnixSlashes(loc);
loc = cmSystemTools::CollapseFullPath(loc); loc = cmSystemTools::CollapseFullPath(loc);
cmSystemTools::SplitPath(
loc, this->DirectoryState->CurrentBinaryDirectoryComponents);
this->ComputeRelativePathTopBinary(); this->ComputeRelativePathTopBinary();
this->Snapshot_.SetDefinition("CMAKE_CURRENT_BINARY_DIR", loc); this->Snapshot_.SetDefinition("CMAKE_CURRENT_BINARY_DIR", loc);
@ -1009,18 +985,6 @@ void cmState::Snapshot::SetListFile(const std::string& listfile)
*this->Position->ExecutionListFile = listfile; *this->Position->ExecutionListFile = listfile;
} }
std::vector<std::string> const&
cmState::Directory::GetCurrentSourceComponents() const
{
return this->DirectoryState->CurrentSourceDirectoryComponents;
}
std::vector<std::string> const&
cmState::Directory::GetCurrentBinaryComponents() const
{
return this->DirectoryState->CurrentBinaryDirectoryComponents;
}
const char* cmState::Directory::GetRelativePathTopSource() const const char* cmState::Directory::GetRelativePathTopSource() const
{ {
return this->DirectoryState->RelativePathTopSource.c_str(); return this->DirectoryState->RelativePathTopSource.c_str();

View File

@ -135,9 +135,6 @@ public:
const char* GetCurrentBinary() const; const char* GetCurrentBinary() const;
void SetCurrentBinary(std::string const& dir); void SetCurrentBinary(std::string const& dir);
std::vector<std::string> const& GetCurrentSourceComponents() const;
std::vector<std::string> const& GetCurrentBinaryComponents() const;
const char* GetRelativePathTopSource() const; const char* GetRelativePathTopSource() const;
const char* GetRelativePathTopBinary() const; const char* GetRelativePathTopBinary() const;
void SetRelativePathTopSource(const char* dir); void SetRelativePathTopSource(const char* dir);
@ -312,9 +309,6 @@ public:
const char* GetBinaryDirectory() const; const char* GetBinaryDirectory() const;
void SetBinaryDirectory(std::string const& binaryDirectory); void SetBinaryDirectory(std::string const& binaryDirectory);
std::vector<std::string> const& GetSourceDirectoryComponents() const;
std::vector<std::string> const& GetBinaryDirectoryComponents() const;
void SetWindowsShell(bool windowsShell); void SetWindowsShell(bool windowsShell);
bool UseWindowsShell() const; bool UseWindowsShell() const;
void SetWindowsVSIDE(bool windowsVSIDE); void SetWindowsVSIDE(bool windowsVSIDE);
@ -350,8 +344,6 @@ private:
cmLinkedTree<SnapshotDataType> SnapshotData; cmLinkedTree<SnapshotDataType> SnapshotData;
cmLinkedTree<cmDefinitions> VarTree; cmLinkedTree<cmDefinitions> VarTree;
std::vector<std::string> SourceDirectoryComponents;
std::vector<std::string> BinaryDirectoryComponents;
std::string SourceDirectory; std::string SourceDirectory;
std::string BinaryDirectory; std::string BinaryDirectory;
bool IsInTryCompile; bool IsInTryCompile;