Use explicit path for libtool rather than implicit invocation of xcrun.

libtool is part of the default path at /usr/bin/libtool. That binary is just a
shim that calls out to xcrun to find the actual libtool. If we're using hermetic
xcode, then we can explicitly specify the path to avoid invoking xcrun.

Bug: 971452
Change-Id: If9344a244160ccc43895cf913d48f9c9a44ac5d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1648836
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#666906}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 1f49775ab209ba5668029cdffe63f40ce5e98668
diff --git a/mac/BUILD.gn b/mac/BUILD.gn
index efba8b3..3de0b92 100644
--- a/mac/BUILD.gn
+++ b/mac/BUILD.gn
@@ -262,7 +262,17 @@
       # corrupted by this process. Don't use spaces for source files or labels.
       rspfile = "{{output}}.rsp"
       rspfile_content = "{{inputs_newline}}"
-      command = "$env_wrapper rm -f {{output}} && TOOL_VERSION=${tool_versions.filter_libtool} python $script libtool -static {{arflags}} -o {{output}} -filelist $rspfile"
+
+      # libtool is part of the default path at /usr/bin/libtool. That binary is
+      # just a shim that calls out to xcrun to find the actual libtool. If we're
+      # using hermetic xcode, then we can explicitly specify the path to avoid
+      # invoking xcrun.
+      if (use_system_xcode) {
+        libtool = "libtool"
+      } else {
+        libtool = "$hermetic_xcode_path/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool"
+      }
+      command = "$env_wrapper rm -f {{output}} && TOOL_VERSION=${tool_versions.filter_libtool} python $script $libtool -static {{arflags}} -o {{output}} -filelist $rspfile"
       description = "LIBTOOL-STATIC {{output}}"
       outputs = [
         "{{output_dir}}/{{target_output_name}}{{output_extension}}",