Commit 67cabcd7 authored by Edward Lemur's avatar Edward Lemur Committed by LUCI CQ

gclient: Remove syntax validation flags.

Change-Id: I7215335eb4592cba80d31595b3bac75f55372dee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2083589Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent a3b6fd06
......@@ -716,8 +716,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
if deps_content:
try:
local_scope = gclient_eval.Parse(
deps_content, self._get_option('validate_syntax', False),
filepath, self.get_vars(), self.get_builtin_vars())
deps_content, filepath, self.get_vars(), self.get_builtin_vars())
except SyntaxError as e:
gclient_utils.SyntaxErrorToError(filepath, e)
......@@ -2698,12 +2697,6 @@ def CMDsync(parser, args):
help='DEPRECATED: This is a no-op.')
parser.add_option('-m', '--manually_grab_svn_rev', action='store_true',
help='DEPRECATED: This is a no-op.')
# TODO(phajdan.jr): Remove validation options once default (crbug/570091).
parser.add_option('--validate-syntax', action='store_true', default=True,
help='Validate the .gclient and DEPS syntax')
parser.add_option('--disable-syntax-validation', action='store_false',
dest='validate_syntax',
help='Disable validation of .gclient and DEPS syntax.')
parser.add_option('--no-rebase-patch-ref', action='store_false',
dest='rebase_patch_ref', default=True,
help='Bypass rebase of the patch ref after checkout.')
......@@ -2745,7 +2738,6 @@ CMDupdate = CMDsync
def CMDvalidate(parser, args):
"""Validates the .gclient and DEPS syntax."""
options, args = parser.parse_args(args)
options.validate_syntax = True
client = GClient.LoadCurrentConfig(options)
rv = client.RunOnDeps('validate', args)
if rv == 0:
......
......@@ -372,44 +372,10 @@ def Exec(content, filename='<unknown>', vars_override=None, builtin_vars=None):
value = _gclient_eval(node, filename, vars_dict)
local_scope.SetNode(name, value, node)
return _GCLIENT_SCHEMA.validate(local_scope)
def ExecLegacy(content, filename='<unknown>', vars_override=None,
builtin_vars=None):
"""Executes a DEPS file |content| using exec."""
local_scope = {}
global_scope = {'Var': lambda var_name: '{%s}' % var_name}
# If we use 'exec' directly, it complains that 'Parse' contains a nested
# function with free variables.
# This is because on versions of Python < 2.7.9, "exec(a, b, c)" not the same
# as "exec a in b, c" (See https://bugs.python.org/issue21591).
eval(compile(content, filename, 'exec'), global_scope, local_scope)
vars_dict = {}
vars_dict.update(local_scope.get('vars', {}))
if builtin_vars:
vars_dict.update(builtin_vars)
if vars_override:
vars_dict.update({k: v for k, v in vars_override.items() if k in vars_dict})
if not vars_dict:
return local_scope
def _DeepFormat(node):
if isinstance(node, basestring):
return node.format(**vars_dict)
elif isinstance(node, dict):
return {k.format(**vars_dict): _DeepFormat(v) for k, v in node.items()}
elif isinstance(node, list):
return [_DeepFormat(elem) for elem in node]
elif isinstance(node, tuple):
return tuple(_DeepFormat(elem) for elem in node)
else:
return node
return _DeepFormat(local_scope)
try:
return _GCLIENT_SCHEMA.validate(local_scope)
except schema.SchemaError as e:
raise gclient_utils.Error(str(e))
def _StandardizeDeps(deps_dict, vars_dict):
......@@ -477,8 +443,7 @@ def UpdateCondition(info_dict, op, new_condition):
del info_dict['condition']
def Parse(content, validate_syntax, filename, vars_override=None,
builtin_vars=None):
def Parse(content, filename, vars_override=None, builtin_vars=None):
"""Parses DEPS strings.
Executes the Python-like string stored in content, resulting in a Python
......@@ -487,8 +452,6 @@ def Parse(content, validate_syntax, filename, vars_override=None,
Args:
content: str. DEPS file stored as a string.
validate_syntax: bool. Whether syntax should be validated using the schema
defined above.
filename: str. The name of the DEPS file, or a string describing the source
of the content, e.g. '<string>', '<unknown>'.
vars_override: dict, optional. A dictionary with overrides for the variables
......@@ -500,10 +463,7 @@ def Parse(content, validate_syntax, filename, vars_override=None,
A Python dict with the parsed contents of the DEPS file, as specified by the
schema above.
"""
if validate_syntax:
result = Exec(content, filename, vars_override, builtin_vars)
else:
result = ExecLegacy(content, filename, vars_override, builtin_vars)
result = Exec(content, filename, vars_override, builtin_vars)
vars_dict = result.get('vars', {})
if 'deps' in result:
......
This diff is collapsed.
......@@ -1002,7 +1002,6 @@ class GclientTest(trial_dir.TestCase):
'}')
options, _ = gclient.OptionParser().parse_args([])
options.ignore_dep_type = 'git'
options.validate_syntax = True
obj = gclient.GClient.LoadCurrentConfig(options)
self.assertEqual(1, len(obj.dependencies))
......@@ -1132,7 +1131,7 @@ class GclientTest(trial_dir.TestCase):
obj.RunOnDeps('None', [])
self.fail()
except gclient_utils.Error as e:
self.assertIn('allowed_hosts must be', str(e))
self.assertIn('Key \'allowed_hosts\' error:', str(e))
finally:
self._get_processed()
......@@ -1160,7 +1159,6 @@ class GclientTest(trial_dir.TestCase):
' }\n'
'}')
options, _ = gclient.OptionParser().parse_args([])
options.validate_syntax = True
obj = gclient.GClient.LoadCurrentConfig(options)
self.assertEqual(1, len(obj.dependencies))
......@@ -1202,7 +1200,6 @@ class GclientTest(trial_dir.TestCase):
'}')
options, _ = gclient.OptionParser().parse_args([])
options.ignore_dep_type = 'cipd'
options.validate_syntax = True
obj = gclient.GClient.LoadCurrentConfig(options)
self.assertEqual(1, len(obj.dependencies))
......
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