void
verify_absolute_path(const std::string& value)
{
- if (!util::is_absolute_path(value)) {
+ if (!fs::path(value).is_absolute()) {
throw core::Error(FMT("not an absolute path: \"{}\"", value));
}
}
#include <util/Tokenizer.hpp>
#include <util/assertions.hpp>
#include <util/file.hpp>
+#include <util/filesystem.hpp>
#include <util/logging.hpp>
#include <util/path.hpp>
#include <util/string.hpp>
#include <algorithm>
+namespace fs = util::filesystem;
+
static inline bool
is_blank(const std::string& s)
{
const auto& token = tokens[i];
bool token_rewritten = false;
- if (seen_target_token && util::is_absolute_path(token)) {
+ if (seen_target_token && fs::path(token).is_absolute()) {
const auto new_path = Util::make_relative_path(ctx, token);
if (new_path != token) {
adjusted_file_content.append(new_path);
std::string
get_relative_path(std::string_view dir, std::string_view path)
{
- ASSERT(util::is_absolute_path(dir));
- ASSERT(util::is_absolute_path(path));
+ ASSERT(fs::path(dir).is_absolute());
+ ASSERT(fs::path(path).is_absolute());
#ifdef _WIN32
// Paths can be escaped by a slash for use with e.g. -isystem.
static std::string
do_normalize_abstract_absolute_path(std::string_view path)
{
- if (!util::is_absolute_path(path)) {
+ if (!fs::path(path).is_absolute()) {
return std::string(path);
}
// filename is included in the hash anyway.
if (ctx.config.is_compiler_group_msvc() && ctx.config.hash_dir()) {
const std::string output_obj_dir =
- util::is_absolute_path(args_info.output_obj)
+ fs::path(args_info.output_obj).is_absolute()
? std::string(Util::dir_name(args_info.output_obj))
: ctx.actual_cwd;
LOG("Hashing object file directory {}", output_obj_dir);
// the profile filename so we need to include the same information in the
// hash.
const std::string profile_path =
- util::is_absolute_path(ctx.args_info.profile_path)
+ fs::path(ctx.args_info.profile_path).is_absolute()
? ctx.args_info.profile_path
: FMT("{}/{}", ctx.apparent_cwd, ctx.args_info.profile_path);
LOG("Adding profile directory {} to our hash", profile_path);
#include <util/FileStream.hpp>
#include <util/expected.hpp>
#include <util/file.hpp>
+#include <util/filesystem.hpp>
#include <util/fmtmacros.hpp>
#include <util/logging.hpp>
#include <util/path.hpp>
#include <algorithm>
+namespace fs = util::filesystem;
+
// Result data format
// ==================
//
{
const auto& output_obj = ctx.args_info.output_obj;
const std::string abs_output_obj =
- util::is_absolute_path(output_obj)
+ fs::path(output_obj).is_absolute()
? output_obj
: FMT("{}/{}", ctx.apparent_cwd, output_obj);
std::string hashified_obj = abs_output_obj;
const std::string& name,
const std::string& exclude_path)
{
- if (util::is_absolute_path(name)) {
+ if (fs::path(name).is_absolute()) {
return name;
}
return actual_cwd;
#else
auto pwd = getenv("PWD");
- if (!pwd || !is_absolute_path(pwd)) {
+ if (!pwd || !fs::path(pwd).is_absolute()) {
return actual_cwd;
}
return k_dev_null_path;
}
-bool
-is_absolute_path(std::string_view path)
-{
-#ifdef _WIN32
- if (path.length() >= 3 && path[1] == ':'
- && (path[2] == '/' || path[2] == '\\')) {
- return true;
- }
-#endif
- return !path.empty() && path[0] == '/';
-}
-
bool
path_starts_with(std::string_view path, std::string_view prefix)
{
const char* get_dev_null_path();
-// Return whether `path` is absolute.
-bool is_absolute_path(std::string_view path);
-
// Return whether `path` is /dev/null or (on Windows) NUL.
bool is_dev_null_path(std::string_view path);
CHECK(util::add_exe_suffix("foo.sh") == "foo.sh");
}
-TEST_CASE("util::is_absolute_path")
-{
-#ifdef _WIN32
- CHECK(util::is_absolute_path("C:/"));
- CHECK(util::is_absolute_path("C:\\"));
- CHECK(util::is_absolute_path("C:\\foo/fie"));
- CHECK(util::is_absolute_path("/C:\\foo/fie")); // MSYS/Cygwin path
- CHECK(!util::is_absolute_path(""));
- CHECK(!util::is_absolute_path("C:"));
- CHECK(!util::is_absolute_path("foo\\fie/fum"));
- CHECK(!util::is_absolute_path("C:foo/fie"));
-#endif
- CHECK(util::is_absolute_path("/"));
- CHECK(util::is_absolute_path("/foo/fie"));
- CHECK(!util::is_absolute_path(""));
- CHECK(!util::is_absolute_path("foo/fie"));
-}
-
TEST_CASE("util::is_full_path")
{
CHECK(!util::is_full_path(""));