return !path.empty() && path[0] == '/';
}
+std::string
+to_absolute_path(nonstd::string_view path)
+{
+ if (util::is_absolute_path(path)) {
+ return to_string(path);
+ } else {
+ return Util::normalize_absolute_path(
+ FMT("{}/{}", Util::get_actual_cwd(), path));
+ }
+}
+
} // namespace util
// Return whether `path` is absolute.
bool is_absolute_path(nonstd::string_view path);
+// Make `path` an absolute path.
+std::string to_absolute_path(nonstd::string_view path);
+
} // namespace util
expect_stat 'unsupported compiler option' 1
expect_exists test1.o.ccache-log
+ # -------------------------------------------------------------------------
+ TEST "CCACHE_DEBUGDIR"
+
+ CCACHE_DEBUG=1 CCACHE_DEBUGDIR=debugdir $CCACHE_COMPILE -c test1.c
+ expect_contains debugdir"$(pwd -P)"/test1.o.ccache-log "Result: cache miss"
+
# -------------------------------------------------------------------------
TEST "CCACHE_DISABLE"
// this program; if not, write to the Free Software Foundation, Inc., 51
// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#include <Util.hpp>
+#include <fmtmacros.hpp>
#include <util/path_utils.hpp>
#include <third_party/doctest.h>
CHECK(!util::is_absolute_path(""));
CHECK(!util::is_absolute_path("foo/fie"));
}
+
+TEST_CASE("util::to_absolute_path")
+{
+ CHECK(util::to_absolute_path("/foo/bar") == "/foo/bar");
+
+#ifdef _WIN32
+ CHECK(util::to_absolute_path("C:\\foo\\bar") == "C:\\foo\\bar");
+#endif
+
+ const auto cwd = Util::get_actual_cwd();
+
+ CHECK(util::to_absolute_path("") == cwd);
+ CHECK(util::to_absolute_path(".") == cwd);
+ CHECK(util::to_absolute_path("..") == Util::dir_name(cwd));
+ CHECK(util::to_absolute_path("foo") == FMT("{}/foo", cwd));
+ CHECK(util::to_absolute_path("../foo/bar")
+ == FMT("{}/foo/bar", Util::dir_name(cwd)));
+}