cos_gpu_installer_v1: compile without -Werror=strict-prototypes

New LLVM versions changed the behavior of -Wstrict-prototypes. It now
shows diagnostics where it previously didn't. Since all kernel code
compiles with -Werror=strict-prototypes, nvidia drivers are compiled
with -Werror=strict-prototypes. As a result, the new -Wstrict-prototypes
behavior breaks nvidia driver compilation.

We can work around this by implementing a compiler wrapper that removes
-Werror=strict-prototypes from the compiler command line.

BUG=b/257271340
TEST=Compile 470 drivers on ToT
RELEASE_NOTE=None

Change-Id: I967d8ae16b934772fa2e576ebda19f51e8031604
Reviewed-on: https://cos-review.googlesource.com/c/cos/tools/+/41196
Reviewed-by: Meena Shanmugam <meenashanmugam@google.com>
Reviewed-by: Arnav Kansal <rnv@google.com>
Tested-by: Robert Kolchmeyer <rkolchmeyer@google.com>
Cloud-Build: GCB Service account <228075978874@cloudbuild.gserviceaccount.com>
diff --git a/src/cmd/cos_gpu_installer_v1/cos-gpu-installer-docker/entrypoint.sh b/src/cmd/cos_gpu_installer_v1/cos-gpu-installer-docker/entrypoint.sh
index 54d574c..3a4d6a9 100755
--- a/src/cmd/cos_gpu_installer_v1/cos-gpu-installer-docker/entrypoint.sh
+++ b/src/cmd/cos_gpu_installer_v1/cos-gpu-installer-docker/entrypoint.sh
@@ -344,8 +344,26 @@
 the nvidia installer."
   ln -sf x86_64-cros-linux-gnu-ld "${TOOLCHAIN_PKG_DIR}/bin/ld"
 
+  info "Creating a CC wrapper. Newer versions of LLVM have different \
+-Wstrict-prototypes behavior that impacts the nvidia installer. The kernel \
+always uses -Werror=strict-prototypes by default. This wrapper removes \
+-Werror=strict-prototypes from the CC command line."
+  mkdir /tmp/wrappers
+  cat <<EOF > "/tmp/wrappers/${CC}"
+#!/bin/bash
+for arg; do
+  shift
+  if [[ "\${arg}" == "-Werror=strict-prototypes" ]]; then continue; fi
+  set -- "\$@" "\${arg}"
+done
+exec ${TOOLCHAIN_PKG_DIR}/bin/${CC} \$@
+EOF
+  chmod a+x "/tmp/wrappers/${CC}"
+  info "Printing CC wrapper to stdout"
+  cat "/tmp/wrappers/${CC}"
+
   info "Configuring environment variables for cross-compilation"
-  export PATH="${TOOLCHAIN_PKG_DIR}/bin:${PATH}"
+  export PATH="/tmp/wrappers:${TOOLCHAIN_PKG_DIR}/bin:${PATH}"
   export SYSROOT="${TOOLCHAIN_PKG_DIR}/usr/x86_64-cros-linux-gnu"
 }