set(
source_files
argprocessing.cpp
- args.cpp
ccache.cpp
compopt.cpp
config.cpp
#include "argprocessing.hpp"
-#include <ccache/args.hpp>
#include <ccache/argsinfo.hpp>
#include <ccache/compopt.hpp>
#include <ccache/context.hpp>
#include <ccache/core/common.hpp>
#include <ccache/depfile.hpp>
#include <ccache/language.hpp>
+#include <ccache/util/args.hpp>
#include <ccache/util/assertions.hpp>
#include <ccache/util/direntry.hpp>
#include <ccache/util/filesystem.hpp>
}
private:
- Args m_preprocessor_args;
- Args m_compiler_args;
- Args m_extra_args_to_hash;
+ util::Args m_preprocessor_args;
+ util::Args m_compiler_args;
+ util::Args m_extra_args_to_hash;
};
bool
process_option_arg(const Context& ctx,
ArgsInfo& args_info,
Config& config,
- Args& args,
+ util::Args& args,
size_t& args_index,
ArgumentProcessingState& state)
{
++argpath;
}
auto file_args =
- Args::from_response_file(argpath, config.response_file_format());
+ util::Args::from_response_file(argpath, config.response_file_format());
if (!file_args) {
LOG("Couldn't read arg file {}", argpath);
return Statistic::bad_compiler_arguments;
// Argument is a comma-separated list of files.
auto paths = util::split_into_strings(args[i], ",");
for (auto it = paths.rbegin(); it != paths.rend(); ++it) {
- auto file_args =
- Args::from_response_file(*it, Args::ResponseFileFormat::posix);
+ auto file_args = util::Args::from_response_file(
+ *it, util::Args::ResponseFileFormat::posix);
if (!file_args) {
LOG("Couldn't read CUDA options file {}", *it);
return Statistic::bad_compiler_arguments;
process_arg(const Context& ctx,
ArgsInfo& args_info,
Config& config,
- Args& args,
+ util::Args& args,
size_t& args_index,
ArgumentProcessingState& state)
{
// args is a copy of the original arguments given to the compiler but with
// arguments from @file and similar constructs expanded. It's only used as a
// temporary data structure to loop over.
- Args args = ctx.orig_args;
+ util::Args args = ctx.orig_args;
ArgumentProcessingState state;
state.add_common_arg(args[0]); // Compiler
#pragma once
-#include <ccache/args.hpp>
#include <ccache/core/statistic.hpp>
+#include <ccache/util/args.hpp>
#include <tl/expected.hpp>
{
// Arguments (except "-E -o output.i") to send to the preprocessor. These are
// part of the input hash (except those marked as AFFECTS_CPP in compopt.cpp).
- Args preprocessor_args;
+ util::Args preprocessor_args;
// Arguments to send to the real compiler. Not part of the input hash.
- Args compiler_args;
+ util::Args compiler_args;
// Arguments not sent to the preprocessor but added to the input hash anyway.
- Args extra_args_to_hash;
+ util::Args extra_args_to_hash;
// Whether to include the actual CWD in the input hash.
bool hash_actual_cwd = false;
-// Copyright (C) 2020-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2025 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#pragma once
-#include <ccache/args.hpp>
+#include <ccache/util/args.hpp>
#include <filesystem>
#include <optional>
#include "ccache.hpp"
#include <ccache/argprocessing.hpp>
-#include <ccache/args.hpp>
#include <ccache/argsinfo.hpp>
#include <ccache/compopt.hpp>
#include <ccache/context.hpp>
#include <ccache/hashutil.hpp>
#include <ccache/signalhandler.hpp>
#include <ccache/storage/storage.hpp>
+#include <ccache/util/args.hpp>
#include <ccache/util/assertions.hpp>
#include <ccache/util/bytes.hpp>
#include <ccache/util/clang.hpp>
}
static void
-add_prefix(const Context& ctx, Args& args, const std::string& prefix_command)
+add_prefix(const Context& ctx,
+ util::Args& args,
+ const std::string& prefix_command)
{
if (prefix_command.empty()) {
return;
}
- Args prefixes;
+ util::Args prefixes;
for (const auto& prefix : util::split_into_strings(prefix_command, " ")) {
prefixes.push_back(prefix);
}
// Execute the compiler/preprocessor, with logic to retry without requesting
// colored diagnostics messages if that fails.
static tl::expected<DoExecuteResult, Failure>
-do_execute(Context& ctx, Args& args, const bool capture_stdout = true)
+do_execute(Context& ctx, util::Args& args, const bool capture_stdout = true)
{
util::UmaskScope umask_scope(ctx.original_umask);
// Run the real compiler and put the result in cache. Returns the result key.
static tl::expected<Hash::Digest, Failure>
to_cache(Context& ctx,
- Args& args,
+ util::Args& args,
std::optional<Hash::Digest> result_key,
Hash* depend_mode_hash)
{
}
static bool
-get_clang_cu_enable_verbose_mode(const Args& args)
+get_clang_cu_enable_verbose_mode(const util::Args& args)
{
for (size_t i = 1; i < args.size(); i++) {
if (args[i] == "-v") {
// Find the result key by running the compiler in preprocessor mode and
// hashing the result.
static tl::expected<Hash::Digest, Failure>
-get_result_key_from_cpp(Context& ctx, Args& args, Hash& hash)
+get_result_key_from_cpp(Context& ctx, util::Args& args, Hash& hash)
{
fs::path preprocessed_path;
util::Bytes cpp_stderr_data;
// update a hash with information common for the direct and preprocessor modes.
static tl::expected<void, Failure>
-hash_common_info(const Context& ctx, const Args& args, Hash& hash)
+hash_common_info(const Context& ctx, const util::Args& args, Hash& hash)
{
hash.hash(HASH_PREFIX);
static std::tuple<std::optional<std::string_view>,
std::optional<std::string_view>>
-get_option_and_value(std::string_view option, const Args& args, size_t& i)
+get_option_and_value(std::string_view option, const util::Args& args, size_t& i)
{
if (args[i] == option) {
if (i + 1 < args.size()) {
static tl::expected<void, Failure>
hash_argument(const Context& ctx,
- const Args& args,
+ const util::Args& args,
size_t& i,
Hash& hash,
const bool is_clang,
std::pair<std::optional<Hash::Digest>, std::optional<Hash::Digest>>,
Failure>
calculate_result_and_manifest_key(Context& ctx,
- const Args& args,
+ const util::Args& args,
Hash& hash,
- Args* preprocessor_args)
+ util::Args* preprocessor_args)
{
bool direct_mode = !preprocessor_args;
bool found_ccbin = false;
argv_parts.config_settings.emplace_back(argv[i]);
++i;
}
- argv_parts.compiler_and_args = Args::from_argv(argc - i, argv + i);
+ argv_parts.compiler_and_args = util::Args::from_argv(argc - i, argv + i);
return argv_parts;
}
tzset(); // Needed for localtime_r.
bool fall_back_to_original_compiler = false;
- Args saved_orig_args;
+ util::Args saved_orig_args;
std::optional<uint32_t> original_umask;
fs::path saved_temp_dir;
Hash direct_hash = common_hash;
init_hash_debug(ctx, direct_hash, 'd', "DIRECT MODE", debug_text_file);
- Args args_to_hash = process_args_result->preprocessor_args;
+ util::Args args_to_hash = process_args_result->preprocessor_args;
args_to_hash.push_back(process_args_result->extra_args_to_hash);
bool put_result_in_manifest = false;
// Copyright (C) 2002-2007 Andrew Tridgell
-// Copyright (C) 2009-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2009-2025 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#pragma once
-#include <ccache/args.hpp>
#include <ccache/config.hpp>
+#include <ccache/util/args.hpp>
#include <filesystem>
#include <functional>
{
bool masquerading_as_compiler = true;
std::vector<std::string> config_settings;
- Args compiler_and_args;
+ util::Args compiler_and_args;
};
ArgvParts split_argv(int argc, const char* const* argv);
{"UMASK", "umask" },
};
-Args::ResponseFileFormat
+util::Args::ResponseFileFormat
parse_response_file_format(const std::string& value)
{
if (value == "posix") {
- return Args::ResponseFileFormat::posix;
+ return util::Args::ResponseFileFormat::posix;
} else if (value == "windows") {
- return Args::ResponseFileFormat::windows;
+ return util::Args::ResponseFileFormat::windows;
} else {
- return Args::ResponseFileFormat::auto_guess;
+ return util::Args::ResponseFileFormat::auto_guess;
}
}
}
std::string
-response_file_format_to_string(Args::ResponseFileFormat response_file_format)
+response_file_format_to_string(
+ util::Args::ResponseFileFormat response_file_format)
{
switch (response_file_format) {
- case Args::ResponseFileFormat::auto_guess:
+ case util::Args::ResponseFileFormat::auto_guess:
return "auto";
- case Args::ResponseFileFormat::posix:
+ case util::Args::ResponseFileFormat::posix:
return "posix";
- case Args::ResponseFileFormat::windows:
+ case util::Args::ResponseFileFormat::windows:
return "windows";
}
#pragma once
-#include <ccache/args.hpp>
#include <ccache/core/sloppiness.hpp>
+#include <ccache/util/args.hpp>
#include <ccache/util/noncopyable.hpp>
#include <ccache/util/path.hpp>
#include <ccache/util/string.hpp>
void read(const std::vector<std::string>& cmdline_config_settings = {});
bool absolute_paths_in_stderr() const;
- Args::ResponseFileFormat response_file_format() const;
+ util::Args::ResponseFileFormat response_file_format() const;
const std::filesystem::path& base_dir() const;
const std::filesystem::path& cache_dir() const;
const std::string& compiler() const;
std::filesystem::path m_system_config_path;
bool m_absolute_paths_in_stderr = false;
- Args::ResponseFileFormat m_response_file_format =
- Args::ResponseFileFormat::auto_guess;
+ util::Args::ResponseFileFormat m_response_file_format =
+ util::Args::ResponseFileFormat::auto_guess;
std::filesystem::path m_base_dir;
std::filesystem::path m_cache_dir;
std::string m_compiler;
return m_absolute_paths_in_stderr;
}
-inline Args::ResponseFileFormat
+inline util::Args::ResponseFileFormat
Config::response_file_format() const
{
- if (m_response_file_format != Args::ResponseFileFormat::auto_guess) {
+ if (m_response_file_format != util::Args::ResponseFileFormat::auto_guess) {
return m_response_file_format;
}
- return is_compiler_group_msvc() ? Args::ResponseFileFormat::windows
- : Args::ResponseFileFormat::posix;
+ return is_compiler_group_msvc() ? util::Args::ResponseFileFormat::windows
+ : util::Args::ResponseFileFormat::posix;
}
inline const std::filesystem::path&
-// Copyright (C) 2020-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2025 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
}
void
-Context::initialize(Args&& compiler_and_args,
+Context::initialize(util::Args&& compiler_and_args,
const std::vector<std::string>& cmdline_config_settings)
{
orig_args = std::move(compiler_and_args);
-// Copyright (C) 2020-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2025 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#pragma once
-#include <ccache/args.hpp>
#include <ccache/argsinfo.hpp>
#include <ccache/config.hpp>
#include <ccache/core/manifest.hpp>
#include <ccache/hash.hpp>
#include <ccache/storage/storage.hpp>
+#include <ccache/util/args.hpp>
#include <ccache/util/bytes.hpp>
#include <ccache/util/filestream.hpp>
#include <ccache/util/noncopyable.hpp>
// Read configuration, initialize logging, etc. Typically not called from unit
// tests.
- void initialize(Args&& compiler_and_args,
+ void initialize(util::Args&& compiler_and_args,
const std::vector<std::string>& cmdline_config_settings);
ArgsInfo args_info;
std::filesystem::path apparent_cwd;
// The original argument list.
- Args orig_args;
+ util::Args orig_args;
// Files included by the preprocessor and their hashes.
std::unordered_map<std::string, Hash::Digest> included_files;
#include "hashutil.hpp"
-#include <ccache/args.hpp>
#include <ccache/config.hpp>
#include <ccache/context.hpp>
#include <ccache/core/exceptions.hpp>
#include <ccache/execute.hpp>
#include <ccache/macroskip.hpp>
+#include <ccache/util/args.hpp>
#include <ccache/util/cpu.hpp>
#include <ccache/util/direntry.hpp>
#include <ccache/util/environment.hpp>
} else {
using_cmd_exe = false;
}
- Args args = Args::from_string(adjusted_command);
+ util::Args args = util::Args::from_string(adjusted_command);
{
auto full_path =
find_executable_in_path(args[0], util::getenv_path_list("PATH")).string();
}
}
#else
- Args args = Args::from_string(command);
+ util::Args args = util::Args::from_string(command);
#endif
for (size_t i = 0; i < args.size(); i++) {
set(
sources
+ args.cpp
assertions.cpp
bytes.cpp
clang.cpp
#include <ccache/util/logging.hpp>
#include <ccache/util/string.hpp>
+namespace util {
+
Args::Args(Args&& other) noexcept
: m_args(std::move(other.m_args))
{
insert(index, args);
}
}
+
+} // namespace util
#include <string_view>
#include <vector>
+namespace util {
+
class Args
{
public:
{
m_args.push_back(arg.string());
}
+
+} // namespace util
source_files
main.cpp
test_argprocessing.cpp
- test_args.cpp
test_ccache.cpp
test_compopt.cpp
test_compression_types.cpp
test_hashutil.cpp
test_storage_local_statsfile.cpp
test_storage_local_util.cpp
+ test_util_args.cpp
test_util_bitset.cpp
test_util_bytes.cpp
test_util_clang.cpp
#include "testutil.hpp"
#include <ccache/argprocessing.hpp>
-#include <ccache/args.hpp>
#include <ccache/config.hpp>
#include <ccache/context.hpp>
#include <ccache/core/statistic.hpp>
+#include <ccache/util/args.hpp>
#include <ccache/util/file.hpp>
#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
using core::Statistic;
using TestUtil::TestContext;
+using util::Args;
namespace {
namespace fs = util::filesystem;
using TestUtil::TestContext;
+using util::Args;
TEST_SUITE_BEGIN("ccache");
TEST_CASE("Config::response_file_format")
{
- using ResponseFileFormat = Args::ResponseFileFormat;
+ using ResponseFileFormat = util::Args::ResponseFileFormat;
Config config;
#include "testutil.hpp"
-#include <ccache/args.hpp>
#include <ccache/config.hpp>
+#include <ccache/util/args.hpp>
#include <ccache/util/file.hpp>
#include <doctest/doctest.h>
TEST_SUITE_BEGIN("Args");
using TestUtil::TestContext;
+using util::Args;
TEST_CASE("Args default constructor")
{