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

Expand variables in gclient flattened output.

Bug: 848990
Change-Id: I0ad7e4f965973edbc5a335bd30f9cbd7b04abff2
Reviewed-on: https://chromium-review.googlesource.com/1085996Reviewed-by: 's avatarMichael Moss <mmoss@chromium.org>
Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent 23d75d2d
...@@ -207,7 +207,7 @@ class Hook(object): ...@@ -207,7 +207,7 @@ class Hook(object):
not gclient_eval.EvaluateCondition(self._condition, self._variables)): not gclient_eval.EvaluateCondition(self._condition, self._variables)):
return return
cmd = [arg.format(**self._variables) for arg in self._action] cmd = [arg for arg in self._action]
if cmd[0] == 'python': if cmd[0] == 'python':
# If the hook specified "python" as the first item, the action is a # If the hook specified "python" as the first item, the action is a
...@@ -240,12 +240,11 @@ class Hook(object): ...@@ -240,12 +240,11 @@ class Hook(object):
class DependencySettings(object): class DependencySettings(object):
"""Immutable configuration settings.""" """Immutable configuration settings."""
def __init__( 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): custom_hooks, deps_file, should_process, relative, condition):
# These are not mutable: # These are not mutable:
self._parent = parent self._parent = parent
self._deps_file = deps_file self._deps_file = deps_file
self._raw_url = raw_url
self._url = url self._url = url
# The condition as string (or None). Useful to keep e.g. for flatten. # The condition as string (or None). Useful to keep e.g. for flatten.
self._condition = condition self._condition = condition
...@@ -323,11 +322,6 @@ class DependencySettings(object): ...@@ -323,11 +322,6 @@ class DependencySettings(object):
def custom_hooks(self): def custom_hooks(self):
return self._custom_hooks[:] return self._custom_hooks[:]
@property
def raw_url(self):
"""URL before variable expansion."""
return self._raw_url
@property @property
def url(self): def url(self):
"""URL after variable expansion.""" """URL after variable expansion."""
...@@ -351,9 +345,6 @@ class DependencySettings(object): ...@@ -351,9 +345,6 @@ class DependencySettings(object):
def set_url(self, url): def set_url(self, url):
self._url = url self._url = url
def set_raw_url(self, url):
self._raw_url = url
def get_custom_deps(self, name, url): def get_custom_deps(self, name, url):
"""Returns a custom deps if applicable.""" """Returns a custom deps if applicable."""
if self.parent: if self.parent:
...@@ -365,12 +356,12 @@ class DependencySettings(object): ...@@ -365,12 +356,12 @@ class DependencySettings(object):
class Dependency(gclient_utils.WorkItem, DependencySettings): class Dependency(gclient_utils.WorkItem, DependencySettings):
"""Object that represents a dependency checkout.""" """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, custom_vars, custom_hooks, deps_file, should_process,
relative, condition, print_outbuf=False): relative, condition, print_outbuf=False):
gclient_utils.WorkItem.__init__(self, name) gclient_utils.WorkItem.__init__(self, name)
DependencySettings.__init__( 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) custom_hooks, deps_file, should_process, relative, condition)
# This is in both .gclient and DEPS files: # This is in both .gclient and DEPS files:
...@@ -468,18 +459,15 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -468,18 +459,15 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
raise gclient_utils.Error('Unknown url type') raise gclient_utils.Error('Unknown url type')
def PinToActualRevision(self): 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: if self.url is None:
return return
url = raw_url = None url = None
scm = self.CreateSCM() scm = self.CreateSCM()
if os.path.isdir(scm.checkout_path): if os.path.isdir(scm.checkout_path):
revision = scm.revinfo(None, None, None) revision = scm.revinfo(None, None, None)
url = '%s@%s' % (gclient_utils.SplitUrlRevision(self.url)[0], revision) 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_url(url)
self.set_raw_url(raw_url)
def ToLines(self): def ToLines(self):
s = [] s = []
...@@ -488,7 +476,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -488,7 +476,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
s.extend([ s.extend([
' # %s' % self.hierarchy(include_url=False), ' # %s' % self.hierarchy(include_url=False),
' "%s": {' % (self.name,), ' "%s": {' % (self.name,),
' "url": "%s",' % (self.raw_url,), ' "url": "%s",' % (self.url,),
] + condition_part + [ ] + condition_part + [
' },', ' },',
'', '',
...@@ -642,25 +630,23 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -642,25 +630,23 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
for package in dep_value.get('packages', []): for package in dep_value.get('packages', []):
if 'version' in package: if 'version' in package:
# Matches version to vars value. # Matches version to vars value.
raw_version = package['version'] version = package['version']
version = raw_version.format(**self.get_vars())
package['version'] = version package['version'] = version
deps_to_add.append( deps_to_add.append(
CipdDependency( CipdDependency(
self, name, package, cipd_root, self.custom_vars, self, name, package, cipd_root, self.custom_vars,
should_process, use_relative_paths, condition)) should_process, use_relative_paths, condition))
else: else:
raw_url = dep_value.get('url') url = dep_value.get('url')
url = raw_url.format(**self.get_vars()) if raw_url else None
deps_to_add.append( deps_to_add.append(
GitDependency( 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_file, should_process, use_relative_paths, condition))
deps_to_add.sort(key=lambda x: x.name) deps_to_add.sort(key=lambda x: x.name)
return deps_to_add return deps_to_add
def ParseDepsFile(self, expand_vars=True): def ParseDepsFile(self):
"""Parses the DEPS file for this dependency.""" """Parses the DEPS file for this dependency."""
assert not self.deps_parsed assert not self.deps_parsed
assert not self.dependencies assert not self.dependencies
...@@ -691,8 +677,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -691,8 +677,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
if deps_content: if deps_content:
try: try:
local_scope = gclient_eval.Parse( local_scope = gclient_eval.Parse(
deps_content, expand_vars, deps_content, self._get_option('validate_syntax', False),
self._get_option('validate_syntax', False),
filepath, self.get_vars()) filepath, self.get_vars())
except SyntaxError as e: except SyntaxError as e:
gclient_utils.SyntaxErrorToError(filepath, e) gclient_utils.SyntaxErrorToError(filepath, e)
...@@ -915,7 +900,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -915,7 +900,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
file_list[i] = file_list[i][1:] file_list[i] = file_list[i][1:]
if self.recursion_limit: if self.recursion_limit:
self.ParseDepsFile(expand_vars=(command != 'flatten')) self.ParseDepsFile()
self._run_is_done(file_list or []) self._run_is_done(file_list or [])
...@@ -1294,7 +1279,7 @@ solutions = %(solution_list)s ...@@ -1294,7 +1279,7 @@ solutions = %(solution_list)s
# Do not change previous behavior. Only solution level and immediate DEPS # Do not change previous behavior. Only solution level and immediate DEPS
# are processed. # are processed.
self._recursion_limit = 2 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) 'unused', True, None, None, True)
self._options = options self._options = options
if options.deps_os: if options.deps_os:
...@@ -1386,7 +1371,7 @@ it or fix the checkout. ...@@ -1386,7 +1371,7 @@ it or fix the checkout.
for s in config_dict.get('solutions', []): for s in config_dict.get('solutions', []):
try: try:
deps_to_add.append(GitDependency( deps_to_add.append(GitDependency(
self, s['name'], s['url'], s['url'], self, s['name'], s['url'],
s.get('managed', True), s.get('managed', True),
s.get('custom_deps', {}), s.get('custom_deps', {}),
s.get('custom_vars', {}), s.get('custom_vars', {}),
...@@ -1753,7 +1738,7 @@ it or fix the checkout. ...@@ -1753,7 +1738,7 @@ it or fix the checkout.
print('%s: %s' % (x, entries[x])) print('%s: %s' % (x, entries[x]))
logging.info(str(self)) logging.info(str(self))
def ParseDepsFile(self, expand_vars=None): def ParseDepsFile(self):
"""No DEPS to parse for a .gclient file.""" """No DEPS to parse for a .gclient file."""
raise gclient_utils.Error('Internal error') raise gclient_utils.Error('Internal error')
...@@ -1846,7 +1831,7 @@ class CipdDependency(Dependency): ...@@ -1846,7 +1831,7 @@ class CipdDependency(Dependency):
self._cipd_package = self._cipd_root.add_package( self._cipd_package = self._cipd_root.add_package(
self._cipd_subdir, self._package_name, self._package_version) 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.""" """CIPD dependencies are not currently allowed to have nested deps."""
self.add_dependencies_and_close([], []) self.add_dependencies_and_close([], [])
...@@ -2196,7 +2181,7 @@ def _DepsOsToLines(deps_os): ...@@ -2196,7 +2181,7 @@ def _DepsOsToLines(deps_os):
s.extend([ s.extend([
' # %s' % dep.hierarchy(include_url=False), ' # %s' % dep.hierarchy(include_url=False),
' "%s": {' % (name,), ' "%s": {' % (name,),
' "url": "%s",' % (dep.raw_url,), ' "url": "%s",' % (dep.url,),
] + condition_part + [ ] + condition_part + [
' },', ' },',
'', '',
...@@ -2728,8 +2713,7 @@ def CMDgetdep(parser, args): ...@@ -2728,8 +2713,7 @@ def CMDgetdep(parser, args):
'DEPS file %s does not exist.' % options.deps_file) 'DEPS file %s does not exist.' % options.deps_file)
with open(options.deps_file) as f: with open(options.deps_file) as f:
contents = f.read() contents = f.read()
local_scope = gclient_eval.Exec( local_scope = gclient_eval.Exec(contents, options.deps_file)
contents, expand_vars=True, filename=options.deps_file)
for var in options.vars: for var in options.vars:
print(gclient_eval.GetVar(local_scope, var)) print(gclient_eval.GetVar(local_scope, var))
...@@ -2778,8 +2762,7 @@ def CMDsetdep(parser, args): ...@@ -2778,8 +2762,7 @@ def CMDsetdep(parser, args):
'DEPS file %s does not exist.' % options.deps_file) 'DEPS file %s does not exist.' % options.deps_file)
with open(options.deps_file) as f: with open(options.deps_file) as f:
contents = f.read() contents = f.read()
local_scope = gclient_eval.Exec( local_scope = gclient_eval.Exec(contents, options.deps_file)
contents, expand_vars=True, filename=options.deps_file)
for var in options.vars: for var in options.vars:
name, _, value = var.partition('=') name, _, value = var.partition('=')
......
...@@ -206,9 +206,9 @@ _GCLIENT_SCHEMA = schema.Schema(_NodeDictSchema({ ...@@ -206,9 +206,9 @@ _GCLIENT_SCHEMA = schema.Schema(_NodeDictSchema({
})) }))
def _gclient_eval(node_or_string, vars_dict=None, expand_vars=False, def _gclient_eval(node_or_string, filename='<unknown>', vars_dict=None):
filename='<unknown>'):
"""Safely evaluates a single expression. Returns the result.""" """Safely evaluates a single expression. Returns the result."""
vars_dict = vars_dict or {}
_allowed_names = {'None': None, 'True': True, 'False': False} _allowed_names = {'None': None, 'True': True, 'False': False}
if isinstance(node_or_string, basestring): if isinstance(node_or_string, basestring):
node_or_string = ast.parse(node_or_string, filename=filename, mode='eval') node_or_string = ast.parse(node_or_string, filename=filename, mode='eval')
...@@ -216,8 +216,6 @@ def _gclient_eval(node_or_string, vars_dict=None, expand_vars=False, ...@@ -216,8 +216,6 @@ def _gclient_eval(node_or_string, vars_dict=None, expand_vars=False,
node_or_string = node_or_string.body node_or_string = node_or_string.body
def _convert(node): def _convert(node):
if isinstance(node, ast.Str): if isinstance(node, ast.Str):
if not expand_vars:
return node.s
try: try:
return node.s.format(**vars_dict) return node.s.format(**vars_dict)
except KeyError as e: except KeyError as e:
...@@ -254,8 +252,6 @@ def _gclient_eval(node_or_string, vars_dict=None, expand_vars=False, ...@@ -254,8 +252,6 @@ def _gclient_eval(node_or_string, vars_dict=None, expand_vars=False,
raise ValueError( raise ValueError(
'Var\'s argument must be a variable name (file %r, line %s)' % ( 'Var\'s argument must be a variable name (file %r, line %s)' % (
filename, getattr(node, 'lineno', '<unknown>'))) filename, getattr(node, 'lineno', '<unknown>')))
if not expand_vars:
return '{%s}' % arg
if vars_dict is None: if vars_dict is None:
raise ValueError( raise ValueError(
'vars must be declared before Var can be used (file %r, line %s)' 'vars must be declared before Var can be used (file %r, line %s)'
...@@ -278,7 +274,7 @@ def _gclient_eval(node_or_string, vars_dict=None, expand_vars=False, ...@@ -278,7 +274,7 @@ def _gclient_eval(node_or_string, vars_dict=None, expand_vars=False,
return _convert(node_or_string) return _convert(node_or_string)
def Exec(content, expand_vars=True, filename='<unknown>', vars_override=None): def Exec(content, filename='<unknown>', vars_override=None):
"""Safely execs a set of assignments.""" """Safely execs a set of assignments."""
def _validate_statement(node, local_scope): def _validate_statement(node, local_scope):
if not isinstance(node, ast.Assign): if not isinstance(node, ast.Assign):
...@@ -330,7 +326,7 @@ def Exec(content, expand_vars=True, filename='<unknown>', vars_override=None): ...@@ -330,7 +326,7 @@ def Exec(content, expand_vars=True, filename='<unknown>', vars_override=None):
vars_dict = {} vars_dict = {}
if 'vars' in statements: if 'vars' in statements:
vars_statement = statements['vars'] vars_statement = statements['vars']
value = _gclient_eval(vars_statement, None, False, filename) value = _gclient_eval(vars_statement, filename)
local_scope.SetNode('vars', value, vars_statement) local_scope.SetNode('vars', value, vars_statement)
# Update the parsed vars with the overrides, but only if they are already # Update the parsed vars with the overrides, but only if they are already
# present (overrides do not introduce new variables). # present (overrides do not introduce new variables).
...@@ -342,14 +338,13 @@ def Exec(content, expand_vars=True, filename='<unknown>', vars_override=None): ...@@ -342,14 +338,13 @@ def Exec(content, expand_vars=True, filename='<unknown>', vars_override=None):
if k in vars_dict}) if k in vars_dict})
for name, node in statements.iteritems(): for name, node in statements.iteritems():
value = _gclient_eval(node, vars_dict, expand_vars, filename) value = _gclient_eval(node, filename, vars_dict)
local_scope.SetNode(name, value, node) local_scope.SetNode(name, value, node)
return _GCLIENT_SCHEMA.validate(local_scope) return _GCLIENT_SCHEMA.validate(local_scope)
def ExecLegacy(content, expand_vars=True, filename='<unknown>', def ExecLegacy(content, filename='<unknown>', vars_override=None):
vars_override=None):
"""Executes a DEPS file |content| using exec.""" """Executes a DEPS file |content| using exec."""
local_scope = {} local_scope = {}
global_scope = {'Var': lambda var_name: '{%s}' % var_name} global_scope = {'Var': lambda var_name: '{%s}' % var_name}
...@@ -360,7 +355,7 @@ def ExecLegacy(content, expand_vars=True, filename='<unknown>', ...@@ -360,7 +355,7 @@ def ExecLegacy(content, expand_vars=True, filename='<unknown>',
# as "exec a in b, c" (See https://bugs.python.org/issue21591). # as "exec a in b, c" (See https://bugs.python.org/issue21591).
eval(compile(content, filename, 'exec'), global_scope, local_scope) eval(compile(content, filename, 'exec'), global_scope, local_scope)
if 'vars' not in local_scope or not expand_vars: if 'vars' not in local_scope:
return local_scope return local_scope
vars_dict = {} vars_dict = {}
...@@ -455,7 +450,7 @@ def UpdateCondition(info_dict, op, new_condition): ...@@ -455,7 +450,7 @@ def UpdateCondition(info_dict, op, new_condition):
del info_dict['condition'] del info_dict['condition']
def Parse(content, expand_vars, validate_syntax, filename, vars_override=None): def Parse(content, validate_syntax, filename, vars_override=None):
"""Parses DEPS strings. """Parses DEPS strings.
Executes the Python-like string stored in content, resulting in a Python Executes the Python-like string stored in content, resulting in a Python
...@@ -464,7 +459,6 @@ def Parse(content, expand_vars, validate_syntax, filename, vars_override=None): ...@@ -464,7 +459,6 @@ def Parse(content, expand_vars, validate_syntax, filename, vars_override=None):
Args: Args:
content: str. DEPS file stored as a string. content: str. DEPS file stored as a string.
expand_vars: bool. Whether variables should be expanded to their values.
validate_syntax: bool. Whether syntax should be validated using the schema validate_syntax: bool. Whether syntax should be validated using the schema
defined above. defined above.
filename: str. The name of the DEPS file, or a string describing the source filename: str. The name of the DEPS file, or a string describing the source
...@@ -477,9 +471,9 @@ def Parse(content, expand_vars, validate_syntax, filename, vars_override=None): ...@@ -477,9 +471,9 @@ def Parse(content, expand_vars, validate_syntax, filename, vars_override=None):
schema above. schema above.
""" """
if validate_syntax: if validate_syntax:
result = Exec(content, expand_vars, filename, vars_override) result = Exec(content, filename, vars_override)
else: else:
result = ExecLegacy(content, expand_vars, filename, vars_override) result = ExecLegacy(content, filename, vars_override)
vars_dict = result.get('vars', {}) vars_dict = result.get('vars', {})
if 'deps' in result: if 'deps' in result:
......
...@@ -9,4 +9,4 @@ As the CI needs of the browser grew, Batty, the Build and Test Yeti, got ...@@ -9,4 +9,4 @@ As the CI needs of the browser grew, Batty, the Build and Test Yeti, got
a new friend: a new friend:
The End! The End.
...@@ -225,7 +225,7 @@ def main(): ...@@ -225,7 +225,7 @@ def main():
# First gather all the information without modifying anything, except for a # First gather all the information without modifying anything, except for a
# git fetch. # git fetch.
deps_path, deps_content = get_deps(current_dir) deps_path, deps_content = get_deps(current_dir)
gclient_dict = gclient_eval.Exec(deps_content, True, deps_path) gclient_dict = gclient_eval.Exec(deps_content, deps_path)
is_relative = gclient_dict.get('use_relative_paths', False) is_relative = gclient_dict.get('use_relative_paths', False)
root_dir = current_dir if is_relative else gclient_root root_dir = current_dir if is_relative else gclient_root
rolls = {} rolls = {}
......
...@@ -44,22 +44,19 @@ class GClientEvalTest(unittest.TestCase): ...@@ -44,22 +44,19 @@ class GClientEvalTest(unittest.TestCase):
gclient_eval._gclient_eval('Foo("bar")') gclient_eval._gclient_eval('Foo("bar")')
self.assertIn('Var is the only allowed function', str(cm.exception)) self.assertIn('Var is the only allowed function', str(cm.exception))
def test_call(self):
self.assertEqual('{bar}', gclient_eval._gclient_eval('Var("bar")'))
def test_expands_vars(self): def test_expands_vars(self):
self.assertEqual( self.assertEqual(
'foo', 'foo',
gclient_eval._gclient_eval('Var("bar")', {'bar': 'foo'}, True)) gclient_eval._gclient_eval('Var("bar")', vars_dict={'bar': 'foo'}))
def test_expands_vars_with_braces(self): def test_expands_vars_with_braces(self):
self.assertEqual( self.assertEqual(
'foo', 'foo',
gclient_eval._gclient_eval('"{bar}"', {'bar': 'foo'}, True)) gclient_eval._gclient_eval('"{bar}"', vars_dict={'bar': 'foo'}))
def test_invalid_var(self): def test_invalid_var(self):
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
gclient_eval._gclient_eval('"{bar}"', {}, True) gclient_eval._gclient_eval('"{bar}"')
self.assertIn('bar was used as a variable, but was not declared', self.assertIn('bar was used as a variable, but was not declared',
str(cm.exception)) str(cm.exception))
...@@ -140,20 +137,6 @@ class ExecTest(unittest.TestCase): ...@@ -140,20 +137,6 @@ class ExecTest(unittest.TestCase):
'deps': collections.OrderedDict([('a_dep', 'abarb')]), 'deps': collections.OrderedDict([('a_dep', 'abarb')]),
}, local_scope) }, local_scope)
def test_var_unexpanded(self):
local_scope = gclient_eval.Exec('\n'.join([
'vars = {',
' "foo": "bar",',
'}',
'deps = {',
' "a_dep": "a" + Var("foo") + "b",',
'}',
]), False)
self.assertEqual({
'vars': collections.OrderedDict([('foo', 'bar')]),
'deps': collections.OrderedDict([('a_dep', 'a{foo}b')]),
}, local_scope)
def test_empty_deps(self): def test_empty_deps(self):
local_scope = gclient_eval.Exec('deps = {}') local_scope = gclient_eval.Exec('deps = {}')
self.assertEqual({'deps': {}}, local_scope) self.assertEqual({'deps': {}}, local_scope)
...@@ -166,7 +149,7 @@ class ExecTest(unittest.TestCase): ...@@ -166,7 +149,7 @@ class ExecTest(unittest.TestCase):
'deps = {', 'deps = {',
' "a_dep": "a{foo}b",', ' "a_dep": "a{foo}b",',
'}', '}',
]), True, vars_override={'foo': 'baz'}) ]), vars_override={'foo': 'baz'})
self.assertEqual({ self.assertEqual({
'vars': collections.OrderedDict([('foo', 'bar')]), 'vars': collections.OrderedDict([('foo', 'bar')]),
'deps': collections.OrderedDict([('a_dep', 'abazb')]), 'deps': collections.OrderedDict([('a_dep', 'abazb')]),
...@@ -181,7 +164,7 @@ class ExecTest(unittest.TestCase): ...@@ -181,7 +164,7 @@ class ExecTest(unittest.TestCase):
'deps = {', 'deps = {',
' "a_dep": "a{baz}b",', ' "a_dep": "a{baz}b",',
'}', '}',
]), True, vars_override={'baz': 'lalala'}) ]), vars_override={'baz': 'lalala'})
self.assertIn('baz was used as a variable, but was not declared', self.assertIn('baz was used as a variable, but was not declared',
str(cm.exception)) str(cm.exception))
...@@ -601,8 +584,7 @@ class RevisionTest(unittest.TestCase): ...@@ -601,8 +584,7 @@ class RevisionTest(unittest.TestCase):
class ParseTest(unittest.TestCase): class ParseTest(unittest.TestCase):
def callParse(self, expand_vars=True, validate_syntax=True, def callParse(self, validate_syntax=True, vars_override=None):
vars_override=None):
return gclient_eval.Parse('\n'.join([ return gclient_eval.Parse('\n'.join([
'vars = {', 'vars = {',
' "foo": "bar",', ' "foo": "bar",',
...@@ -610,7 +592,7 @@ class ParseTest(unittest.TestCase): ...@@ -610,7 +592,7 @@ class ParseTest(unittest.TestCase):
'deps = {', 'deps = {',
' "a_dep": "a{foo}b",', ' "a_dep": "a{foo}b",',
'}', '}',
]), expand_vars, validate_syntax, '<unknown>', vars_override) ]), validate_syntax, '<unknown>', vars_override)
def test_expands_vars(self): def test_expands_vars(self):
for validate_syntax in True, False: for validate_syntax in True, False:
...@@ -621,16 +603,6 @@ class ParseTest(unittest.TestCase): ...@@ -621,16 +603,6 @@ class ParseTest(unittest.TestCase):
'dep_type': 'git'}}, 'dep_type': 'git'}},
}, local_scope) }, local_scope)
def test_no_expands_vars(self):
for validate_syntax in True, False:
local_scope = self.callParse(False,
validate_syntax=validate_syntax)
self.assertEqual({
'vars': {'foo': 'bar'},
'deps': {'a_dep': {'url': 'a{foo}b',
'dep_type': 'git'}},
}, local_scope)
def test_overrides_vars(self): def test_overrides_vars(self):
for validate_syntax in True, False: for validate_syntax in True, False:
local_scope = self.callParse(validate_syntax=validate_syntax, local_scope = self.callParse(validate_syntax=validate_syntax,
...@@ -653,15 +625,13 @@ class ParseTest(unittest.TestCase): ...@@ -653,15 +625,13 @@ class ParseTest(unittest.TestCase):
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
gclient_eval.Parse( gclient_eval.Parse(
deps_file, True, True, deps_file, True, '<unknown>', {'baz': 'lalala'})
'<unknown>', {'baz': 'lalala'})
self.assertIn('baz was used as a variable, but was not declared', self.assertIn('baz was used as a variable, but was not declared',
str(cm.exception)) str(cm.exception))
with self.assertRaises(KeyError) as cm: with self.assertRaises(KeyError) as cm:
gclient_eval.Parse( gclient_eval.Parse(
deps_file, True, False, deps_file, False, '<unknown>', {'baz': 'lalala'})
'<unknown>', {'baz': 'lalala'})
self.assertIn('baz', str(cm.exception)) self.assertIn('baz', str(cm.exception))
def test_standardizes_deps_string_dep(self): def test_standardizes_deps_string_dep(self):
...@@ -670,7 +640,7 @@ class ParseTest(unittest.TestCase): ...@@ -670,7 +640,7 @@ class ParseTest(unittest.TestCase):
'deps = {', 'deps = {',
' "a_dep": "a_url@a_rev",', ' "a_dep": "a_url@a_rev",',
'}', '}',
]), False, validate_syntax, '<unknown>') ]), validate_syntax, '<unknown>')
self.assertEqual({ self.assertEqual({
'deps': {'a_dep': {'url': 'a_url@a_rev', 'deps': {'a_dep': {'url': 'a_url@a_rev',
'dep_type': 'git'}}, 'dep_type': 'git'}},
...@@ -685,7 +655,7 @@ class ParseTest(unittest.TestCase): ...@@ -685,7 +655,7 @@ class ParseTest(unittest.TestCase):
' "condition": "checkout_android",', ' "condition": "checkout_android",',
' },', ' },',
'}', '}',
]), False, validate_syntax, '<unknown>') ]), validate_syntax, '<unknown>')
self.assertEqual({ self.assertEqual({
'deps': {'a_dep': {'url': 'a_url@a_rev', 'deps': {'a_dep': {'url': 'a_url@a_rev',
'dep_type': 'git', 'dep_type': 'git',
...@@ -703,7 +673,7 @@ class ParseTest(unittest.TestCase): ...@@ -703,7 +673,7 @@ class ParseTest(unittest.TestCase):
' "a_dep": None,', ' "a_dep": None,',
' },', ' },',
'}', '}',
]), False, validate_syntax, '<unknown>') ]), validate_syntax, '<unknown>')
self.assertEqual({ self.assertEqual({
'deps': {'a_dep': {'url': 'a_url@a_rev', 'deps': {'a_dep': {'url': 'a_url@a_rev',
'dep_type': 'git'}}, 'dep_type': 'git'}},
...@@ -720,7 +690,7 @@ class ParseTest(unittest.TestCase): ...@@ -720,7 +690,7 @@ class ParseTest(unittest.TestCase):
' "b_dep": "b_url@b_rev"', ' "b_dep": "b_url@b_rev"',
' },', ' },',
'}', '}',
]), False, validate_syntax, '<unknown>') ]), validate_syntax, '<unknown>')
self.assertEqual({ self.assertEqual({
'deps': {'a_dep': {'url': 'a_url@a_rev', 'deps': {'a_dep': {'url': 'a_url@a_rev',
'dep_type': 'git'}, 'dep_type': 'git'},
...@@ -740,7 +710,7 @@ class ParseTest(unittest.TestCase): ...@@ -740,7 +710,7 @@ class ParseTest(unittest.TestCase):
' "a_dep": "a_url@a_rev"', ' "a_dep": "a_url@a_rev"',
' },', ' },',
'}', '}',
]), False, validate_syntax, '<unknown>') ]), validate_syntax, '<unknown>')
self.assertEqual({ self.assertEqual({
'deps': {'a_dep': {'url': 'a_url@a_rev', 'deps': {'a_dep': {'url': 'a_url@a_rev',
'dep_type': 'git'}}, 'dep_type': 'git'}},
...@@ -760,7 +730,7 @@ class ParseTest(unittest.TestCase): ...@@ -760,7 +730,7 @@ class ParseTest(unittest.TestCase):
' "a_dep": "a_url@a_rev"', ' "a_dep": "a_url@a_rev"',
' },', ' },',
'}', '}',
]), False, validate_syntax, '<unknown>') ]), validate_syntax, '<unknown>')
self.assertEqual({ self.assertEqual({
'deps': { 'deps': {
'a_dep': {'url': 'a_url@a_rev', 'a_dep': {'url': 'a_url@a_rev',
...@@ -780,7 +750,7 @@ class ParseTest(unittest.TestCase): ...@@ -780,7 +750,7 @@ class ParseTest(unittest.TestCase):
' "a_dep": "a_url@a_rev"', ' "a_dep": "a_url@a_rev"',
' },', ' },',
'}', '}',
]), False, validate_syntax, '<unknown>') ]), validate_syntax, '<unknown>')
self.assertEqual({ self.assertEqual({
'deps': { 'deps': {
'a_dep': {'url': 'a_url@a_rev', 'a_dep': {'url': 'a_url@a_rev',
...@@ -804,7 +774,7 @@ class ParseTest(unittest.TestCase): ...@@ -804,7 +774,7 @@ class ParseTest(unittest.TestCase):
' "a_dep": "a_url@b_rev"', ' "a_dep": "a_url@b_rev"',
' },', ' },',
'}', '}',
]), False, validate_syntax, '<unknown>') ]), validate_syntax, '<unknown>')
self.assertIn('conflicts with existing deps', str(cm.exception)) self.assertIn('conflicts with existing deps', str(cm.exception))
def test_merges_hooks_os(self): def test_merges_hooks_os(self):
...@@ -822,7 +792,7 @@ class ParseTest(unittest.TestCase): ...@@ -822,7 +792,7 @@ class ParseTest(unittest.TestCase):
' },', ' },',
' ]', ' ]',
'}', '}',
]), False, validate_syntax, '<unknown>') ]), validate_syntax, '<unknown>')
self.assertEqual({ self.assertEqual({
"hooks": [{"action": ["a", "action"]}, "hooks": [{"action": ["a", "action"]},
{"action": ["b", "action"], "condition": "checkout_mac"}], {"action": ["b", "action"], "condition": "checkout_mac"}],
......
...@@ -839,13 +839,15 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -839,13 +839,15 @@ class GClientSmokeGIT(GClientSmokeBase):
'}', '}',
])) ]))
self.gclient([ results = self.gclient([
'setdep', '-r', 'foo@new_foo', '-r', 'bar@new_bar', 'setdep', '-r', 'foo@new_foo', '-r', 'bar@new_bar',
'--var', 'foo_var=new_val', '--deps-file', fake_deps]) '--var', 'foo_var=new_val', '--deps-file', fake_deps])
with open(fake_deps) as f: with open(fake_deps) as f:
contents = f.read().splitlines() contents = f.read().splitlines()
self.assertEqual('', results[1])
self.assertEqual(0, results[2])
self.assertEqual([ self.assertEqual([
'vars = { ', 'vars = { ',
' "foo_var": "new_val",', ' "foo_var": "new_val",',
...@@ -879,11 +881,13 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -879,11 +881,13 @@ class GClientSmokeGIT(GClientSmokeBase):
'getdep', '-r', 'foo', '-r', 'bar','--var', 'foo_var', 'getdep', '-r', 'foo', '-r', 'bar','--var', 'foo_var',
'--deps-file', fake_deps]) '--deps-file', fake_deps])
self.assertEqual('', results[1])
self.assertEqual([ self.assertEqual([
'foo_val', 'foo_val',
'foo_rev', 'foo_rev',
'bar_rev', 'bar_rev',
], results[0].splitlines()) ], results[0].splitlines())
self.assertEqual(0, results[2])
def testFlatten(self): def testFlatten(self):
if not self.enabled: if not self.enabled:
...@@ -928,7 +932,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -928,7 +932,7 @@ class GClientSmokeGIT(GClientSmokeBase):
'deps = {', 'deps = {',
' # src -> src/repo2 -> foo/bar', ' # src -> src/repo2 -> foo/bar',
' "foo/bar": {', ' "foo/bar": {',
' "url": "/repo_3",', ' "url": "' + self.git_base + 'repo_3",',
' "condition": \'(repo2_false_var) and (true_str_var)\',', ' "condition": \'(repo2_false_var) and (true_str_var)\',',
' },', ' },',
'', '',
...@@ -939,43 +943,43 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -939,43 +943,43 @@ class GClientSmokeGIT(GClientSmokeBase):
'', '',
' # src -> src/mac_repo', ' # src -> src/mac_repo',
' "src/mac_repo": {', ' "src/mac_repo": {',
' "url": "{repo5_var}",', ' "url": "' + self.git_base + 'repo_5",',
' "condition": \'checkout_mac\',', ' "condition": \'checkout_mac\',',
' },', ' },',
'', '',
' # src -> src/repo8 -> src/recursed_os_repo', ' # src -> src/repo8 -> src/recursed_os_repo',
' "src/recursed_os_repo": {', ' "src/recursed_os_repo": {',
' "url": "/repo_5",', ' "url": "' + self.git_base + 'repo_5",',
' "condition": \'(checkout_linux) or (checkout_mac)\',', ' "condition": \'(checkout_linux) or (checkout_mac)\',',
' },', ' },',
'', '',
' # src -> src/repo2', ' # src -> src/repo2',
' "src/repo2": {', ' "src/repo2": {',
' "url": "{git_base}repo_2@%s",' % ( ' "url": "' + self.git_base + 'repo_2@%s",' % (
self.githash('repo_2', 1)[:7]), self.githash('repo_2', 1)[:7]),
' "condition": \'true_str_var\',', ' "condition": \'true_str_var\',',
' },', ' },',
'', '',
' # src -> src/repo4', ' # src -> src/repo4',
' "src/repo4": {', ' "src/repo4": {',
' "url": "/repo_4",', ' "url": "' + self.git_base + 'repo_4",',
' "condition": \'False\',', ' "condition": \'False\',',
' },', ' },',
'', '',
' # src -> src/repo8', ' # src -> src/repo8',
' "src/repo8": {', ' "src/repo8": {',
' "url": "/repo_8",', ' "url": "' + self.git_base + 'repo_8",',
' },', ' },',
'', '',
' # src -> src/unix_repo', ' # src -> src/unix_repo',
' "src/unix_repo": {', ' "src/unix_repo": {',
' "url": "{repo5_var}",', ' "url": "' + self.git_base + 'repo_5",',
' "condition": \'checkout_linux\',', ' "condition": \'checkout_linux\',',
' },', ' },',
'', '',
' # src -> src/win_repo', ' # src -> src/win_repo',
' "src/win_repo": {', ' "src/win_repo": {',
' "url": "{repo5_var}",', ' "url": "' + self.git_base + 'repo_5",',
' "condition": \'checkout_win\',', ' "condition": \'checkout_win\',',
' },', ' },',
'', '',
...@@ -991,7 +995,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -991,7 +995,7 @@ class GClientSmokeGIT(GClientSmokeBase):
' "python",', ' "python",',
' "-c",', ' "-c",',
' "open(\'src/git_hooked1\', \'w\')' ' "open(\'src/git_hooked1\', \'w\')'
'.write(\'{hook1_contents}\')",', '.write(\'git_hooked1\')",',
' ]', ' ]',
' },', ' },',
'', '',
...@@ -1089,7 +1093,8 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1089,7 +1093,8 @@ class GClientSmokeGIT(GClientSmokeBase):
'deps = {', 'deps = {',
' # src -> src/repo2 -> foo/bar', ' # src -> src/repo2 -> foo/bar',
' "foo/bar": {', ' "foo/bar": {',
' "url": "/repo_3@%s",' % (self.githash('repo_3', 2)), ' "url": "' + self.git_base + 'repo_3@%s",' % (
self.githash('repo_3', 2)),
' "condition": \'(repo2_false_var) and (true_str_var)\',', ' "condition": \'(repo2_false_var) and (true_str_var)\',',
' },', ' },',
'', '',
...@@ -1101,43 +1106,49 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1101,43 +1106,49 @@ class GClientSmokeGIT(GClientSmokeBase):
'', '',
' # src -> src/mac_repo', ' # src -> src/mac_repo',
' "src/mac_repo": {', ' "src/mac_repo": {',
' "url": "{repo5_var}@%s",' % (self.githash('repo_5', 3)), ' "url": "' + self.git_base + 'repo_5@%s",' % (
self.githash('repo_5', 3)),
' "condition": \'checkout_mac\',', ' "condition": \'checkout_mac\',',
' },', ' },',
'', '',
' # src -> src/repo8 -> src/recursed_os_repo', ' # src -> src/repo8 -> src/recursed_os_repo',
' "src/recursed_os_repo": {', ' "src/recursed_os_repo": {',
' "url": "/repo_5@%s",' % (self.githash('repo_5', 3)), ' "url": "' + self.git_base + 'repo_5@%s",' % (
self.githash('repo_5', 3)),
' "condition": \'(checkout_linux) or (checkout_mac)\',', ' "condition": \'(checkout_linux) or (checkout_mac)\',',
' },', ' },',
'', '',
' # src -> src/repo2', ' # src -> src/repo2',
' "src/repo2": {', ' "src/repo2": {',
' "url": "{git_base}repo_2@%s",' % ( ' "url": "' + self.git_base + 'repo_2@%s",' % (
self.githash('repo_2', 1)), self.githash('repo_2', 1)),
' "condition": \'true_str_var\',', ' "condition": \'true_str_var\',',
' },', ' },',
'', '',
' # src -> src/repo4', ' # src -> src/repo4',
' "src/repo4": {', ' "src/repo4": {',
' "url": "/repo_4@%s",' % (self.githash('repo_4', 2)), ' "url": "' + self.git_base + 'repo_4@%s",' % (
self.githash('repo_4', 2)),
' "condition": \'False\',', ' "condition": \'False\',',
' },', ' },',
'', '',
' # src -> src/repo8', ' # src -> src/repo8',
' "src/repo8": {', ' "src/repo8": {',
' "url": "/repo_8@%s",' % (self.githash('repo_8', 1)), ' "url": "' + self.git_base + 'repo_8@%s",' % (
self.githash('repo_8', 1)),
' },', ' },',
'', '',
' # src -> src/unix_repo', ' # src -> src/unix_repo',
' "src/unix_repo": {', ' "src/unix_repo": {',
' "url": "{repo5_var}@%s",' % (self.githash('repo_5', 3)), ' "url": "' + self.git_base + 'repo_5@%s",' % (
self.githash('repo_5', 3)),
' "condition": \'checkout_linux\',', ' "condition": \'checkout_linux\',',
' },', ' },',
'', '',
' # src -> src/win_repo', ' # src -> src/win_repo',
' "src/win_repo": {', ' "src/win_repo": {',
' "url": "{repo5_var}@%s",' % (self.githash('repo_5', 3)), ' "url": "' + self.git_base + 'repo_5@%s",' % (
self.githash('repo_5', 3)),
' "condition": \'checkout_win\',', ' "condition": \'checkout_win\',',
' },', ' },',
'', '',
...@@ -1153,7 +1164,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1153,7 +1164,7 @@ class GClientSmokeGIT(GClientSmokeBase):
' "python",', ' "python",',
' "-c",', ' "-c",',
' "open(\'src/git_hooked1\', \'w\')' ' "open(\'src/git_hooked1\', \'w\')'
'.write(\'{hook1_contents}\')",', '.write(\'git_hooked1\')",',
' ]', ' ]',
' },', ' },',
'', '',
...@@ -1256,46 +1267,46 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1256,46 +1267,46 @@ class GClientSmokeGIT(GClientSmokeBase):
'', '',
' # src -> src/repo9 -> src/repo8 -> src/recursed_os_repo', ' # src -> src/repo9 -> src/repo8 -> src/recursed_os_repo',
' "src/recursed_os_repo": {', ' "src/recursed_os_repo": {',
' "url": "/repo_5",', ' "url": "' + self.git_base + 'repo_5",',
' "condition": \'(checkout_linux) or (checkout_mac)\',', ' "condition": \'(checkout_linux) or (checkout_mac)\',',
' },', ' },',
'', '',
' # src -> src/repo11', ' # src -> src/repo11',
' "src/repo11": {', ' "src/repo11": {',
' "url": "/repo_11",', ' "url": "' + self.git_base + 'repo_11",',
' "condition": \'(checkout_ios) or (checkout_mac)\',', ' "condition": \'(checkout_ios) or (checkout_mac)\',',
' },', ' },',
'', '',
' # src -> src/repo11 -> src/repo12', ' # src -> src/repo11 -> src/repo12',
' "src/repo12": {', ' "src/repo12": {',
' "url": "/repo_12",', ' "url": "' + self.git_base + 'repo_12",',
' "condition": \'(checkout_ios) or (checkout_mac)\',', ' "condition": \'(checkout_ios) or (checkout_mac)\',',
' },', ' },',
'', '',
' # src -> src/repo9 -> src/repo4', ' # src -> src/repo9 -> src/repo4',
' "src/repo4": {', ' "src/repo4": {',
' "url": "/repo_4",', ' "url": "' + self.git_base + 'repo_4",',
' "condition": \'checkout_android\',', ' "condition": \'checkout_android\',',
' },', ' },',
'', '',
' # src -> src/repo6', ' # src -> src/repo6',
' "src/repo6": {', ' "src/repo6": {',
' "url": "/repo_6",', ' "url": "' + self.git_base + 'repo_6",',
' },', ' },',
'', '',
' # src -> src/repo9 -> src/repo7', ' # src -> src/repo9 -> src/repo7',
' "src/repo7": {', ' "src/repo7": {',
' "url": "/repo_7",', ' "url": "' + self.git_base + 'repo_7",',
' },', ' },',
'', '',
' # src -> src/repo9 -> src/repo8', ' # src -> src/repo9 -> src/repo8',
' "src/repo8": {', ' "src/repo8": {',
' "url": "/repo_8",', ' "url": "' + self.git_base + 'repo_8",',
' },', ' },',
'', '',
' # src -> src/repo9', ' # src -> src/repo9',
' "src/repo9": {', ' "src/repo9": {',
' "url": "/repo_9",', ' "url": "' + self.git_base + 'repo_9",',
' },', ' },',
'', '',
'}', '}',
......
...@@ -201,7 +201,7 @@ class GclientTest(trial_dir.TestCase): ...@@ -201,7 +201,7 @@ class GclientTest(trial_dir.TestCase):
# auto-fixed. # auto-fixed.
url = 'proto://host/path/@revision' url = 'proto://host/path/@revision'
d = gclient.Dependency( d = gclient.Dependency(
None, 'name', url, url, None, None, None, None, 'name', url, None, None, None,
None, '', True, False, None, True) None, '', True, False, None, True)
self.assertEquals('proto://host/path@revision', d.url) self.assertEquals('proto://host/path@revision', d.url)
...@@ -212,10 +212,10 @@ class GclientTest(trial_dir.TestCase): ...@@ -212,10 +212,10 @@ class GclientTest(trial_dir.TestCase):
obj.add_dependencies_and_close( obj.add_dependencies_and_close(
[ [
gclient.Dependency( gclient.Dependency(
obj, 'foo', 'svn://example.com/foo', 'svn://example.com/foo', None, obj, 'foo', 'svn://example.com/foo', None,
None, None, None, 'DEPS', True, False, None, True), None, None, None, 'DEPS', True, False, None, True),
gclient.Dependency( gclient.Dependency(
obj, 'bar', 'svn://example.com/bar', 'svn://example.com/bar', None, obj, 'bar', 'svn://example.com/bar', None,
None, None, None, 'DEPS', True, False, None, True), None, None, None, 'DEPS', True, False, None, True),
], ],
[]) [])
...@@ -223,7 +223,7 @@ class GclientTest(trial_dir.TestCase): ...@@ -223,7 +223,7 @@ class GclientTest(trial_dir.TestCase):
[ [
gclient.Dependency( gclient.Dependency(
obj.dependencies[0], 'foo/dir1', 'svn://example.com/foo/dir1', obj.dependencies[0], 'foo/dir1', 'svn://example.com/foo/dir1',
'svn://example.com/foo/dir1', None, None, None, None, 'DEPS', True, None, None, None, None, 'DEPS', True,
False, None, True), False, None, True),
], ],
[]) [])
...@@ -1130,7 +1130,7 @@ class GclientTest(trial_dir.TestCase): ...@@ -1130,7 +1130,7 @@ class GclientTest(trial_dir.TestCase):
obj.add_dependencies_and_close( obj.add_dependencies_and_close(
[ [
gclient.Dependency( gclient.Dependency(
obj, 'foo', 'svn://example.com/foo', 'svn://example.com/foo', None, obj, 'foo', 'svn://example.com/foo', None,
None, None, None, 'DEPS', True, None, None, None, 'DEPS', True,
False, None, True), False, None, True),
], ],
......
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