Update import_util.py to work from chrome/chrome_cleaner/internal

This prepares for a pending commit to the internal chrome_cleaner repo
which will delete the internal copy of import_util.py:

* Add separate GetChromiumRootDirectory and GetInternalRootDirectory
functions to clarify the ambiguous term "root directory" when called
from the internal repo mounted at //chrome/chrome_cleaner/internal.

* Move all the functions that depend on being called from inside the
chromium source tree to a separate import_paths.py script. (All the
current callers of these functions happen to be in
//chrome/chrome_cleaner/internal.)

* Delete code to find a local copy of find_depot_tools. It's no longer
supported to run this script without calling gclient sync, which will
update depot_tools.

R=​proberge

(cherry picked from commit 1673a55ce9dfd635d021fd5b238f8b147d3ccc70)

Bug: 1004848
Change-Id: I829851f332975c950f1dcde59735ee96f34f295e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2451810
Reviewed-by: proberge <[email protected]>
Commit-Queue: proberge <[email protected]>
Auto-Submit: Joe Mason <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#814390}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2458486
Reviewed-by: Joe Mason <[email protected]>
Commit-Queue: Joe Mason <[email protected]>
Cr-Commit-Position: refs/branch-heads/4280@{#94}
Cr-Branched-From: ea420fb963f9658c9969b6513c56b8f47efa1a2a-refs/heads/master@{#812852}
diff --git a/chrome/chrome_cleaner/tools/import_paths.py b/chrome/chrome_cleaner/tools/import_paths.py
new file mode 100644
index 0000000..634248fd
--- /dev/null
+++ b/chrome/chrome_cleaner/tools/import_paths.py
@@ -0,0 +1,53 @@
+# Copyright 2020 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Paths for python proto modules and depot_tools.
+
+This script must be used from inside a chromium checkout because it depends on
+paths relative to the root of the checkout.
+"""
+
+import import_util
+import os
+import sys
+
+
+# Expect this script to be located in <root_dir>/chrome/chrome_cleaner/tools.
+_CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
+_ROOT_DIRECTORY = os.path.normpath(os.path.join(_CURRENT_DIRECTORY, os.pardir,
+                                                os.pardir, os.pardir))
+assert(_CURRENT_DIRECTORY == os.path.join(_ROOT_DIRECTORY, 'chrome',
+                                          'chrome_cleaner', 'tools'))
+
+
+def GetBuildDirectory(build_configuration):
+  """Returns the path to the build directory relative to this file.
+
+  Args:
+    build_configuration: name of the build configuration whose directory
+        should be looked up, e.g. 'Debug' or 'Release'.
+  """
+  return os.path.join(_ROOT_DIRECTORY, 'out', build_configuration)
+
+
+def GetChromiumRootDirectory():
+  """Returns the path to root directory of the chromium checkout."""
+  return _ROOT_DIRECTORY
+
+
+def GetInternalRootDirectory():
+  """Returns the path to //chrome/chrome_cleaner/internal."""
+  return os.path.join(_ROOT_DIRECTORY, 'chrome', 'chrome_cleaner', 'internal')
+
+
+def AddDepotToolsToPath():
+  """Locates a depot_tools checkout and adds it to the Python import path.
+
+  Returns:
+    The path to depot_tools.
+  """
+
+  # Try to import find_depot_tools from the build subdir.
+  import_util.AddImportPath(os.path.join(_ROOT_DIRECTORY, 'build'))
+  import find_depot_tools
+  return find_depot_tools.add_depot_tools_to_path()
diff --git a/chrome/chrome_cleaner/tools/import_util.py b/chrome/chrome_cleaner/tools/import_util.py
index fa1858e..f89c5293 100644
--- a/chrome/chrome_cleaner/tools/import_util.py
+++ b/chrome/chrome_cleaner/tools/import_util.py
@@ -1,40 +1,17 @@
 # Copyright 2018 The Chromium Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
-"""Utilities for importing python proto modules."""
+"""Utilities for importing python scripts and proto modules."""
 
 import os
 import sys
 
 
-_CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
-_ROOT_DIRECTORY = os.path.join(_CURRENT_DIRECTORY, os.pardir, os.pardir)
-
-
-def _InSourceTree():
-  return os.path.basename(os.path.abspath(_ROOT_DIRECTORY)) == 'src'
-
-
 def AddImportPath(path):
   """Adds the given path to the front of the Python import path."""
   sys.path.insert(0, os.path.normpath(path))
 
 
-def GetBuildDirectory(build_configuration):
-  """Returns the path to the build directory relative to this file.
-
-  Args:
-    build_configuration: name of the build configuration whose directory
-        should be looked up, e.g. 'Debug' or 'Release'.
-
-  Returns:
-    Path to the build directory or None if used from outside the source tree.
-  """
-  if not _InSourceTree():
-    return None
-  return os.path.join(_ROOT_DIRECTORY, 'out', build_configuration)
-
-
 def AddProtosToPath(root_path):
   """Adds generated protobuf modules to the Python import path.
 
@@ -55,24 +32,3 @@
   AddImportPath(os.path.join(pyproto_dir, 'chrome', 'chrome_cleaner', 'proto'))
   AddImportPath(os.path.join(pyproto_dir, 'chrome', 'chrome_cleaner', 'logging',
                              'proto'))
-
-
-def AddDepotToolsToPath():
-  """Locates a depot_tools checkout and adds it to the Python import path.
-
-  Returns:
-    The path to depot_tools.
-  """
-
-  # Try to import the local copy of find_depot_tools from the import subdir, in
-  # case this is being run from a checkout that hasn't been synced.
-  AddImportPath(os.path.join(_CURRENT_DIRECTORY, 'import'))
-
-  # But prefer to use the copy synced into the build dir which might be more
-  # up-to-date. (This path will take priority over the path added above.)
-  if _InSourceTree():
-    AddImportPath(os.path.join(_ROOT_DIRECTORY, 'build'))
-
-  # Import the first copy of find_depot_tools found in the above paths.
-  import find_depot_tools
-  return find_depot_tools.add_depot_tools_to_path()