namespace Util {
-std::string
-change_extension(std::string_view path, std::string_view new_ext)
-{
- std::string_view without_ext = Util::remove_extension(path);
- return std::string(without_ext).append(new_ext.data(), new_ext.length());
-}
-
size_t
common_dir_prefix_length(std::string_view dir, std::string_view path)
{
namespace Util {
-// Remove the extension via `remove_extension()`, then add `new_ext`. `new_ext`
-// should start with a dot, no extra dot is inserted.
-std::string change_extension(std::string_view path, std::string_view new_ext);
-
// Compute the length of the longest directory path that is common to paths
// `dir` (a directory) and `path` (any path).
size_t common_dir_prefix_length(std::string_view dir, std::string_view path);
pch_file = included_pch_file;
included_pch_file.clear(); // reset pch file set from /Fp
} else {
- std::string file = Util::change_extension(arg, ".pch");
- if (DirEntry(file).is_regular_file()) {
+ fs::path file = fs::path(arg).replace_extension(".pch");
+ if (fs::is_regular_file(file)) {
LOG("Detected use of precompiled header: {}", file);
- pch_file = file;
+ pch_file = file.string();
}
}
} else if (option == "-Fp") {
} else {
extension = get_default_object_file_extension(ctx.config);
}
- args_info.output_obj += Util::change_extension(
- fs::path(args_info.input_file).filename().string(), extension);
+ args_info.output_obj += fs::path(args_info.input_file)
+ .filename()
+ .replace_extension(extension)
+ .string();
}
args_info.orig_output_obj = args_info.output_obj;
args_info.seen_split_dwarf = false;
} else {
args_info.output_dwo =
- Util::change_extension(args_info.output_obj, ".dwo");
+ fs::path(args_info.output_obj).replace_extension(".dwo").string();
}
}
if (args_info.generating_dependencies) {
if (state.output_dep_origin == OutputDepOrigin::none) {
- args_info.output_dep = Util::change_extension(args_info.output_obj, ".d");
+ args_info.output_dep =
+ fs::path(args_info.output_obj).replace_extension(".d").string();
if (!config.run_second_cpp()) {
// If we're compiling preprocessed code we're sending dep_args to the
// preprocessor so we need to use -MF to write to the correct .d file
} else if (config.compiler_type() == CompilerType::gcc) {
// GCC strangely uses the base name of the source file but with a .o
// extension.
- dep_target = Util::change_extension(
- fs::path(args_info.orig_input_file).filename().string(),
- get_default_object_file_extension(ctx.config));
+ dep_target =
+ fs::path(args_info.orig_input_file)
+ .filename()
+ .replace_extension(get_default_object_file_extension(ctx.config))
+ .string();
} else {
// How other compilers behave is currently unknown, so bail out.
LOG_RAW(
}
if (args_info.generating_stackusage) {
- auto default_sufile_name =
- Util::change_extension(args_info.output_obj, ".su");
+ std::string default_sufile_name =
+ fs::path(args_info.output_obj).replace_extension(".su").string();
args_info.output_su = Util::make_relative_path(ctx, default_sufile_name);
}
-// Copyright (C) 2019-2023 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2024 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "Config.hpp"
#include "Context.hpp"
-#include "Util.hpp"
#include <ccache.hpp>
#include <core/CacheEntryDataReader.hpp>
: FMT("{}/{}", ctx.apparent_cwd, output_obj);
std::string hashified_obj = abs_output_obj;
std::replace(hashified_obj.begin(), hashified_obj.end(), '/', '#');
- return Util::change_extension(hashified_obj, ".gcno");
+ return fs::path(hashified_obj).replace_extension(".gcno").string();
}
std::string
gcno_file_in_unmangled_form(const Context& ctx)
{
- return Util::change_extension(ctx.args_info.output_obj, ".gcno");
+ return fs::path(ctx.args_info.output_obj).replace_extension(".gcno").string();
}
Deserializer::Deserializer(nonstd::span<const uint8_t> data) : m_data(data)
-// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2024 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "Depfile.hpp"
#include <Context.hpp>
-#include <Util.hpp>
#include <core/MsvcShowIncludesOutput.hpp>
#include <core/common.hpp>
#include <core/exceptions.hpp>
#include <util/Fd.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 <unistd.h>
#endif
+namespace fs = util::filesystem;
+
using util::DirEntry;
namespace core {
case FileType::coverage_unmangled:
if (m_ctx.args_info.generating_coverage) {
- return Util::change_extension(m_ctx.args_info.output_obj, ".gcno");
+ return fs::path(m_ctx.args_info.output_obj)
+ .replace_extension(".gcno")
+ .string();
}
break;
TEST_SUITE_BEGIN("Util");
-TEST_CASE("Util::change_extension")
-{
- CHECK(Util::change_extension("", "") == "");
- CHECK(Util::change_extension("x", "") == "x");
- CHECK(Util::change_extension("", "x") == "x");
- CHECK(Util::change_extension("", ".") == ".");
- CHECK(Util::change_extension(".", "") == ".");
- CHECK(Util::change_extension("...", "x") == "..x");
- CHECK(Util::change_extension("abc", "def") == "abcdef");
- CHECK(Util::change_extension("dot.", ".dot") == "dot.dot");
- CHECK(Util::change_extension("foo.ext", "e2") == "fooe2");
- CHECK(Util::change_extension("bar.txt", ".o") == "bar.o");
- CHECK(Util::change_extension("foo.bar.txt", ".o") == "foo.bar.o");
-}
-
TEST_CASE("Util::common_dir_prefix_length")
{
CHECK(Util::common_dir_prefix_length("", "") == 0);