[infra] Fix rpmalloc linking.

The rpmalloc configure.py script forces the '-Weverything` flag
which conflicts with more recent default C standard used by recent
Clang rolls (see associated bug with details). This results in
compilation failures.

We may be able to convince upstream to do the change themselves
but this is a temporary solution until this happens.

Bug: 278
Change-Id: I4ee10d1e10dc39b2a903cee0e1407ecc14b58ec7
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/13140
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 128c0e6..e63326d 100644
--- a/infra/recipes/gn.expected/ci_linux.json
+++ b/infra/recipes/gn.expected/ci_linux.json
@@ -139,6 +139,44 @@
     ]
   },
   {
+    "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,
+    "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',  '-Wfoo']",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py"
+    ],
+    "infra_step": true,
+    "name": "rpmalloc.write [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall',  '-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 9d2811d..0a5dba9 100644
--- a/infra/recipes/gn.expected/cipd_exists.json
+++ b/infra/recipes/gn.expected/cipd_exists.json
@@ -139,6 +139,44 @@
     ]
   },
   {
+    "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,
+    "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',  '-Wfoo']",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py"
+    ],
+    "infra_step": true,
+    "name": "rpmalloc.write [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall',  '-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 425046a..b5e173a 100644
--- a/infra/recipes/gn.expected/cipd_register.json
+++ b/infra/recipes/gn.expected/cipd_register.json
@@ -139,6 +139,44 @@
     ]
   },
   {
+    "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,
+    "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',  '-Wfoo']",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py"
+    ],
+    "infra_step": true,
+    "name": "rpmalloc.write [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall',  '-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 4e32325..daea41e 100644
--- a/infra/recipes/gn.expected/cq_linux.json
+++ b/infra/recipes/gn.expected/cq_linux.json
@@ -166,6 +166,44 @@
     ]
   },
   {
+    "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,
+    "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',  '-Wfoo']",
+      "[START_DIR]/rpmalloc/build/ninja/clang.py"
+    ],
+    "infra_step": true,
+    "name": "rpmalloc.write [START_DIR]/rpmalloc/build/ninja/clang.py",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@clang.py@CXXFLAGS = ['-Wall',  '-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 6ba79ae..e8fcff1 100644
--- a/infra/recipes/gn.py
+++ b/infra/recipes/gn.py
@@ -198,6 +198,19 @@
               ['git', 'fetch', '--tags', RPMALLOC_GIT_URL, RPMALLOC_REVISION])
           api.step('checkout', ['git', 'checkout', 'FETCH_HEAD'])
 
+        # Patch configure.py since it forces -Weverything which conflicts
+        # with recent Clang rolls. Remove it in-place to work around the issue.
+        # See https://bugs.chromium.org/p/gn/issues/detail?id=278
+        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']")
+        if '-Weverything' in build_ninja_clang_py:
+          build_ninja_clang_py = build_ninja_clang_py.replace("'-Weverything',", '')
+          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('-')