| 2839 | } |
| 2840 | |
| 2841 | std::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 | |
| 2890 | std::string cmCTest::GetCTestConfiguration(std::string const& name) |
| 2891 | { |
no test coverage detected