MCPcopy Create free account
hub / github.com/Kitware/CMake / GetShortPathToFile

Method GetShortPathToFile

Source/cmCTest.cxx:2841–2888  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2839}
2840
2841std::string cmCTest::GetShortPathToFile(std::string const& cfname)
2842{
2843 std::string const& sourceDir =
2844 this->GetCTestConfiguration("SourceDirectory");
2845 std::string const& buildDir = this->GetCTestConfiguration("BuildDirectory");
2846 std::string fname = cmSystemTools::CollapseFullPath(cfname);
2847
2848 // Find relative paths to both directories
2849 std::string srcRelpath = cmSystemTools::RelativePath(sourceDir, fname);
2850 std::string bldRelpath = cmSystemTools::RelativePath(buildDir, fname);
2851
2852 // If any contains "." it is not parent directory
2853 bool inSrc = srcRelpath.find("..") == std::string::npos;
2854 bool inBld = bldRelpath.find("..") == std::string::npos;
2855 // TODO: Handle files with .. in their name
2856
2857 std::string* res = nullptr;
2858
2859 if (inSrc && inBld) {
2860 // If both have relative path with no dots, pick the shorter one
2861 if (srcRelpath.size() < bldRelpath.size()) {
2862 res = &srcRelpath;
2863 } else {
2864 res = &bldRelpath;
2865 }
2866 } else if (inSrc) {
2867 res = &srcRelpath;
2868 } else if (inBld) {
2869 res = &bldRelpath;
2870 }
2871
2872 std::string path;
2873
2874 if (!res) {
2875 path = fname;
2876 } else {
2877 cmSystemTools::ConvertToUnixSlashes(*res);
2878
2879 path = "./" + *res;
2880 if (path.back() == '/') {
2881 path.resize(path.size() - 1);
2882 }
2883 }
2884
2885 cmsys::SystemTools::ReplaceString(path, ":", "_");
2886 cmsys::SystemTools::ReplaceString(path, " ", "_");
2887 return path;
2888}
2889
2890std::string cmCTest::GetCTestConfiguration(std::string const& name)
2891{

Callers 9

GenerateCTestXMLMethod · 0.80
WriteTestResultHeaderMethod · 0.80
GenerateCTestXMLMethod · 0.80
ProcessHandlerMethod · 0.80
LoadLabelsMethod · 0.80
IsFilteredOutMethod · 0.80
FindUncoveredFilesMethod · 0.80

Calls 5

GetCTestConfigurationMethod · 0.95
findMethod · 0.45
sizeMethod · 0.45
backMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected