Commit 112a77f4 authored by Dirk Pranke's avatar Dirk Pranke Committed by Commit Bot

Make sys a top-level import in gclient_paths.

sys takes essentially no time to import (I think possibly because
it's a built-in?), and importing it as-needed is fragile. Make
it a top-level import to gclient_paths to prevent future breakages.

BUG=939959

Change-Id: I1ebe1260afd927355d668acf3cab5067ff0a2e03
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1515669Reviewed-by: 's avatarNico Weber <thakis@chromium.org>
Commit-Queue: Dirk Pranke <dpranke@chromium.org>
parent 8195bd9e
...@@ -4,8 +4,11 @@ ...@@ -4,8 +4,11 @@
# This file is imported by various thin wrappers (around gn, clang-format, ...), # This file is imported by various thin wrappers (around gn, clang-format, ...),
# so it's meant to import very quickly. To keep it that way don't add more # so it's meant to import very quickly. To keep it that way don't add more
# code, and even more importantly don't add more toplevel import statements. # code, and even more importantly don't add more toplevel import statements,
# particularly for modules that are not builtin (see sys.builtin_modules_names,
# os isn't built in, but it's essential to this file).
import os import os
import sys
def FindGclientRoot(from_dir, filename='.gclient'): def FindGclientRoot(from_dir, filename='.gclient'):
...@@ -23,7 +26,6 @@ def FindGclientRoot(from_dir, filename='.gclient'): ...@@ -23,7 +26,6 @@ def FindGclientRoot(from_dir, filename='.gclient'):
if path != real_from_dir: if path != real_from_dir:
entries_filename = os.path.join(path, filename + '_entries') entries_filename = os.path.join(path, filename + '_entries')
if not os.path.exists(entries_filename): if not os.path.exists(entries_filename):
import sys
# If .gclient_entries does not exist, a previous call to gclient sync # If .gclient_entries does not exist, a previous call to gclient sync
# might have failed. In that case, we cannot verify that the .gclient # 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, # is the one we want to use. In order to not to cause too much trouble,
...@@ -106,7 +108,6 @@ def GetBuildtoolsPlatformBinaryPath(): ...@@ -106,7 +108,6 @@ def GetBuildtoolsPlatformBinaryPath():
if not buildtools_path: if not buildtools_path:
return None return None
import sys
if sys.platform.startswith(('cygwin', 'win')): if sys.platform.startswith(('cygwin', 'win')):
subdir = 'win' subdir = 'win'
elif sys.platform == 'darwin': elif sys.platform == 'darwin':
...@@ -120,7 +121,6 @@ def GetBuildtoolsPlatformBinaryPath(): ...@@ -120,7 +121,6 @@ def GetBuildtoolsPlatformBinaryPath():
def GetExeSuffix(): def GetExeSuffix():
"""Returns '' or '.exe' depending on how executables work on this platform.""" """Returns '' or '.exe' depending on how executables work on this platform."""
import sys
if sys.platform.startswith(('cygwin', 'win')): if sys.platform.startswith(('cygwin', 'win')):
return '.exe' return '.exe'
return '' return ''
......
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