diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2004-10-18 02:46:23 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2004-10-18 02:46:23 (GMT) |
commit | 3de7010216202e59eb05968bf12fb0811ff478ca (patch) | |
tree | ddbfd9a9f0115fa0935432f6f9a1b1a55831034e /Source | |
parent | 17619508e9d651f32cbd8d5bfbea6ac94ef975fc (diff) | |
download | CMake-3de7010216202e59eb05968bf12fb0811ff478ca.zip CMake-3de7010216202e59eb05968bf12fb0811ff478ca.tar.gz CMake-3de7010216202e59eb05968bf12fb0811ff478ca.tar.bz2 |
ENH: Add method to get the relative path to source or build
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCTest.cxx | 44 | ||||
-rw-r--r-- | Source/cmCTest.h | 3 |
2 files changed, 47 insertions, 0 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 5cea554..00860f6 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -2123,6 +2123,50 @@ void cmCTest::PopulateCustomVector(cmMakefile* mf, const char* def, tm_VectorOfS } } +std::string cmCTest::GetShortPathToFile(const char* fname) +{ + const std::string& sourceDir = GetDartConfiguration("SourceDirectory"); + const std::string& buildDir = GetDartConfiguration("BuildDirectory"); + + // Find relative paths to both directories + std::string srcRelpath = cmSystemTools::RelativePath(sourceDir.c_str(), fname); + std::string bldRelpath = cmSystemTools::RelativePath(buildDir.c_str(), fname); + + // If any contains "." it is not parent directory + bool inSrc = srcRelpath.find("..") == srcRelpath.npos; + bool inBld = bldRelpath.find("..") == bldRelpath.npos; + // TODO: Handle files with .. in their name + + std::string* res = 0; + + if ( inSrc && inBld ) + { + // If both have relative path with no dots, pick the shorter one + if ( srcRelpath.size() < bldRelpath.size() ) + { + res = &srcRelpath; + } + else + { + res = &bldRelpath; + } + } + else if ( inSrc ) + { + res = &srcRelpath; + } + else if ( inBld ) + { + res = &bldRelpath; + } + if ( !res ) + { + return fname; + } + cmSystemTools::ConvertToUnixSlashes(*res); + return "./" + *res; +} + std::string cmCTest::GetDartConfiguration(const char *name) { return m_DartConfiguration[name]; diff --git a/Source/cmCTest.h b/Source/cmCTest.h index bb53b10..2039350 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -183,6 +183,9 @@ public: //! Get the path to CTest const char* GetCTestExecutable() { return m_CTestSelf.c_str(); } + //! Get the short path to the file. This means if the file is in binary or + //source directory, it will become /.../relative/path/to/file + std::string GetShortPathToFile(const char* fname); private: // these are helper classes |