]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Simplify detect_pch
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 3 May 2020 07:23:40 +0000 (09:23 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 5 May 2020 18:25:58 +0000 (20:25 +0200)
src/argprocessing.cpp

index 542bd4df824205817306486858cb38c753ec0488..f665f135958edd98da343ff4728aeba15a0825fd 100644 (file)
@@ -103,22 +103,11 @@ detect_pch(Context& ctx,
       pch_file = arg;
     }
   } else {
-    std::string gch_path = fmt::format("{}.gch", arg);
-    if (Stat::stat(gch_path)) {
-      cc_log("Detected use of precompiled header: %s", gch_path.c_str());
-      pch_file = gch_path;
-    } else {
-      std::string pch_path = fmt::format("{}.pch", arg);
-      if (Stat::stat(pch_path)) {
-        cc_log("Detected use of precompiled header: %s", pch_path.c_str());
-        pch_file = pch_path;
-      } else {
-        // Clang may use pretokenized headers.
-        std::string pth_path = fmt::format("{}.pth", arg);
-        if (Stat::stat(pth_path)) {
-          cc_log("Detected use of pretokenized header: %s", pth_path.c_str());
-          pch_file = pth_path;
-        }
+    for (const auto& extension : {".gch", ".pch", ".pth"}) {
+      std::string path = arg + extension;
+      if (Stat::stat(path)) {
+        cc_log("Detected use of precompiled header: %s", path.c_str());
+        pch_file = path;
       }
     }
   }