]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
C++-ify ArgsInfo::debug_prefix_maps
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 2 May 2020 10:55:57 +0000 (12:55 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 5 May 2020 18:25:58 +0000 (20:25 +0200)
Makefile.in
dev.mk.in
src/ArgsInfo.cpp [deleted file]
src/ArgsInfo.hpp
src/argprocessing.cpp
src/ccache.cpp

index 9a69baaf4b5ade94f49f1cd370fca07185ef94aa..2ac06c80ebcdcbecf163f96d83d3c95607b4b749 100644 (file)
@@ -32,7 +32,6 @@ Q=$(if $(quiet),@)
 
 non_third_party_sources = \
     src/Args.cpp \
-    src/ArgsInfo.cpp \
     src/AtomicFile.cpp \
     src/CacheEntryReader.cpp \
     src/CacheEntryWriter.cpp \
index fd551d0ceb1bfa13b6f5a0630082baff0e096318..15af273cada7f719112fbebc96adcad4848c44f9 100644 (file)
--- a/dev.mk.in
+++ b/dev.mk.in
@@ -37,6 +37,7 @@ generated_docs = \
 built_dist_files = $(generated_sources) $(generated_docs)
 
 non_third_party_headers_without_cpp = \
+    src/ArgsInfo.hpp \
     src/Checksum.hpp \
     src/File.hpp \
     src/FormatNonstdStringView.hpp \
diff --git a/src/ArgsInfo.cpp b/src/ArgsInfo.cpp
deleted file mode 100644 (file)
index 180dafb..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
-//
-// See doc/AUTHORS.adoc for a complete list of contributors.
-//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by the Free
-// Software Foundation; either version 3 of the License, or (at your option)
-// any later version.
-//
-// This program is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-// more details.
-//
-// You should have received a copy of the GNU General Public License along with
-// this program; if not, write to the Free Software Foundation, Inc., 51
-// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-#include "ArgsInfo.hpp"
-
-ArgsInfo::~ArgsInfo()
-{
-  for (size_t i = 0; i < debug_prefix_maps_len; i++) {
-    free(debug_prefix_maps[i]);
-  }
-  free(debug_prefix_maps);
-}
index 5200304929c497bb038e5ee43dd910ba204af1f6..bbc1ce57f1c08279d25d517998faedb7321b81e2 100644 (file)
@@ -98,18 +98,8 @@ struct ArgsInfo
   std::vector<std::string> arch_args;
 
   // Relocating debuginfo in the format old=new.
-  char** debug_prefix_maps = nullptr;
-  size_t debug_prefix_maps_len = 0;
+  std::vector<std::string> debug_prefix_maps;
 
   // Argument list to add to compiler invocation in depend mode.
   Args depend_extra_args;
-
-  ArgsInfo() = default;
-  ~ArgsInfo();
-
-  ArgsInfo(const ArgsInfo&) = delete;
-  ArgsInfo& operator=(const ArgsInfo&) = delete;
-
-  ArgsInfo(ArgsInfo&&) = delete;
-  ArgsInfo& operator=(ArgsInfo&&) = delete;
 };
index 51f1a7bcc3454e782442999f23c108d2e880e9ac..85934699e7dbc4912bdfb0881f91b30ebd528209 100644 (file)
@@ -415,14 +415,10 @@ process_arg(Context& ctx,
     return nullopt;
   }
 
-  if (str_startswith(argv[i], "-fdebug-prefix-map=")
-      || str_startswith(argv[i], "-ffile-prefix-map=")) {
-    args_info.debug_prefix_maps = static_cast<char**>(
-      x_realloc(args_info.debug_prefix_maps,
-                (args_info.debug_prefix_maps_len + 1) * sizeof(char*)));
-    args_info.debug_prefix_maps[args_info.debug_prefix_maps_len++] =
-      x_strdup(&argv[i][argv[i][2] == 'f' ? 18 : 19]);
-    args_add(state.common_args, argv[i]);
+  if (Util::starts_with(arg, "-fdebug-prefix-map=")
+      || Util::starts_with(arg, "-ffile-prefix-map=")) {
+    args_info.debug_prefix_maps.push_back(arg.substr(arg.find('=') + 1));
+    state.common_args.push_back(arg);
     return nullopt;
   }
 
index ba5bdb23de5f48dcd2c4567b27a911a4caf60cdc..722de37e6312e6613ca7def71f737fbd996a7257 100644 (file)
@@ -1466,21 +1466,18 @@ hash_common_info(const Context& ctx,
   // Possibly hash the current working directory.
   if (args_info.generating_debuginfo && ctx.config.hash_dir()) {
     std::string dir_to_hash = ctx.apparent_cwd;
-    for (size_t i = 0; i < args_info.debug_prefix_maps_len; i++) {
-      char* map = args_info.debug_prefix_maps[i];
-      char* sep = strchr(map, '=');
-      if (sep) {
-        char* old_path = x_strndup(map, sep - map);
-        char* new_path = static_cast<char*>(x_strdup(sep + 1));
+    for (const auto& map : args_info.debug_prefix_maps) {
+      size_t sep_pos = map.find('=');
+      if (sep_pos != std::string::npos) {
+        std::string old_path = map.substr(0, sep_pos);
+        std::string new_path = map.substr(sep_pos + 1);
         cc_log("Relocating debuginfo from %s to %s (CWD: %s)",
-               old_path,
-               new_path,
+               old_path.c_str(),
+               new_path.c_str(),
                ctx.apparent_cwd.c_str());
         if (Util::starts_with(ctx.apparent_cwd, old_path)) {
-          dir_to_hash = new_path + ctx.apparent_cwd.substr(strlen(old_path));
+          dir_to_hash = new_path + ctx.apparent_cwd.substr(old_path.size());
         }
-        free(old_path);
-        free(new_path);
       }
     }
     cc_log("Hashing CWD %s", dir_to_hash.c_str());