in facebook-clang-plugins/libtooling/FileUtils.cpp [69:93]
std::string makeRelativePath(const std::string &repoRoot,
const std::string &sysRoot,
bool keepExternalPaths,
bool allowSiblingsToRepoRoot,
const std::string &path) {
if (repoRoot != "") {
if (llvm::StringRef(path).startswith(repoRoot + "/")) {
return path.substr(repoRoot.size() + 1);
}
if (allowSiblingsToRepoRoot) {
std::string parentOfRoot = llvm::sys::path::parent_path(repoRoot).str();
if (llvm::StringRef(path).startswith(parentOfRoot + "/")) {
return "../" + path.substr(parentOfRoot.size() + 1);
}
}
}
if (sysRoot != "" && llvm::StringRef(path).startswith(sysRoot + "/")) {
// Intentionally keep the heading "/" in this case.
return path.substr(sysRoot.size());
}
if (keepExternalPaths) {
return path;
}
return "";
}