{
auto prefix = debug_dir.empty()
? output_obj
- : debug_dir + util::to_absolute_path(output_obj);
-#ifdef _WIN32
- prefix.erase(std::remove(prefix.begin(), prefix.end(), ':'), prefix.end());
-#endif
- try {
- Util::ensure_dir_exists(Util::dir_name(prefix));
- } catch (core::Error&) {
+ : debug_dir + util::to_absolute_path_no_drive(output_obj);
+ if (!Util::create_dir(Util::dir_name(prefix))) {
// Ignore since we can't handle an error in another way in this context. The
// caller takes care of logging when trying to open the path for writing.
}
}
}
+std::string
+to_absolute_path_no_drive(nonstd::string_view path)
+{
+ std::string abs_path = to_absolute_path(path);
+#ifdef _WIN32
+ if (abs_path.length() >= 2 && abs_path[1] == ':')
+ abs_path.erase(0, 2);
+#endif
+ return abs_path;
+}
+
} // namespace util
// Make `path` an absolute path.
std::string to_absolute_path(nonstd::string_view path);
+// Make `path` an absolute path, but do not include Windows drive.
+std::string to_absolute_path_no_drive(nonstd::string_view path);
+
// --- Inline implementations ---
inline bool
CHECK(util::to_absolute_path("../foo/bar")
== FMT("{}/foo/bar", Util::dir_name(cwd)));
}
+
+TEST_CASE("util::to_absolute_path_no_drive")
+{
+ CHECK(util::to_absolute_path_no_drive("/foo/bar") == "/foo/bar");
+
+#ifdef _WIN32
+ CHECK(util::to_absolute_path_no_drive("C:\\foo\\bar") == "\\foo\\bar");
+#endif
+
+ auto cwd = Util::get_actual_cwd();
+#ifdef _WIN32
+ cwd = cwd.substr(2);
+#endif
+
+ CHECK(util::to_absolute_path_no_drive("") == cwd);
+ CHECK(util::to_absolute_path_no_drive(".") == cwd);
+ CHECK(util::to_absolute_path_no_drive("..") == Util::dir_name(cwd));
+ CHECK(util::to_absolute_path_no_drive("foo") == FMT("{}/foo", cwd));
+ CHECK(util::to_absolute_path_no_drive("../foo/bar")
+ == FMT("{}/foo/bar", Util::dir_name(cwd)));
+}