]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Make handling of Clang config options more robust
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 17 Oct 2023 19:36:35 +0000 (21:36 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 21 Oct 2023 18:10:06 +0000 (20:10 +0200)
Closes #1335.

src/argprocessing.cpp
src/ccache.cpp

index b46ddf64b1e64622b79a539db968ea4100b97a41..22788cb9dca3e8bef166f71f4287b17db7ce9d22 100644 (file)
@@ -391,7 +391,9 @@ process_option_arg(const Context& ctx,
 
   // These are always too hard.
   if (compopt_too_hard(arg) || util::starts_with(arg, "-fdump-")
-      || util::starts_with(arg, "-MJ") || util::starts_with(arg, "-Yc")) {
+      || util::starts_with(arg, "-MJ") || util::starts_with(arg, "-Yc")
+      || util::starts_with(arg, "--config-system-dir=")
+      || util::starts_with(arg, "--config-user-dir=")) {
     LOG("Compiler option {} is unsupported", args[i]);
     return Statistic::unsupported_compiler_option;
   }
index e34c94b8c1017441f7bd2faf79d746673a191e80..71eefb4090a08bef6f8eae01ca895035504fd44f 100644 (file)
@@ -1743,6 +1743,14 @@ hash_argument(const Context& ctx,
     } else {
       path = args[i].substr(eq_pos + 1);
     }
+
+    if (args[i] == "--config" && path.find('/') == std::string::npos) {
+      // --config FILE without / in FILE: the file is searched for in Clang's
+      // user/system/executable directories.
+      LOG("Argument to compiler option {} is too hard", args[i]);
+      return tl::unexpected(Statistic::unsupported_compiler_option);
+    }
+
     DirEntry dir_entry(path, DirEntry::LogOnError::yes);
     if (dir_entry.is_regular_file()) {
       // If given an explicit specs file, then hash that file, but don't
@@ -1750,6 +1758,9 @@ hash_argument(const Context& ctx,
       hash.hash_delimiter("specs");
       TRY(hash_compiler(ctx, hash, dir_entry, path, false));
       return {};
+    } else {
+      LOG("While processing {}: {} is missing", args[i], path);
+      return tl::unexpected(Statistic::bad_compiler_arguments);
     }
   }
 
@@ -1801,12 +1812,16 @@ static tl::expected<std::optional<Hash::Digest>, Failure>
 get_manifest_key(Context& ctx, Hash& hash)
 {
   // Hash environment variables that affect the preprocessor output.
-  const char* envvars[] = {"CPATH",
-                           "C_INCLUDE_PATH",
-                           "CPLUS_INCLUDE_PATH",
-                           "OBJC_INCLUDE_PATH",
-                           "OBJCPLUS_INCLUDE_PATH", // clang
-                           nullptr};
+  const char* envvars[] = {
+    "CPATH",
+    "C_INCLUDE_PATH",
+    "CPLUS_INCLUDE_PATH",
+    "OBJC_INCLUDE_PATH",
+    "OBJCPLUS_INCLUDE_PATH",        // Clang
+    "CLANG_CONFIG_FILE_SYSTEM_DIR", // Clang
+    "CLANG_CONFIG_FILE_USER_DIR",   // Clang
+    nullptr,
+  };
   for (const char** p = envvars; *p; ++p) {
     const char* v = getenv(*p);
     if (v) {