// Use the original arguments (including dependency options) in depend
// mode.
- assert(orig_args);
- struct args* depend_mode_args = args_copy(orig_args);
+ assert(ctx.orig_args);
+ struct args* depend_mode_args = args_copy(ctx.orig_args);
args_strip(depend_mode_args, "--ccache-");
if (depend_extra_args) {
args_extend(depend_mode_args, depend_extra_args);
hash_file(hash, path);
} else { // command string
bool ok = hash_multicommand_output(
- ctx, hash, ctx.config.compiler_check().c_str(), orig_args->argv[0]);
+ ctx, hash, ctx.config.compiler_check().c_str(), ctx.orig_args->argv[0]);
if (!ok) {
fatal("Failure running compiler check command: %s",
ctx.config.compiler_check().c_str());
// We might be being invoked like "ccache gcc -c foo.c".
std::string base(Util::base_name(argv[0]));
if (same_executable_name(base.c_str(), MYNAME)) {
- args_remove_first(orig_args);
- if (is_full_path(orig_args->argv[0])) {
+ args_remove_first(ctx.orig_args);
+ if (is_full_path(ctx.orig_args->argv[0])) {
// A full path was given.
return;
}
- base = std::string(Util::base_name(orig_args->argv[0]));
+ base = std::string(Util::base_name(ctx.orig_args->argv[0]));
}
// Support user override of the compiler.
fatal("Recursive invocation (the name of the ccache binary must be \"%s\")",
MYNAME);
}
- orig_args->argv[0] = compiler;
+ ctx.orig_args->argv[0] = compiler;
}
bool
// Initialize ccache, must be called once before anything else is run.
static Context&
-initialize()
+initialize(int argc, char* argv[])
{
// This object is placed onto the heap so it is available in exit functions
// which run after main(). It is cleaned up by the last exit function.
init_log(ctx->config);
+ ctx->orig_args = args_init(argc, argv);
+
exitfn_init();
exitfn_delete_context(ctx);
exitfn_add(stats_flush, ctx);
free_and_nullify(current_working_dir);
free_and_nullify(included_pch_file);
- args_free(orig_args);
- orig_args = NULL;
free_and_nullify(cached_result_name);
free_and_nullify(cached_result_path);
free_and_nullify(manifest_path);
// Needed for portability when using localtime_r.
tzset();
- orig_args = args_init(argc, argv);
-
- Context& ctx = initialize();
+ Context& ctx = initialize(argc, argv);
MTR_BEGIN("main", "find_compiler");
find_compiler(ctx, argv);
stats_update(e.stat());
}
- assert(orig_args);
+ assert(ctx.orig_args);
- args_strip(orig_args, "--ccache-");
- add_prefix(ctx, orig_args, ctx.config.prefix_command().c_str());
+ args_strip(ctx.orig_args, "--ccache-");
+ add_prefix(ctx, ctx.orig_args, ctx.config.prefix_command().c_str());
cc_log("Failed; falling back to running the real compiler");
- cc_log_argv("Executing ", orig_args->argv);
+ cc_log_argv("Executing ", ctx.orig_args->argv);
+ ctx.free_orig_args = false;
+ struct args* orig_args_for_execv = ctx.orig_args;
exitfn_call();
- execv(orig_args->argv[0], orig_args->argv);
- fatal("execv of %s failed: %s", orig_args->argv[0], strerror(errno));
+ execv(orig_args_for_execv->argv[0], orig_args_for_execv->argv);
+ fatal("execv of %s failed: %s", orig_args_for_execv->argv[0], strerror(errno));
}
}
std::min(std::max(ctx.config.limit_multiple(), 0.0), 1.0));
MTR_BEGIN("main", "guess_compiler");
- guessed_compiler = guess_compiler(orig_args->argv[0]);
+ guessed_compiler = guess_compiler(ctx.orig_args->argv[0]);
MTR_END("main", "guess_compiler");
// Arguments (except -E) to send to the preprocessor.
MTR_BEGIN("main", "process_args");
if (!cc_process_args(ctx,
- orig_args,
+ ctx.orig_args,
&preprocessor_args,
&extra_args_to_hash,
&compiler_args)) {
{"zero-stats", no_argument, 0, 'z'},
{0, 0, 0, 0}};
- Context& ctx = initialize();
+ Context& ctx = initialize(argc, argv);
(void)ctx;
int c;