From fca672cdbb51f5d48afaf98e7c6de765c962c2bf Mon Sep 17 00:00:00 2001
From: Junji Watanabe <jwata@google.com>
Date: Mon, 28 Nov 2022 14:29:05 +0000
Subject: [PATCH] [build/android] Replace references to
 third_party/depot_tools/{ninja, gn}

ninja and gn are installed by DEPS. Calling them directly is better than using depot_tools/{ninja, gn} wrappers.

Bug: 1338373
Change-Id: I4097c01e0ddfc63a4745a809c083086e418014f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4060328
Auto-Submit: Junji Watanabe <jwata@google.com>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1076192}
---
 build/android/gyp/nocompile_test.py           |  4 ++--
 build/android/list_java_targets.py            | 20 +++++++++++++------
 .../incremental_javac_test_android_library.py |  4 ++--
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/build/android/gyp/nocompile_test.py b/build/android/gyp/nocompile_test.py
index da88504ff1f83..c3b02d2c961f8 100755
--- a/build/android/gyp/nocompile_test.py
+++ b/build/android/gyp/nocompile_test.py
@@ -13,10 +13,10 @@ import sys
 from util import build_utils
 
 _CHROMIUM_SRC = os.path.normpath(os.path.join(__file__, '..', '..', '..', '..'))
-_NINJA_PATH = os.path.join(_CHROMIUM_SRC, 'third_party', 'depot_tools', 'ninja')
+_NINJA_PATH = os.path.join(_CHROMIUM_SRC, 'third_party', 'ninja', 'ninja')
 
 # Relative to _CHROMIUM_SRC
-_GN_SRC_REL_PATH = os.path.join('third_party', 'depot_tools', 'gn')
+_GN_SRC_REL_PATH = os.path.join('buildtools', 'linux64', 'gn')
 
 # Regex for determining whether compile failed because 'gn gen' needs to be run.
 _GN_GEN_REGEX = re.compile(r'ninja: (error|fatal):')
diff --git a/build/android/list_java_targets.py b/build/android/list_java_targets.py
index 5390957592797..78e849a5b4772 100755
--- a/build/android/list_java_targets.py
+++ b/build/android/list_java_targets.py
@@ -54,17 +54,25 @@ _VALID_TYPES = (
 )
 
 
-def _resolve_ninja(cmd):
+def _resolve_ninja():
   # Prefer the version on PATH, but fallback to known version if PATH doesn't
   # have one (e.g. on bots).
-  if shutil.which(cmd) is None:
-    return os.path.join(_SRC_ROOT, 'third_party', 'depot_tools', cmd)
-  return cmd
+  if shutil.which('ninja') is None:
+    return os.path.join(_SRC_ROOT, 'third_party', 'ninja', 'ninja')
+  return 'ninja'
+
+
+def _resolve_autoninja():
+  # Prefer the version on PATH, but fallback to known version if PATH doesn't
+  # have one (e.g. on bots).
+  if shutil.which('autoninja') is None:
+    return os.path.join(_SRC_ROOT, 'third_party', 'depot_tools', 'autoninja')
+  return 'autoninja'
 
 
 def _run_ninja(output_dir, args, quiet=False):
   cmd = [
-      _resolve_ninja('autoninja'),
+      _resolve_autoninja(),
       '-C',
       output_dir,
   ]
@@ -80,7 +88,7 @@ def _query_for_build_config_targets(output_dir):
   # Query ninja rather than GN since it's faster.
   # Use ninja rather than autoninja to avoid extra output if user has set the
   # NINJA_SUMMARIZE_BUILD environment variable.
-  cmd = [_resolve_ninja('ninja'), '-C', output_dir, '-t', 'targets']
+  cmd = [_resolve_ninja(), '-C', output_dir, '-t', 'targets']
   logging.info('Running: %r', cmd)
   ninja_output = subprocess.run(cmd,
                                 check=True,
diff --git a/build/android/test/incremental_javac_gn/incremental_javac_test_android_library.py b/build/android/test/incremental_javac_gn/incremental_javac_test_android_library.py
index 117592f290342..640745086cbb6 100755
--- a/build/android/test/incremental_javac_gn/incremental_javac_test_android_library.py
+++ b/build/android/test/incremental_javac_gn/incremental_javac_test_android_library.py
@@ -16,10 +16,10 @@ import subprocess
 import shutil
 
 _CHROMIUM_SRC = pathlib.Path(__file__).resolve().parents[4].resolve()
-_NINJA_PATH = _CHROMIUM_SRC / 'third_party' / 'depot_tools' / 'ninja'
+_NINJA_PATH = _CHROMIUM_SRC / 'third_party' / 'ninja' / 'ninja'
 
 # Relative to _CHROMIUM_SRC
-_GN_SRC_REL_PATH = 'third_party/depot_tools/gn'
+_GN_SRC_REL_PATH = 'buildtools/linux64/gn'
 
 _USING_PARTIAL_JAVAC_MSG = 'Using partial javac optimization'