Convert: Extract method to determine if paths are in directory

The conditional early return can be moved to clients, which would have
many benefits, notably making cmOutputConverter independent of
directory-specific state.
This commit is contained in:
Stephen Kelly 2016-10-04 22:56:30 +02:00
parent 52168f3210
commit c3264f48c2
2 changed files with 17 additions and 5 deletions

View File

@ -76,13 +76,14 @@ static bool cmOutputConverterNotAbove(const char* a, const char* b)
cmSystemTools::IsSubDirectory(a, b)); cmSystemTools::IsSubDirectory(a, b));
} }
std::string cmOutputConverter::ConvertToRelativePath( bool cmOutputConverter::ContainedInDirectory(std::string const& local_path,
std::string const& local_path, std::string const& remote_path) const std::string const& remote_path,
cmState::Directory directory)
{ {
const std::string relativePathTopBinary = const std::string relativePathTopBinary =
this->StateSnapshot.GetDirectory().GetRelativePathTopBinary(); directory.GetRelativePathTopBinary();
const std::string relativePathTopSource = const std::string relativePathTopSource =
this->StateSnapshot.GetDirectory().GetRelativePathTopSource(); directory.GetRelativePathTopSource();
const bool bothInBinary = const bool bothInBinary =
cmOutputConverterNotAbove(local_path.c_str(), cmOutputConverterNotAbove(local_path.c_str(),
@ -96,7 +97,14 @@ std::string cmOutputConverter::ConvertToRelativePath(
cmOutputConverterNotAbove(remote_path.c_str(), cmOutputConverterNotAbove(remote_path.c_str(),
relativePathTopSource.c_str()); relativePathTopSource.c_str());
if (!(bothInSource || bothInBinary)) { return bothInSource || bothInBinary;
}
std::string cmOutputConverter::ConvertToRelativePath(
std::string const& local_path, std::string const& remote_path) const
{
if (!ContainedInDirectory(local_path, remote_path,
this->StateSnapshot.GetDirectory())) {
return remote_path; return remote_path;
} }

View File

@ -99,6 +99,10 @@ public:
}; };
static FortranFormat GetFortranFormat(const char* value); static FortranFormat GetFortranFormat(const char* value);
static bool ContainedInDirectory(std::string const& local_path,
std::string const& remote_path,
cmState::Directory directory);
/** /**
* Convert the given remote path to a relative path with respect to * Convert the given remote path to a relative path with respect to
* the given local path. Both paths must use forward slashes and not * the given local path. Both paths must use forward slashes and not