Add script to run menuconfig properly

This accounts for the fact that running menuconfig properly requires
that all of our compiler environment variables are set correctly.

BUG=None
TEST=```
~/cos/src/scripts/cos/menuconfig.sh
--kernel_tree=../third_party/kernel/v6.18 --arch=x86
--config=lakitu_defconfig
```
and
```
~/cos/src/scripts/cos/menuconfig.sh
--kernel_tree=../third_party/kernel/v6.18 --arch=arm64
--config=lakitu_defconfig
```
RELEASE_NOTE=None

Change-Id: I0d13b536c162ded1c758369781ec4951e3b02258
Reviewed-on: https://cos-review.googlesource.com/c/cos/scripts/+/144904
Reviewed-by: Robert Kolchmeyer <rkolchmeyer@google.com>
Tested-by: Kevin Berry <kpberry@google.com>
diff --git a/menuconfig.sh b/menuconfig.sh
new file mode 100755
index 0000000..407a427
--- /dev/null
+++ b/menuconfig.sh
@@ -0,0 +1,86 @@
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
+SCRIPT_ROOT=${SCRIPT_ROOT%cos}
+. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
+
+# Script must be run inside the chroot.
+restart_in_chroot_if_needed "$@"
+
+DEFINE_string kernel_tree "" \
+  "In-chroot path to the kernel tree."
+DEFINE_string arch "" \
+  "Architecture of the config."
+DEFINE_string config '' \
+  'Name of the config. The config is assumed to be in the arch/${arch}/configs directory.'
+DEFINE_string update_chroot '' \
+  'Whether or not to update the chroot before running menuconfig. Defaults to true.'
+
+# Parse command line.
+FLAGS "$@" || exit 1
+eval set -- "${FLAGS_ARGV}"
+
+switch_to_strict_mode
+
+menuconfig() {
+  local -r config=$1
+  local -r arch=$2
+
+  local tuple
+  case "${arch}" in
+    x86_64)
+      tuple=x86_64-cros-linux-gnu
+      ;;
+    arm64)
+      tuple=aarch64-cros-linux-gnu
+      ;;
+    *)
+      error "Unknown arch ${arch}"
+      return 1
+      ;;
+  esac
+
+  local build_dir
+  build_dir="$(mktemp -d)"
+  cp "${config}" "${build_dir}/.config"
+  make -C "${FLAGS_kernel_tree}" O="${build_dir}" ARCH="${arch}" \
+    CC="${tuple}-clang" LD="${tuple}-ld.lld" CROSS_COMPILE="${tuple}-" \
+    menuconfig
+  cp "${build_dir}/.config" "${config}"
+  rm -rf "${build_dir}"
+}
+
+main() {
+  if [[ -z "${FLAGS_kernel_tree}" ]]; then
+    error "Please provide a --kernel_tree value"
+    return 1
+  fi
+
+  local -r config_path="${FLAGS_kernel_tree}/arch/${FLAGS_arch}/configs/${FLAGS_config}"
+
+  # The arch used for the config path is not necessarily the one expected
+  # by the compiler.
+  local compiler_arch="${FLAGS_arch}"
+  if [[ "${FLAGS_arch}" == "x86" ]]; then
+    compiler_arch=x86_64
+  fi
+
+  if [[ "${FLAGS_update_chroot}" != "false" ]]; then
+    update_chroot
+  fi
+  menuconfig "${config_path}" "${compiler_arch}"
+}
+
+main "$@"