gclient validate: schema fixes (patch #1)

- allow None in deps_os values (for chromeos buildspecs)
- allow string formatting (%) in expressions (for dart)
- allow empty lists/dicts (for build slaves)
- allow target_os (for internal android)

Bug: 570091, 722206, 725422
Change-Id: I7f3d822a1c4aac16fddd96ef2f9f365e05b2d0e8
Reviewed-on: https://chromium-review.googlesource.com/512724
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Paweł Hajdan Jr. <phajdan.jr@chromium.org>
changes/24/512724/3
Paweł Hajdan, Jr 9 years ago committed by Commit Bot
parent 7c7b5592d8
commit b7e533360c

@ -25,7 +25,7 @@ _GCLIENT_SCHEMA = schema.Schema({
# List of host names from which dependencies are allowed (whitelist).
# NOTE: when not present, all hosts are allowed.
# NOTE: scoped to current DEPS file, not recursive.
schema.Optional('allowed_hosts'): [basestring],
schema.Optional('allowed_hosts'): [schema.Optional(basestring)],
# Mapping from paths to repo and revision to check out under that path.
# Applying this mapping to the on-disk checkout is the main purpose
@ -38,7 +38,12 @@ _GCLIENT_SCHEMA = schema.Schema({
schema.Optional('deps'): {schema.Optional(basestring): basestring},
# Similar to 'deps' (see above) - also keyed by OS (e.g. 'linux').
schema.Optional('deps_os'): {basestring: {basestring: basestring}},
# Also see 'target_os'.
schema.Optional('deps_os'): {
schema.Optional(basestring): {
schema.Optional(basestring): schema.Or(basestring, None)
}
},
# Hooks executed after gclient sync (unless suppressed), or explicitly
# on gclient hooks. See _GCLIENT_HOOKS_SCHEMA for details.
@ -46,33 +51,41 @@ _GCLIENT_SCHEMA = schema.Schema({
schema.Optional('hooks'): _GCLIENT_HOOKS_SCHEMA,
# Similar to 'hooks', also keyed by OS.
schema.Optional('hooks_os'): {basestring: _GCLIENT_HOOKS_SCHEMA},
schema.Optional('hooks_os'): {
schema.Optional(basestring): _GCLIENT_HOOKS_SCHEMA
},
# Rules which #includes are allowed in the directory.
# Also see 'skip_child_includes' and 'specific_include_rules'.
schema.Optional('include_rules'): [basestring],
schema.Optional('include_rules'): [schema.Optional(basestring)],
# Hooks executed before processing DEPS. See 'hooks' for more details.
schema.Optional('pre_deps_hooks'): _GCLIENT_HOOKS_SCHEMA,
# Whitelists deps for which recursion should be enabled.
schema.Optional('recursedeps'): [
schema.Or(basestring, (basestring, basestring))
schema.Optional(schema.Or(basestring, (basestring, basestring)))
],
# Blacklists directories for checking 'include_rules'.
schema.Optional('skip_child_includes'): [basestring],
schema.Optional('skip_child_includes'): [schema.Optional(basestring)],
# Mapping from paths to include rules specific for that path.
# See 'include_rules' for more details.
schema.Optional('specific_include_rules'): {basestring: [basestring]},
schema.Optional('specific_include_rules'): {
schema.Optional(basestring): [basestring]
},
# List of additional OS names to consider when selecting dependencies
# from deps_os.
schema.Optional('target_os'): [schema.Optional(basestring)],
# For recursed-upon sub-dependencies, check out their own dependencies
# relative to the paren't path, rather than relative to the .gclient file.
schema.Optional('use_relative_paths'): bool,
# Variables that can be referenced using Var() - see 'deps'.
schema.Optional('vars'): {basestring: basestring},
schema.Optional('vars'): {schema.Optional(basestring): basestring},
})
@ -112,6 +125,8 @@ def _gclient_eval(node_or_string, global_scope, filename='<unknown>'):
return global_scope[node.func.id](*args)
elif isinstance(node, ast.BinOp) and isinstance(node.op, ast.Add):
return _convert(node.left) + _convert(node.right)
elif isinstance(node, ast.BinOp) and isinstance(node.op, ast.Mod):
return _convert(node.left) % _convert(node.right)
else:
raise ValueError(
'unexpected AST node: %s (file %r, line %s)' % (

@ -44,6 +44,9 @@ class GClientEvalTest(unittest.TestCase):
def test_plus(self):
self.assertEqual('foo', gclient_eval._gclient_eval('"f" + "o" + "o"', {}))
def test_format(self):
self.assertEqual('foo', gclient_eval._gclient_eval('"%s" % "foo"', {}))
def test_not_expression(self):
with self.assertRaises(SyntaxError) as cm:
gclient_eval._gclient_eval('def foo():\n pass', {})

Loading…
Cancel
Save