[infra] Fix GN build with rpmalloc and latest Clang.

Latest Clang will now complain when the `-funit-at-a-time` optimization flag,
used by the rpmalloc build, is being used. The error message looks like:

```
.....
clang-15: error: optimization flag '-funit-at-a-time' is not supported [-Werror,-Wignored-optimization-argument]
```

This CL locally patches the rpmalloc `build/ninja/clang.py` file to add
the `-Wno-ignored-optimization-argument` flag to avoid this. This is a
temporary fix until the issue is fixed in upstream rpmalloc.

Bug: None
Change-Id: I7e3af4222a1813219843d532d61d8c2babe9b86f
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/13581
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
diff --git a/infra/recipes/gn.expected/ci_linux.json b/infra/recipes/gn.expected/ci_linux.json
index 8457f94..a7001a6 100644
--- a/infra/recipes/gn.expected/ci_linux.json
+++ b/infra/recipes/gn.expected/ci_linux.json
@@ -235,6 +235,68 @@
     ]
   },
   {
+    "cmd": [
+      "vpython",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py",
+      "/path/to/tmp/"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "gn:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "rpmalloc.read [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']@@@",
+      "@@@STEP_LOG_END@clang.py@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "vpython",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "gn:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "rpmalloc.write [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']@@@",
+      "@@@STEP_LOG_END@clang.py@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "rpmalloc.build rpmalloc-linux-amd64",
     "~followup_annotations": [
diff --git a/infra/recipes/gn.expected/cipd_exists.json b/infra/recipes/gn.expected/cipd_exists.json
index 7ed384a..6094333 100644
--- a/infra/recipes/gn.expected/cipd_exists.json
+++ b/infra/recipes/gn.expected/cipd_exists.json
@@ -235,6 +235,68 @@
     ]
   },
   {
+    "cmd": [
+      "vpython",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py",
+      "/path/to/tmp/"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "infra-internal:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "rpmalloc.read [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']@@@",
+      "@@@STEP_LOG_END@clang.py@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "vpython",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "infra-internal:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "rpmalloc.write [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']@@@",
+      "@@@STEP_LOG_END@clang.py@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "rpmalloc.build rpmalloc-linux-amd64",
     "~followup_annotations": [
diff --git a/infra/recipes/gn.expected/cipd_register.json b/infra/recipes/gn.expected/cipd_register.json
index f0b7372..9420990 100644
--- a/infra/recipes/gn.expected/cipd_register.json
+++ b/infra/recipes/gn.expected/cipd_register.json
@@ -235,6 +235,68 @@
     ]
   },
   {
+    "cmd": [
+      "vpython",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py",
+      "/path/to/tmp/"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "infra-internal:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "rpmalloc.read [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']@@@",
+      "@@@STEP_LOG_END@clang.py@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "vpython",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "infra-internal:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "rpmalloc.write [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']@@@",
+      "@@@STEP_LOG_END@clang.py@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "rpmalloc.build rpmalloc-linux-amd64",
     "~followup_annotations": [
diff --git a/infra/recipes/gn.expected/cq_linux.json b/infra/recipes/gn.expected/cq_linux.json
index 1181b8c..9f6943e 100644
--- a/infra/recipes/gn.expected/cq_linux.json
+++ b/infra/recipes/gn.expected/cq_linux.json
@@ -286,6 +286,68 @@
     ]
   },
   {
+    "cmd": [
+      "vpython",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py",
+      "/path/to/tmp/"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "gn:try"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "rpmalloc.read [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']@@@",
+      "@@@STEP_LOG_END@clang.py@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "vpython",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "gn:try"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "rpmalloc.write [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']@@@",
+      "@@@STEP_LOG_END@clang.py@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "rpmalloc.build rpmalloc-linux-amd64",
     "~followup_annotations": [
diff --git a/infra/recipes/gn.py b/infra/recipes/gn.py
index 19a3033..011d4b0 100644
--- a/infra/recipes/gn.py
+++ b/infra/recipes/gn.py
@@ -202,6 +202,19 @@
               ['git', 'fetch', '--tags', RPMALLOC_GIT_URL, RPMALLOC_BRANCH])
           api.step('checkout', ['git', 'checkout', RPMALLOC_REVISION])
 
+        # Patch configure.py since to add -Wno-ignored-optimization-flag since
+        # Clang will now complain when `-funit-at-a-time` is being used.
+        build_ninja_clang_path = api.path.join(rpmalloc_src_dir, 'build/ninja/clang.py')
+        build_ninja_clang_py = api.file.read_text('read %s' % build_ninja_clang_path,
+                                                 build_ninja_clang_path,
+                                                 "CXXFLAGS = ['-Wall', '-Weverything', '-Wfoo']")
+        build_ninja_clang_py = build_ninja_clang_py.replace(
+            "'-Wno-disabled-macro-expansion'",
+            "'-Wno-disabled-macro-expansion', '-Wno-ignored-optimization-argument'")
+        api.file.write_text('write %s' % build_ninja_clang_path,
+                            build_ninja_clang_path,
+                            build_ninja_clang_py)
+
         for platform in all_config_platforms:
           # Convert target architecture and os to rpmalloc format.
           rpmalloc_os, rpmalloc_arch = platform.split('-')