Commit ca879322 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

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/+/1790603Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent 934836a6
......@@ -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:
......
#!/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))
......
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