mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
switch to 4 space indent
Leave the recipes/ code at 2 space to match the rest of the recipes
project in other repos.
Reformatted using:
files=( $(
git ls-tree -r --name-only HEAD | \
grep -Ev -e '^(third_party|recipes)/' | \
grep '\.py$';
git grep -l '#!/usr/bin/env.*python' | grep -v '\.py$'
) )
parallel ./yapf -i -- "${files[@]}"
~/chromiumos/chromite/contrib/reflow_overlong_comments "${files[@]}"
The files that still had strings that were too long were manually
reformatted because they were easy and only a few issues.
autoninja.py
clang_format.py
download_from_google_storage.py
fix_encoding.py
gclient_utils.py
git_cache.py
git_common.py
git_map_branches.py
git_reparent_branch.py
gn.py
my_activity.py
owners_finder.py
presubmit_canned_checks.py
reclient_helper.py
reclientreport.py
roll_dep.py
rustfmt.py
siso.py
split_cl.py
subcommand.py
subprocess2.py
swift_format.py
upload_to_google_storage.py
These files still had lines (strings) that were too long, so the pylint
warnings were suppressed with a TODO.
auth.py
gclient.py
gclient_eval.py
gclient_paths.py
gclient_scm.py
gerrit_util.py
git_cl.py
presubmit_canned_checks.py
presubmit_support.py
scm.py
Change-Id: Ia6535c4f2c48d46b589ec1e791dde6c6b2ea858f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4836379
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
This commit is contained in:
207
gclient_paths.py
207
gclient_paths.py
@@ -15,136 +15,139 @@ import sys
|
||||
import gclient_utils
|
||||
import subprocess2
|
||||
|
||||
# TODO: Should fix these warnings.
|
||||
# pylint: disable=line-too-long
|
||||
|
||||
|
||||
def FindGclientRoot(from_dir, filename='.gclient'):
|
||||
"""Tries to find the gclient root."""
|
||||
real_from_dir = os.path.abspath(from_dir)
|
||||
path = real_from_dir
|
||||
while not os.path.exists(os.path.join(path, filename)):
|
||||
split_path = os.path.split(path)
|
||||
if not split_path[1]:
|
||||
return None
|
||||
path = split_path[0]
|
||||
"""Tries to find the gclient root."""
|
||||
real_from_dir = os.path.abspath(from_dir)
|
||||
path = real_from_dir
|
||||
while not os.path.exists(os.path.join(path, filename)):
|
||||
split_path = os.path.split(path)
|
||||
if not split_path[1]:
|
||||
return None
|
||||
path = split_path[0]
|
||||
|
||||
logging.info('Found gclient root at ' + path)
|
||||
logging.info('Found gclient root at ' + path)
|
||||
|
||||
if path == real_from_dir:
|
||||
return path
|
||||
if path == real_from_dir:
|
||||
return path
|
||||
|
||||
# If we did not find the file in the current directory, make sure we are in a
|
||||
# sub directory that is controlled by this configuration.
|
||||
entries_filename = os.path.join(path, filename + '_entries')
|
||||
if not os.path.exists(entries_filename):
|
||||
# If .gclient_entries does not exist, a previous call to gclient sync
|
||||
# might have failed. In that case, we cannot verify that the .gclient
|
||||
# is the one we want to use. In order to not to cause too much trouble,
|
||||
# just issue a warning and return the path anyway.
|
||||
print(
|
||||
"%s missing, %s file in parent directory %s might not be the file "
|
||||
"you want to use." % (entries_filename, filename, path),
|
||||
file=sys.stderr)
|
||||
return path
|
||||
# If we did not find the file in the current directory, make sure we are in
|
||||
# a sub directory that is controlled by this configuration.
|
||||
entries_filename = os.path.join(path, filename + '_entries')
|
||||
if not os.path.exists(entries_filename):
|
||||
# If .gclient_entries does not exist, a previous call to gclient sync
|
||||
# might have failed. In that case, we cannot verify that the .gclient
|
||||
# is the one we want to use. In order to not to cause too much trouble,
|
||||
# just issue a warning and return the path anyway.
|
||||
print(
|
||||
"%s missing, %s file in parent directory %s might not be the file "
|
||||
"you want to use." % (entries_filename, filename, path),
|
||||
file=sys.stderr)
|
||||
return path
|
||||
|
||||
entries_content = gclient_utils.FileRead(entries_filename)
|
||||
scope = {}
|
||||
try:
|
||||
exec(entries_content, scope)
|
||||
except (SyntaxError, Exception) as e:
|
||||
gclient_utils.SyntaxErrorToError(filename, e)
|
||||
entries_content = gclient_utils.FileRead(entries_filename)
|
||||
scope = {}
|
||||
try:
|
||||
exec(entries_content, scope)
|
||||
except (SyntaxError, Exception) as e:
|
||||
gclient_utils.SyntaxErrorToError(filename, e)
|
||||
|
||||
all_directories = scope['entries'].keys()
|
||||
path_to_check = os.path.relpath(real_from_dir, path)
|
||||
while path_to_check:
|
||||
if path_to_check in all_directories:
|
||||
return path
|
||||
path_to_check = os.path.dirname(path_to_check)
|
||||
all_directories = scope['entries'].keys()
|
||||
path_to_check = os.path.relpath(real_from_dir, path)
|
||||
while path_to_check:
|
||||
if path_to_check in all_directories:
|
||||
return path
|
||||
path_to_check = os.path.dirname(path_to_check)
|
||||
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
def GetPrimarySolutionPath():
|
||||
"""Returns the full path to the primary solution. (gclient_root + src)"""
|
||||
"""Returns the full path to the primary solution. (gclient_root + src)"""
|
||||
|
||||
gclient_root = FindGclientRoot(os.getcwd())
|
||||
if gclient_root:
|
||||
# Some projects' top directory is not named 'src'.
|
||||
source_dir_name = GetGClientPrimarySolutionName(gclient_root) or 'src'
|
||||
return os.path.join(gclient_root, source_dir_name)
|
||||
gclient_root = FindGclientRoot(os.getcwd())
|
||||
if gclient_root:
|
||||
# Some projects' top directory is not named 'src'.
|
||||
source_dir_name = GetGClientPrimarySolutionName(gclient_root) or 'src'
|
||||
return os.path.join(gclient_root, source_dir_name)
|
||||
|
||||
# Some projects might not use .gclient. Try to see whether we're in a git
|
||||
# checkout that contains a 'buildtools' subdir.
|
||||
top_dir = os.getcwd()
|
||||
try:
|
||||
top_dir = subprocess2.check_output(['git', 'rev-parse', '--show-toplevel'],
|
||||
stderr=subprocess2.DEVNULL)
|
||||
top_dir = top_dir.decode('utf-8', 'replace')
|
||||
top_dir = os.path.normpath(top_dir.strip())
|
||||
except subprocess2.CalledProcessError:
|
||||
pass
|
||||
# Some projects might not use .gclient. Try to see whether we're in a git
|
||||
# checkout that contains a 'buildtools' subdir.
|
||||
top_dir = os.getcwd()
|
||||
try:
|
||||
top_dir = subprocess2.check_output(
|
||||
['git', 'rev-parse', '--show-toplevel'], stderr=subprocess2.DEVNULL)
|
||||
top_dir = top_dir.decode('utf-8', 'replace')
|
||||
top_dir = os.path.normpath(top_dir.strip())
|
||||
except subprocess2.CalledProcessError:
|
||||
pass
|
||||
|
||||
if os.path.exists(os.path.join(top_dir, 'buildtools')):
|
||||
return top_dir
|
||||
return None
|
||||
if os.path.exists(os.path.join(top_dir, 'buildtools')):
|
||||
return top_dir
|
||||
return None
|
||||
|
||||
|
||||
def GetBuildtoolsPath():
|
||||
"""Returns the full path to the buildtools directory.
|
||||
"""Returns the full path to the buildtools directory.
|
||||
This is based on the root of the checkout containing the current directory."""
|
||||
|
||||
# Overriding the build tools path by environment is highly unsupported and may
|
||||
# break without warning. Do not rely on this for anything important.
|
||||
override = os.environ.get('CHROMIUM_BUILDTOOLS_PATH')
|
||||
if override is not None:
|
||||
return override
|
||||
# Overriding the build tools path by environment is highly unsupported and
|
||||
# may break without warning. Do not rely on this for anything important.
|
||||
override = os.environ.get('CHROMIUM_BUILDTOOLS_PATH')
|
||||
if override is not None:
|
||||
return override
|
||||
|
||||
primary_solution = GetPrimarySolutionPath()
|
||||
if not primary_solution:
|
||||
return None
|
||||
|
||||
buildtools_path = os.path.join(primary_solution, 'buildtools')
|
||||
if os.path.exists(buildtools_path):
|
||||
return buildtools_path
|
||||
|
||||
# buildtools may be in the gclient root.
|
||||
gclient_root = FindGclientRoot(os.getcwd())
|
||||
buildtools_path = os.path.join(gclient_root, 'buildtools')
|
||||
if os.path.exists(buildtools_path):
|
||||
return buildtools_path
|
||||
|
||||
primary_solution = GetPrimarySolutionPath()
|
||||
if not primary_solution:
|
||||
return None
|
||||
|
||||
buildtools_path = os.path.join(primary_solution, 'buildtools')
|
||||
if os.path.exists(buildtools_path):
|
||||
return buildtools_path
|
||||
|
||||
# buildtools may be in the gclient root.
|
||||
gclient_root = FindGclientRoot(os.getcwd())
|
||||
buildtools_path = os.path.join(gclient_root, 'buildtools')
|
||||
if os.path.exists(buildtools_path):
|
||||
return buildtools_path
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def GetBuildtoolsPlatformBinaryPath():
|
||||
"""Returns the full path to the binary directory for the current platform."""
|
||||
buildtools_path = GetBuildtoolsPath()
|
||||
if not buildtools_path:
|
||||
return None
|
||||
"""Returns the full path to the binary directory for the current platform."""
|
||||
buildtools_path = GetBuildtoolsPath()
|
||||
if not buildtools_path:
|
||||
return None
|
||||
|
||||
if sys.platform.startswith(('cygwin', 'win')):
|
||||
subdir = 'win'
|
||||
elif sys.platform == 'darwin':
|
||||
subdir = 'mac'
|
||||
elif sys.platform.startswith('linux'):
|
||||
subdir = 'linux64'
|
||||
else:
|
||||
raise gclient_utils.Error('Unknown platform: ' + sys.platform)
|
||||
return os.path.join(buildtools_path, subdir)
|
||||
if sys.platform.startswith(('cygwin', 'win')):
|
||||
subdir = 'win'
|
||||
elif sys.platform == 'darwin':
|
||||
subdir = 'mac'
|
||||
elif sys.platform.startswith('linux'):
|
||||
subdir = 'linux64'
|
||||
else:
|
||||
raise gclient_utils.Error('Unknown platform: ' + sys.platform)
|
||||
return os.path.join(buildtools_path, subdir)
|
||||
|
||||
|
||||
def GetExeSuffix():
|
||||
"""Returns '' or '.exe' depending on how executables work on this platform."""
|
||||
if sys.platform.startswith(('cygwin', 'win')):
|
||||
return '.exe'
|
||||
return ''
|
||||
"""Returns '' or '.exe' depending on how executables work on this platform."""
|
||||
if sys.platform.startswith(('cygwin', 'win')):
|
||||
return '.exe'
|
||||
return ''
|
||||
|
||||
|
||||
def GetGClientPrimarySolutionName(gclient_root_dir_path):
|
||||
"""Returns the name of the primary solution in the .gclient file specified."""
|
||||
gclient_config_file = os.path.join(gclient_root_dir_path, '.gclient')
|
||||
gclient_config_contents = gclient_utils.FileRead(gclient_config_file)
|
||||
env = {}
|
||||
exec(gclient_config_contents, env)
|
||||
solutions = env.get('solutions', [])
|
||||
if solutions:
|
||||
return solutions[0].get('name')
|
||||
return None
|
||||
"""Returns the name of the primary solution in the .gclient file specified."""
|
||||
gclient_config_file = os.path.join(gclient_root_dir_path, '.gclient')
|
||||
gclient_config_contents = gclient_utils.FileRead(gclient_config_file)
|
||||
env = {}
|
||||
exec(gclient_config_contents, env)
|
||||
solutions = env.get('solutions', [])
|
||||
if solutions:
|
||||
return solutions[0].get('name')
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user