cronet import: add --git-origin-checkout-hook to run gclient

Running gclient in Copybara's git origin checkout is a bit tricky.
Copybara does a bare checkout which gclient does not support (and it
keeps the git dir speparate from the checkout dir). This checkout script
essentially reinitializes the git dir and runs a gclient sync on it.

Test: ./import_cronet.sh -n 108.0.5359.128 -l \
1cd27afdb8e5d057070c0961e04c490d2aca1aa0 -f

Change-Id: I2b78a7b8e0e1e9adc74175e90560a58a82b978ca
diff --git a/Cronet/tools/import/git_checkout_hook.sh b/Cronet/tools/import/git_checkout_hook.sh
new file mode 100755
index 0000000..48b737c
--- /dev/null
+++ b/Cronet/tools/import/git_checkout_hook.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+# Copyright 2023 Google Inc. All rights reserved.
+#
+# 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 to invoke copybara locally to import Cronet into Android.
+# Inputs:
+#  Environment:
+#   REV: The git revision to sync.
+set -e
+
+# HACK: Copybara does a bare checkout which gclient does not support.
+git init
+git remote add origin https://chromium.googlesource.com/chromium/src.git
+git fetch origin --depth=1 "${REV}"
+git reset --hard FETCH_HEAD
+
+# For some reason, gclient still likes to reference the repository name (src)
+# despite name being './'.
+ln -s . src
+gclient sync \
+    --no-history \
+    --nohooks \
+    --shallow \
+    --spec="solutions=[{'name':'./','managed':False,'url':'https://chromium.googlesource.com/chromium/src.git'}];target_os=['android']" \
+    --rev="${REV}"
+
+
diff --git a/Cronet/tools/import/import_cronet.sh b/Cronet/tools/import/import_cronet.sh
index eb82551..b71297c 100755
--- a/Cronet/tools/import/import_cronet.sh
+++ b/Cronet/tools/import/import_cronet.sh
@@ -66,6 +66,15 @@
     flags+=(--git-destination-url="file://${ANDROID_BUILD_TOP}/external/cronet")
     flags+=(--repo-timeout 3h)
 
+    # git_checkout_hook.sh reruns git clone and subsequently invokes gclient,
+    # so this can take a while.
+    flags+=(--commands-timeout 3h)
+
+    # Export _new_rev for use in git_checkout_hook.sh.
+    # Arguments are not supported for --git-origin-checkout-hook.
+    export REV="${_new_rev}"
+    flags+=(--git-origin-checkout-hook="${PWD}/git_checkout_hook.sh")
+
     if [ ! -z "${_force}" ]; then
         flags+=(--force)
     fi