Commit 1673a55c authored by Joe Mason's avatar Joe Mason Committed by Commit Bot

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

Bug: 1004848
Change-Id: I829851f332975c950f1dcde59735ee96f34f295e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2451810Reviewed-by: default avatarproberge <proberge@chromium.org>
Commit-Queue: proberge <proberge@chromium.org>
Auto-Submit: Joe Mason <joenotcharles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814390}
parent 415c28cd
# 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()
# 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 @@ def AddProtosToPath(root_path):
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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment