Reland "Expand variables in gclient flattened output."
This is a reland of a32f98e652d5e151f70d571cf046c3d83ae2f486
Original change's description:
> Expand variables in gclient flattened output.
>
> Bug: 848990
> Change-Id: I0ad7e4f965973edbc5a335bd30f9cbd7b04abff2
> Reviewed-on: https://chromium-review.googlesource.com/1085996
> Reviewed-by: Michael Moss <mmoss@chromium.org>
> Reviewed-by: Aaron Gable <agable@chromium.org>
> Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Tbr: agable@chromium.org
Bug: 848990
Change-Id: I7843544b79b2ab7e2046c187d13ea3eb65fc1b7d
Reviewed-on: https://chromium-review.googlesource.com/1085975
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
diff --git a/gclient.py b/gclient.py
index 10f3fa0..2f59cf7 100755
--- a/gclient.py
+++ b/gclient.py
@@ -207,7 +207,7 @@
not gclient_eval.EvaluateCondition(self._condition, self._variables)):
return
- cmd = [arg.format(**self._variables) for arg in self._action]
+ cmd = [arg for arg in self._action]
if cmd[0] == 'python':
# If the hook specified "python" as the first item, the action is a
@@ -240,12 +240,11 @@
class DependencySettings(object):
"""Immutable configuration settings."""
def __init__(
- self, parent, raw_url, url, managed, custom_deps, custom_vars,
+ self, parent, url, managed, custom_deps, custom_vars,
custom_hooks, deps_file, should_process, relative, condition):
# These are not mutable:
self._parent = parent
self._deps_file = deps_file
- self._raw_url = raw_url
self._url = url
# The condition as string (or None). Useful to keep e.g. for flatten.
self._condition = condition
@@ -324,11 +323,6 @@
return self._custom_hooks[:]
@property
- def raw_url(self):
- """URL before variable expansion."""
- return self._raw_url
-
- @property
def url(self):
"""URL after variable expansion."""
return self._url
@@ -351,9 +345,6 @@
def set_url(self, url):
self._url = url
- def set_raw_url(self, url):
- self._raw_url = url
-
def get_custom_deps(self, name, url):
"""Returns a custom deps if applicable."""
if self.parent:
@@ -365,12 +356,12 @@
class Dependency(gclient_utils.WorkItem, DependencySettings):
"""Object that represents a dependency checkout."""
- def __init__(self, parent, name, raw_url, url, managed, custom_deps,
+ def __init__(self, parent, name, url, managed, custom_deps,
custom_vars, custom_hooks, deps_file, should_process,
relative, condition, print_outbuf=False):
gclient_utils.WorkItem.__init__(self, name)
DependencySettings.__init__(
- self, parent, raw_url, url, managed, custom_deps, custom_vars,
+ self, parent, url, managed, custom_deps, custom_vars,
custom_hooks, deps_file, should_process, relative, condition)
# This is in both .gclient and DEPS files:
@@ -468,18 +459,15 @@
raise gclient_utils.Error('Unknown url type')
def PinToActualRevision(self):
- """Updates self.url and self.raw_url to the revision checked out on disk."""
+ """Updates self.url to the revision checked out on disk."""
if self.url is None:
return
- url = raw_url = None
+ url = None
scm = self.CreateSCM()
if os.path.isdir(scm.checkout_path):
revision = scm.revinfo(None, None, None)
url = '%s@%s' % (gclient_utils.SplitUrlRevision(self.url)[0], revision)
- raw_url = '%s@%s' % (
- gclient_utils.SplitUrlRevision(self.raw_url)[0], revision)
self.set_url(url)
- self.set_raw_url(raw_url)
def ToLines(self):
s = []
@@ -488,7 +476,7 @@
s.extend([
' # %s' % self.hierarchy(include_url=False),
' "%s": {' % (self.name,),
- ' "url": "%s",' % (self.raw_url,),
+ ' "url": "%s",' % (self.url,),
] + condition_part + [
' },',
'',
@@ -642,25 +630,23 @@
for package in dep_value.get('packages', []):
if 'version' in package:
# Matches version to vars value.
- raw_version = package['version']
- version = raw_version.format(**self.get_vars())
+ version = package['version']
package['version'] = version
deps_to_add.append(
CipdDependency(
self, name, package, cipd_root, self.custom_vars,
should_process, use_relative_paths, condition))
else:
- raw_url = dep_value.get('url')
- url = raw_url.format(**self.get_vars()) if raw_url else None
+ url = dep_value.get('url')
deps_to_add.append(
GitDependency(
- self, name, raw_url, url, None, None, self.custom_vars, None,
+ self, name, url, None, None, self.custom_vars, None,
deps_file, should_process, use_relative_paths, condition))
deps_to_add.sort(key=lambda x: x.name)
return deps_to_add
- def ParseDepsFile(self, expand_vars=True):
+ def ParseDepsFile(self):
"""Parses the DEPS file for this dependency."""
assert not self.deps_parsed
assert not self.dependencies
@@ -691,8 +677,7 @@
if deps_content:
try:
local_scope = gclient_eval.Parse(
- deps_content, expand_vars,
- self._get_option('validate_syntax', False),
+ deps_content, self._get_option('validate_syntax', False),
filepath, self.get_vars())
except SyntaxError as e:
gclient_utils.SyntaxErrorToError(filepath, e)
@@ -915,7 +900,7 @@
file_list[i] = file_list[i][1:]
if self.recursion_limit:
- self.ParseDepsFile(expand_vars=(command != 'flatten'))
+ self.ParseDepsFile()
self._run_is_done(file_list or [])
@@ -1294,7 +1279,7 @@
# Do not change previous behavior. Only solution level and immediate DEPS
# are processed.
self._recursion_limit = 2
- GitDependency.__init__(self, None, None, None, None, True, None, None, None,
+ GitDependency.__init__(self, None, None, None, True, None, None, None,
'unused', True, None, None, True)
self._options = options
if options.deps_os:
@@ -1386,7 +1371,7 @@
for s in config_dict.get('solutions', []):
try:
deps_to_add.append(GitDependency(
- self, s['name'], s['url'], s['url'],
+ self, s['name'], s['url'],
s.get('managed', True),
s.get('custom_deps', {}),
s.get('custom_vars', {}),
@@ -1753,7 +1738,7 @@
print('%s: %s' % (x, entries[x]))
logging.info(str(self))
- def ParseDepsFile(self, expand_vars=None):
+ def ParseDepsFile(self):
"""No DEPS to parse for a .gclient file."""
raise gclient_utils.Error('Internal error')
@@ -1846,7 +1831,7 @@
self._cipd_package = self._cipd_root.add_package(
self._cipd_subdir, self._package_name, self._package_version)
- def ParseDepsFile(self, expand_vars=None):
+ def ParseDepsFile(self):
"""CIPD dependencies are not currently allowed to have nested deps."""
self.add_dependencies_and_close([], [])
@@ -2196,7 +2181,7 @@
s.extend([
' # %s' % dep.hierarchy(include_url=False),
' "%s": {' % (name,),
- ' "url": "%s",' % (dep.raw_url,),
+ ' "url": "%s",' % (dep.url,),
] + condition_part + [
' },',
'',
@@ -2728,8 +2713,7 @@
'DEPS file %s does not exist.' % options.deps_file)
with open(options.deps_file) as f:
contents = f.read()
- local_scope = gclient_eval.Exec(
- contents, expand_vars=True, filename=options.deps_file)
+ local_scope = gclient_eval.Exec(contents, options.deps_file)
for var in options.vars:
print(gclient_eval.GetVar(local_scope, var))
@@ -2778,8 +2762,7 @@
'DEPS file %s does not exist.' % options.deps_file)
with open(options.deps_file) as f:
contents = f.read()
- local_scope = gclient_eval.Exec(
- contents, expand_vars=True, filename=options.deps_file)
+ local_scope = gclient_eval.Exec(contents, options.deps_file)
for var in options.vars:
name, _, value = var.partition('=')