mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
gclient: Fix gclient Python 3 errors and add to presubmit tests.
Bug: 984182 Change-Id: I06e88f56aebf31c0c1ca495e6cbf03b6698b3676 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1790603 Reviewed-by: Dirk Pranke <dpranke@chromium.org> Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
This commit is contained in:
15
gclient.py
15
gclient.py
@@ -241,13 +241,14 @@ class Hook(object):
|
||||
|
||||
cmd = [arg for arg in self._action]
|
||||
|
||||
if cmd[0] == 'python' and six.PY2:
|
||||
if cmd[0] == 'python':
|
||||
# If the hook specified "python" as the first item, the action is a
|
||||
# Python script. Run it by starting a new copy of the same interpreter if
|
||||
# we're running on Python 2.
|
||||
# On Python 3 we simply execute 'python'.
|
||||
cmd[0] = sys.executable
|
||||
elif cmd[0] == 'vpython' and _detect_host_os() == 'win':
|
||||
# When using vpython3, "python" refers to the Python 3 executable used by
|
||||
# vpython3, so use "vpython" instead.
|
||||
cmd[0] = sys.executable if six.PY2 else 'vpython'
|
||||
if cmd[0] == 'vpython' and _detect_host_os() == 'win':
|
||||
cmd[0] += '.bat'
|
||||
|
||||
try:
|
||||
@@ -2707,7 +2708,7 @@ def CMDsync(parser, args):
|
||||
'url': str(d.url) if d.url else None,
|
||||
'was_processed': d.should_process,
|
||||
}
|
||||
with open(options.output_json, 'wb') as f:
|
||||
with open(options.output_json, 'w') as f:
|
||||
json.dump({'solutions': slns}, f)
|
||||
return ret
|
||||
|
||||
@@ -2862,7 +2863,7 @@ def CMDgetdep(parser, args):
|
||||
if client is not None:
|
||||
builtin_vars = client.get_builtin_vars()
|
||||
else:
|
||||
logging.warn(
|
||||
logging.warning(
|
||||
'Couldn\'t find a valid gclient config. Will attempt to parse the DEPS '
|
||||
'file without support for built-in variables.')
|
||||
builtin_vars = None
|
||||
@@ -2922,7 +2923,7 @@ def CMDsetdep(parser, args):
|
||||
if client is not None:
|
||||
builtin_vars = client.get_builtin_vars()
|
||||
else:
|
||||
logging.warn(
|
||||
logging.warning(
|
||||
'Couldn\'t find a valid gclient config. Will attempt to parse the DEPS '
|
||||
'file without support for built-in variables.')
|
||||
builtin_vars = None
|
||||
|
||||
@@ -37,7 +37,7 @@ def main():
|
||||
new_content = parse_cipd(args.root, f.readlines())
|
||||
|
||||
# Install new packages
|
||||
for path, packages in new_content.iteritems():
|
||||
for path, packages in new_content.items():
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
with open(os.path.join(path, '_cipd'), 'w') as f:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env vpython3
|
||||
# Copyright (c) 2012 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.
|
||||
@@ -734,13 +734,7 @@ class GClientSmokeGIT(GClientSmokeBase):
|
||||
('running', self.root_dir), # pre-deps hook
|
||||
('running', self.root_dir), # pre-deps hook (fails)
|
||||
]
|
||||
executable = sys.executable
|
||||
# On Python 3 we always execute hooks with 'python', so we cannot use
|
||||
# sys.executable.
|
||||
if sys.version_info.major == 3:
|
||||
executable = subprocess.check_output(
|
||||
['python', '-c', 'import sys; print(sys.executable)'])
|
||||
executable = executable.decode('utf-8').strip()
|
||||
executable = sys.executable if sys.version_info.major == 2 else 'vpython'
|
||||
expected_stderr = ("Error: Command '%s -c import sys; "
|
||||
"sys.exit(1)' returned non-zero exit status 1 in %s\n"
|
||||
% (executable, self.root_dir))
|
||||
|
||||
Reference in New Issue
Block a user