GN: Use the hermetic XCode if available.

This matches Chromium's logic and make it less likely to break developer
workflow in the subsequent roll of Chromium's buildtools.

Bug: dawn:339
Change-Id: Ic42553827be125985a3d16b4f5d003b6662ead39
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/16520
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/build_overrides/build.gni b/build_overrides/build.gni
index 1acd4a1..9bb8713 100644
--- a/build_overrides/build.gni
+++ b/build_overrides/build.gni
@@ -12,16 +12,35 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Tell Dawn and dependencies to not do Chromium-specific things
-build_with_chromium = false
+declare_args() {
+  # Tell Dawn and dependencies to not do Chromium-specific things
+  build_with_chromium = false
 
-# Use Chromium's binutils to have "hermetic" builds on bots
-linux_use_bundled_binutils_override = true
+  # Use Chromium's binutils to have "hermetic" builds on bots
+  linux_use_bundled_binutils_override = true
 
-# In standalone Dawn builds, don't try to use the hermetic install of Xcode
-# that Chromium uses
-use_system_xcode = true
+  # In standalone Dawn builds, don't try to use the hermetic install of Xcode
+  # that Chromium uses
+  use_system_xcode = ""
 
-# Android 32-bit non-component, non-clang builds cannot have symbol_level=2
-# due to 4GiB file size limit, see https://crbug.com/648948.
-ignore_elf32_limitations = false
+  # Android 32-bit non-component, non-clang builds cannot have symbol_level=2
+  # due to 4GiB file size limit, see https://crbug.com/648948.
+  ignore_elf32_limitations = false
+}
+
+# Detect whether we can use the hermetic XCode like in Chromium and do so if
+# possible.
+if (host_os == "mac" && use_system_xcode == "") {
+  _result = exec_script("//build/mac/should_use_hermetic_xcode.py",
+                        [ target_os ],
+                        "value")
+
+  assert(_result != 2,
+         "Do not allow building targets with the default" +
+             "hermetic toolchain if the minimum OS version is not met.")
+  assert(_result != 3,
+         "iOS does not support building with a hermetic toolchain. " +
+             "Please install Xcode.")
+
+  use_system_xcode = _result != 1
+}