Commit 3c117949 authored by Edward Lemur's avatar Edward Lemur Committed by LUCI CQ

gclient_eval: Raise an error on implicitly concatenated strings.

Implicitly concatenated strings are not supported when setting new
revisions, so raise an error when attempting to do se.

Bug: 1060772
Change-Id: I74d39b9eb8dcc420e9b7787c90bee642beb783cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2099407Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent 1ee78cda
...@@ -759,6 +759,14 @@ def SetRevision(gclient_dict, dep_name, new_revision): ...@@ -759,6 +759,14 @@ def SetRevision(gclient_dict, dep_name, new_revision):
if isinstance(node, ast.BinOp): if isinstance(node, ast.BinOp):
node = node.right node = node.right
token = tokens[node.lineno, node.col_offset][1][1:-1]
if isinstance(node, ast.Str) and token != node.s:
raise ValueError(
'Can\'t update value for %s. Multiline strings and implicitly '
'concatenated strings are not supported.\n'
'Consider reformatting the DEPS file.' % dep_key)
if not isinstance(node, ast.Call) and not isinstance(node, ast.Str): if not isinstance(node, ast.Call) and not isinstance(node, ast.Str):
raise ValueError( raise ValueError(
"Unsupported dependency revision format. Please file a bug to the " "Unsupported dependency revision format. Please file a bug to the "
......
...@@ -265,6 +265,8 @@ def main(): ...@@ -265,6 +265,8 @@ def main():
except Error as e: except Error as e:
sys.stderr.write('error: %s\n' % e) sys.stderr.write('error: %s\n' % e)
return 2 if isinstance(e, AlreadyRolledError) else 1 return 2 if isinstance(e, AlreadyRolledError) else 1
except subprocess.CalledProcessError:
return 1
print('') print('')
if not reviewers: if not reviewers:
......
...@@ -663,6 +663,37 @@ class RevisionTest(unittest.TestCase): ...@@ -663,6 +663,37 @@ class RevisionTest(unittest.TestCase):
] ]
self.assert_gets_and_sets_revision(before, after) self.assert_gets_and_sets_revision(before, after)
def test_revision_multiline_strings(self):
deps = [
'deps = {',
' "src/dep": "https://example.com/dep.git@"',
' "deadbeef",',
'}',
]
with self.assertRaises(ValueError) as e:
local_scope = gclient_eval.Exec('\n'.join(deps))
gclient_eval.SetRevision(local_scope, 'src/dep', 'deadfeed')
self.assertEqual(
'Can\'t update value for src/dep. Multiline strings and implicitly '
'concatenated strings are not supported.\n'
'Consider reformatting the DEPS file.',
str(e.exception))
def test_revision_implicitly_concatenated_strings(self):
deps = [
'deps = {',
' "src/dep": "https://example.com" + "/dep.git@" "deadbeef",',
'}',
]
with self.assertRaises(ValueError) as e:
local_scope = gclient_eval.Exec('\n'.join(deps))
gclient_eval.SetRevision(local_scope, 'src/dep', 'deadfeed')
self.assertEqual(
'Can\'t update value for src/dep. Multiline strings and implicitly '
'concatenated strings are not supported.\n'
'Consider reformatting the DEPS file.',
str(e.exception))
def test_revision_inside_dict(self): def test_revision_inside_dict(self):
before = [ before = [
'deps = {', 'deps = {',
......
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