]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Const-ify context parameters where appropriate
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 16 Feb 2020 18:14:53 +0000 (19:14 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 16 Feb 2020 20:14:57 +0000 (21:14 +0100)
src/ccache.cpp
src/compress.cpp
src/compress.hpp
src/execute.cpp
src/execute.hpp
src/hashutil.cpp
src/hashutil.hpp
src/result.cpp
src/result.hpp
src/stats.cpp
src/stats.hpp

index 5bec417e8a65fddb3cc67dca4257089f1240d358..9d5dedd31b32de89d005ece28b2cb73a3dac2f5f 100644 (file)
@@ -157,7 +157,7 @@ static pid_t compiler_pid = 0;
 static const char HASH_PREFIX[] = "3";
 
 static void
-add_prefix(Context& ctx, struct args* args, const char* prefix_command)
+add_prefix(const Context& ctx, struct args* args, const char* prefix_command)
 {
   if (str_eq(prefix_command, "")) {
     return;
@@ -197,7 +197,7 @@ failed(enum stats stat)
 }
 
 static const char*
-temp_dir(Context& ctx)
+temp_dir(const Context& ctx)
 {
   static const char* path = NULL;
   if (path) {
@@ -325,7 +325,7 @@ set_up_signal_handlers(void)
 #endif // _WIN32
 
 static void
-clean_up_internal_tempdir(Context& ctx)
+clean_up_internal_tempdir(const Context& ctx)
 {
   time_t now = time(NULL);
   auto st = Stat::stat(ctx.config.cache_dir(), Stat::OnError::log);
@@ -377,7 +377,7 @@ dump_debug_log_buffer_exitfn(void* context)
 }
 
 static void
-init_hash_debug(Context& ctx,
+init_hash_debug(const Context& ctx,
                 struct hash* hash,
                 const char* obj_path,
                 char type,
@@ -436,7 +436,7 @@ get_current_working_dir(void)
 }
 
 static bool
-do_remember_include_file(Context& ctx,
+do_remember_include_file(const Context& ctx,
                          std::string path,
                          struct hash* cpp_hash,
                          bool system,
@@ -626,7 +626,7 @@ print_included_files(FILE* fp)
 // Make a relative path from current working directory to path if path is under
 // the base directory.
 static std::string
-make_relative_path(Context& ctx, const char* path)
+make_relative_path(const Context& ctx, const char* path)
 {
   if (ctx.config.base_dir().empty()
       || !str_startswith(path, ctx.config.base_dir().c_str())) {
@@ -906,7 +906,7 @@ process_preprocessed_file(Context& ctx,
 
 // Replace absolute paths with relative paths in the provided dependency file.
 static void
-use_relative_paths_in_depfile(Context& ctx)
+use_relative_paths_in_depfile(const Context& ctx)
 {
   const char* depfile = ctx.args_info.output_dep.c_str();
 
@@ -1057,7 +1057,7 @@ send_cached_stderr(const char* path_stderr)
 
 // Create or update the manifest file.
 static void
-update_manifest_file(Context& ctx)
+update_manifest_file(const Context& ctx)
 {
   if (!ctx.config.direct_mode() || ctx.config.read_only()
       || ctx.config.read_only_direct()) {
@@ -1508,7 +1508,7 @@ get_result_name_from_cpp(Context& ctx, struct args* args, struct hash* hash)
 // Hash mtime or content of a file, or the output of a command, according to
 // the CCACHE_COMPILERCHECK setting.
 static void
-hash_compiler(Context& ctx,
+hash_compiler(const Context& ctx,
               struct hash* hash,
               const Stat& st,
               const char* path,
@@ -1542,7 +1542,7 @@ hash_compiler(Context& ctx,
 // with -ccbin/--compiler-bindir. If they are NULL, the compilers are looked up
 // in PATH instead.
 static void
-hash_nvcc_host_compiler(Context& ctx,
+hash_nvcc_host_compiler(const Context& ctx,
                         struct hash* hash,
                         const Stat* ccbin_st,
                         const char* ccbin)
@@ -1591,7 +1591,7 @@ hash_nvcc_host_compiler(Context& ctx,
 
 // Update a hash with information common for the direct and preprocessor modes.
 static void
-hash_common_info(Context& ctx,
+hash_common_info(const Context& ctx,
                  struct args* args,
                  struct hash* hash,
                  const ArgsInfo& args_info)
@@ -2048,7 +2048,7 @@ calculate_result_name(Context& ctx,
 // Try to return the compile result from cache. If we can return from cache
 // then this function exits with the correct status code, otherwise it returns.
 static void
-from_cache(Context& ctx,
+from_cache(const Context& ctx,
            enum fromcache_call_mode mode,
            bool put_result_in_manifest)
 {
@@ -2143,7 +2143,7 @@ from_cache(Context& ctx,
 // Find the real compiler. We just search the PATH to find an executable of the
 // same name that isn't a link to ourselves.
 static void
-find_compiler(Context& ctx, char** argv)
+find_compiler(const Context& ctx, char** argv)
 {
   // We might be being invoked like "ccache gcc -c foo.c".
   std::string base(Util::base_name(argv[0]));
@@ -3647,7 +3647,8 @@ cache_compilation(int argc, char* argv[])
     struct args* orig_args_for_execv = ctx.orig_args;
     exitfn_call();
     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));
+    fatal(
+      "execv of %s failed: %s", orig_args_for_execv->argv[0], strerror(errno));
   }
 }
 
index d127e8610ce2f27eab1bcaaea5a46a0ca827211d..bbf691a0fd2bd4c7e0120624dd2fc278a481e786 100644 (file)
@@ -85,7 +85,7 @@ create_writer(FILE* stream,
 }
 
 static void
-recompress_file(Context& ctx,
+recompress_file(const Context& ctx,
                 const std::string& stats_file,
                 const CacheFile& cache_file,
                 int8_t level)
@@ -200,7 +200,7 @@ compress_stats(const Config& config,
 }
 
 void
-compress_recompress(Context& ctx,
+compress_recompress(const Context& ctx,
                     int8_t level,
                     const Util::ProgressReceiver& progress_receiver)
 {
index 118bab51741768774ef37df6bb0fdde99392e0af..a2a397c4cc6ddcd063a815d9e303f909d3309c8b 100644 (file)
@@ -35,6 +35,6 @@ void compress_stats(const Config& config,
 // - level: Target compression level (positive or negative value), or 0 for no
 //   compression.
 // - progress_receiver: Function that will be called for progress updates.
-void compress_recompress(Context& ctx,
+void compress_recompress(const Context& ctx,
                          int8_t level,
                          const Util::ProgressReceiver& progress_receiver);
index d23bef65418d0c20f948a9aad987b1abba4bffca..ffbf53d313f349d8807451896d2c0cfdd78605e3 100644 (file)
@@ -306,7 +306,7 @@ execute(char** argv, int fd_out, int fd_err, pid_t* pid)
 // Find an executable by name in $PATH. Exclude any that are links to
 // exclude_name.
 char*
-find_executable(Context& ctx, const char* name, const char* exclude_name)
+find_executable(const Context& ctx, const char* name, const char* exclude_name)
 {
   if (is_absolute_path(name)) {
     return x_strdup(name);
index 73ffa13105fd843ecc29f62411b9454a55be9b0f..10702de5da0bc0045ccb2695a03abdda4f52a9df 100644 (file)
@@ -23,6 +23,7 @@
 struct Context;
 
 int execute(char** argv, int fd_out, int fd_err, pid_t* pid);
-char* find_executable(Context& ctx, const char* name, const char* exclude_name);
+char*
+find_executable(const Context& ctx, const char* name, const char* exclude_name);
 void print_command(FILE* fp, char** argv);
 char* format_command(const char* const* argv);
index 1168f4998c360143d96a3b2712537588c40b4045..df5026efebceec2392edaee9a4ced820154d449b 100644 (file)
@@ -285,7 +285,7 @@ hash_source_code_file(const Config& config, struct hash* hash, const char* path)
 }
 
 bool
-hash_command_output(Context& ctx,
+hash_command_output(const Context& ctx,
                     struct hash* hash,
                     const char* command,
                     const char* compiler)
@@ -431,7 +431,7 @@ hash_command_output(Context& ctx,
 }
 
 bool
-hash_multicommand_output(Context& ctx,
+hash_multicommand_output(const Context& ctx,
                          struct hash* hash,
                          const char* commands,
                          const char* compiler)
index 560fae20681113e2b9a2918c5a560f6ebfc0af39..ffde6a8df31c1e0ec811bc930899dfe20ae34052 100644 (file)
@@ -44,11 +44,11 @@ int hash_source_code_string(const Config& config,
 int hash_source_code_file(const Config& config,
                           struct hash* hash,
                           const char* path);
-bool hash_command_output(Context& ctx,
+bool hash_command_output(const Context& ctx,
                          struct hash* hash,
                          const char* command,
                          const char* compiler);
-bool hash_multicommand_output(Context& ctx,
+bool hash_multicommand_output(const Context& ctx,
                               struct hash* hash,
                               const char* command,
                               const char* compiler);
index 747b5bfa7f334e59fe2b1c66df4e9cfd8167e80d..0b6d0f03dc58bdcd3c561d780c7afc79469afde2 100644 (file)
@@ -94,7 +94,7 @@ const uint8_t k_embedded_file_marker = 0;
 // File stored as-is in the file system.
 const uint8_t k_raw_file_marker = 1;
 
-using ReadEntryFunction = void (*)(Context& ctx,
+using ReadEntryFunction = void (*)(const Context& ctx,
                                    CacheEntryReader& reader,
                                    const std::string& result_path_in_cache,
                                    uint32_t entry_number,
@@ -102,7 +102,7 @@ using ReadEntryFunction = void (*)(Context& ctx,
                                    FILE* dump_stream);
 
 using WriteEntryFunction =
-  void (*)(Context& ctx,
+  void (*)(const Context& ctx,
            CacheEntryWriter& writer,
            const std::string& result_path_in_cache,
            uint32_t entry_number,
@@ -138,7 +138,7 @@ UnderlyingFileTypeIntToString(UnderlyingFileTypeInt underlying_type)
 }
 
 static void
-read_embedded_file_entry(Context&,
+read_embedded_file_entry(const Context&,
                          CacheEntryReader& reader,
                          const std::string& /*result_path_in_cache*/,
                          uint32_t entry_number,
@@ -212,7 +212,7 @@ get_raw_file_path(const std::string& result_path_in_cache,
 }
 
 static bool
-copy_raw_file(Context& ctx,
+copy_raw_file(const Context& ctx,
               const std::string& source,
               const std::string& dest,
               bool to_cache)
@@ -239,7 +239,7 @@ copy_raw_file(Context& ctx,
 }
 
 static void
-read_raw_file_entry(Context& ctx,
+read_raw_file_entry(const Context& ctx,
                     CacheEntryReader& reader,
                     const std::string& result_path_in_cache,
                     uint32_t entry_number,
@@ -290,7 +290,7 @@ read_raw_file_entry(Context& ctx,
 }
 
 static bool
-read_result(Context& ctx,
+read_result(const Context& ctx,
             const std::string& path,
             const ResultFileMap* result_file_map,
             FILE* dump_stream)
@@ -343,7 +343,7 @@ read_result(Context& ctx,
 }
 
 static void
-write_embedded_file_entry(Context&,
+write_embedded_file_entry(const Context&,
                           CacheEntryWriter& writer,
                           const std::string& /*result_path_in_cache*/,
                           uint32_t entry_number,
@@ -383,7 +383,7 @@ write_embedded_file_entry(Context&,
 }
 
 static void
-write_raw_file_entry(Context& ctx,
+write_raw_file_entry(const Context& ctx,
                      CacheEntryWriter& writer,
                      const std::string& result_path_in_cache,
                      uint32_t entry_number,
@@ -444,7 +444,7 @@ should_store_raw_file(const Config& config, FileType type)
 }
 
 static void
-write_result(Context& ctx,
+write_result(const Context& ctx,
              const std::string& path,
              const ResultFileMap& result_file_map)
 {
@@ -484,7 +484,7 @@ write_result(Context& ctx,
 }
 
 bool
-result_get(Context& ctx,
+result_get(const Context& ctx,
            const std::string& path,
            const ResultFileMap& result_file_map)
 {
@@ -506,7 +506,7 @@ result_get(Context& ctx,
 }
 
 bool
-result_put(Context& ctx,
+result_put(const Context& ctx,
            const std::string& path,
            const ResultFileMap& result_file_map)
 {
@@ -522,7 +522,7 @@ result_put(Context& ctx,
 }
 
 bool
-result_dump(Context& ctx, const std::string& path, FILE* stream)
+result_dump(const Context& ctx, const std::string& path, FILE* stream)
 {
   assert(stream);
 
index 7ccb5edcae24032be470edac5ad3d0d79c38415a..4015cf6cbe44fd38d0e777b4402ef521ee9912f1 100644 (file)
@@ -46,10 +46,10 @@ enum class FileType : UnderlyingFileTypeInt {
 
 using ResultFileMap = std::map<FileType, std::string /*path*/>;
 
-bool result_get(Context& ctx,
+bool result_get(const Context& ctx,
                 const std::string& path,
                 const ResultFileMap& result_file_map);
-bool result_put(Context& ctx,
+bool result_put(const Context& ctx,
                 const std::string& path,
                 const ResultFileMap& result_file_map);
-bool result_dump(Context& ctx, const std::string& path, FILE* stream);
+bool result_dump(const Context& ctx, const std::string& path, FILE* stream);
index 5cf6eb0ad64dee33d0d41cf2bff88e7eab96ed38..c88d7713e1986bc0fed1fb995c3659d004c1b81c 100644 (file)
@@ -299,7 +299,7 @@ stats_collect(const Config& config,
 // Record that a number of bytes and files have been added to the cache. Size
 // is in bytes.
 void
-stats_update_size(Context& ctx,
+stats_update_size(const Context& ctx,
                   const std::string& sfile,
                   int64_t size,
                   int files)
index 1a0df5fcba325aed66cbdce148897ed7ee81494a..fb7a2e1745a6b553e845e56d52281c993804b5e9 100644 (file)
@@ -70,7 +70,7 @@ unsigned stats_get_pending(enum stats stat);
 void stats_zero(const Config& config);
 void stats_summary(const Config& config);
 void stats_print(const Config& config);
-void stats_update_size(Context& ctx,
+void stats_update_size(const Context& ctx,
                        const std::string& sfile,
                        int64_t size,
                        int files);