]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Context: move output_dep
authorThomas Otto <thomas.otto@pdv-fs.de>
Fri, 24 Jan 2020 18:14:00 +0000 (19:14 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 13 Feb 2020 20:15:57 +0000 (21:15 +0100)
src/ccache.cpp
src/legacy_globals.cpp
src/legacy_globals.hpp
unittest/test_argument_processing.cpp

index 5130ca18e2f69eacc182ca817443a713c378e67d..c583a27aa5b8be79c6c995634e841fe6df70be83 100644 (file)
@@ -907,8 +907,10 @@ process_preprocessed_file(Context& ctx,
 
 // Replace absolute paths with relative paths in the provided dependency file.
 static void
-use_relative_paths_in_depfile(const char* depfile)
+use_relative_paths_in_depfile(Context& ctx)
 {
+  const char* depfile = ctx.args_info.output_dep.c_str();
+
   if (g_config.base_dir().empty()) {
     cc_log("Base dir not set, skip using relative paths");
     return; // nothing to do
@@ -1297,8 +1299,8 @@ to_cache(Context& ctx,
   }
 
   if (g_config.depend_mode()) {
-    struct digest* result_name =
-      result_name_from_depfile(ctx, output_dep, depend_mode_hash);
+    struct digest* result_name = result_name_from_depfile(
+      ctx, ctx.args_info.output_dep.c_str(), depend_mode_hash);
     if (!result_name) {
       stats_update(STATS_ERROR);
       failed();
@@ -1307,10 +1309,10 @@ to_cache(Context& ctx,
   }
 
   bool produce_dep_file =
-    generating_dependencies && !str_eq(output_dep, "/dev/null");
+    generating_dependencies && ctx.args_info.output_dep != "/dev/null";
 
   if (produce_dep_file) {
-    use_relative_paths_in_depfile(output_dep);
+    use_relative_paths_in_depfile(ctx);
   }
 
   st = Stat::stat(ctx.args_info.output_obj);
@@ -1336,7 +1338,7 @@ to_cache(Context& ctx,
   }
   result_file_map.emplace(FileType::object, ctx.args_info.output_obj);
   if (generating_dependencies) {
-    result_file_map.emplace(FileType::dependency, output_dep);
+    result_file_map.emplace(FileType::dependency, ctx.args_info.output_dep);
   }
   if (generating_coverage) {
     result_file_map.emplace(FileType::coverage, output_cov);
@@ -1824,7 +1826,7 @@ calculate_result_name(Context& ctx,
         hash_delimiter(hash, "arg");
         hash_string_buffer(hash, args->argv[i], 3);
 
-        if (!str_eq(output_dep, "/dev/null")) {
+        if (ctx.args_info.output_dep != "/dev/null") {
           bool separate_argument = (strlen(args->argv[i]) == 3);
           if (separate_argument) {
             // Next argument is dependency name, so skip it.
@@ -1899,7 +1901,7 @@ calculate_result_name(Context& ctx,
 
   // Make results with dependency file /dev/null different from those without
   // it.
-  if (generating_dependencies && str_eq(output_dep, "/dev/null")) {
+  if (generating_dependencies && ctx.args_info.output_dep == "/dev/null") {
     hash_delimiter(hash, "/dev/null dependency file");
   }
 
@@ -2062,7 +2064,7 @@ from_cache(Context& ctx,
   MTR_BEGIN("cache", "from_cache");
 
   bool produce_dep_file =
-    generating_dependencies && !str_eq(output_dep, "/dev/null");
+    generating_dependencies && ctx.args_info.output_dep != "/dev/null";
 
   MTR_BEGIN("file", "file_get");
 
@@ -2080,7 +2082,7 @@ from_cache(Context& ctx,
   }
   result_file_map.emplace(FileType::stderr_output, tmp_stderr);
   if (produce_dep_file) {
-    result_file_map.emplace(FileType::dependency, output_dep);
+    result_file_map.emplace(FileType::dependency, ctx.args_info.output_dep);
   }
   if (generating_coverage) {
     result_file_map.emplace(FileType::coverage, output_cov);
@@ -3547,7 +3549,6 @@ cc_reset(void)
   free_and_nullify(included_pch_file);
   args_free(orig_args);
   orig_args = NULL;
-  free_and_nullify(output_dep);
   free_and_nullify(output_cov);
   free_and_nullify(output_su);
   free_and_nullify(output_dia);
@@ -3708,7 +3709,6 @@ do_cache_compilation(Context& ctx, char* argv[])
     failed(); // stats_update is called in cc_process_args.
   }
 
-  output_dep = x_strdup(ctx.args_info.output_dep.c_str());
   output_cov = x_strdup(ctx.args_info.output_cov.c_str());
   output_su = x_strdup(ctx.args_info.output_su.c_str());
   output_dia = x_strdup(ctx.args_info.output_dia.c_str());
@@ -3738,7 +3738,7 @@ do_cache_compilation(Context& ctx, char* argv[])
   MTR_END("main", "process_args");
 
   if (g_config.depend_mode()
-      && (!generating_dependencies || str_eq(output_dep, "/dev/null")
+      && (!generating_dependencies || ctx.args_info.output_dep == "/dev/null"
           || !g_config.run_second_cpp())) {
     cc_log("Disabling depend mode");
     g_config.set_depend_mode(false);
@@ -3746,7 +3746,7 @@ do_cache_compilation(Context& ctx, char* argv[])
 
   cc_log("Source file: %s", ctx.args_info.input_file.c_str());
   if (generating_dependencies) {
-    cc_log("Dependency file: %s", output_dep);
+    cc_log("Dependency file: %s", ctx.args_info.output_dep.c_str());
   }
   if (generating_coverage) {
     cc_log("Coverage file: %s", output_cov);
index a9ab2719c63db49388dd946ac5b1ea0f9671e5a3..3bf956864981dfc8c7277fa31148cd3531b35cc7 100644 (file)
@@ -25,9 +25,6 @@ char* current_working_dir = nullptr;
 extern struct args* orig_args;
 struct args* orig_args = nullptr;
 
-// The path to the dependency file (implicit or specified with -MF).
-char* output_dep;
-
 // The path to the coverage file (implicit when using -ftest-coverage).
 char* output_cov;
 
index d0b04b631e632ec9617104fd4c612bf7a4522611..2218fcc50dfc1ac5d53e071f7eb19d61065af7c4 100644 (file)
@@ -34,8 +34,6 @@ extern unsigned lock_staleness_limit;
 
 extern struct args* orig_args;
 
-extern char* output_dep;
-
 extern char* output_cov;
 
 extern char* output_su;
index b0c5fb1c89eed41e6a93a8719b4e35704e2161f9..7f62314266d85cc8ca2c12703ea537d8b4dcabae 100644 (file)
@@ -84,7 +84,6 @@ cc_process_args(Context& ctx,
                                  extra_args_to_hash,
                                  compiler_args);
 
-  output_dep = x_strdup(ctx.args_info.output_dep.c_str());
   output_cov = x_strdup(ctx.args_info.output_cov.c_str());
   output_su = x_strdup(ctx.args_info.output_su.c_str());
   output_dia = x_strdup(ctx.args_info.output_dia.c_str());