[clang] Add options to build with host compiler

On platforms for which no clang binaries are shipped, it can be useful
to reuse the scripts to build clang natively. However in this case, we
cannot download the previous clang version.

This adds --host-cc and --host-cxx options to use a host compiler to
build clang.

Change-Id: I31f431bc52a668f2613a2c57e23727f002581c5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3635499
Commit-Queue: Pierre Langlois <pierre.langlois@arm.com>
Reviewed-by: Arthur Eubanks <aeubanks@google.com>
Cr-Commit-Position: refs/heads/main@{#1005835}
NOKEYCHECK=True
GitOrigin-RevId: 7010f5ff5fb1ea292c7c7bb703ac5fee3d15846f
diff --git a/scripts/build.py b/scripts/build.py
index 3fc0b0e..b0d403e 100755
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -490,6 +490,12 @@
                       help='Build arm binaries. Only valid on macOS.')
   parser.add_argument('--disable-asserts', action='store_true',
                       help='build with asserts disabled')
+  parser.add_argument('--host-cc',
+                      help='build with host C compiler, requires --host-cxx as '
+                      'well')
+  parser.add_argument('--host-cxx',
+                      help='build with host C++ compiler, requires --host-cc '
+                      'as well')
   parser.add_argument('--gcc-toolchain', help='what gcc toolchain to use for '
                       'building; --gcc-toolchain=/opt/foo picks '
                       '/opt/foo/bin/gcc')
@@ -664,12 +670,18 @@
 
   if sys.platform.startswith('linux'):
     MaybeDownloadHostGcc(args)
-    DownloadPinnedClang()
-    cc = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang')
-    cxx = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang++')
-    # Use the libraries in the specified gcc installation for building.
-    cflags.append('--gcc-toolchain=' + args.gcc_toolchain)
-    cxxflags.append('--gcc-toolchain=' + args.gcc_toolchain)
+    if args.host_cc or args.host_cxx:
+      assert args.host_cc and args.host_cxx, \
+             "--host-cc and --host-cxx need to be used together"
+      cc = args.host_cc
+      cxx = args.host_cxx
+    else:
+      DownloadPinnedClang()
+      cc = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang')
+      cxx = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang++')
+      # Use the libraries in the specified gcc installation for building.
+      cflags.append('--gcc-toolchain=' + args.gcc_toolchain)
+      cxxflags.append('--gcc-toolchain=' + args.gcc_toolchain)
     base_cmake_args += [
         # The host clang has lld.
         '-DLLVM_ENABLE_LLD=ON',