Add CheckVPythonSpec for verifying .vpython file syntax

This check will be used in Chromium, V8 and Catapult PRESUBMIT scripts.

R=maruel@chromium.org, tandrii@chromium.org

Bug: 777893
Change-Id: I2ca1e774b89787c4d3b5f336315d145571858864
Reviewed-on: https://chromium-review.googlesource.com/738169
Commit-Queue: Sergiy Byelozyorov <sergiyb@google.com>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
Reviewed-by: Daniel Jacques <dnj@chromium.org>
changes/69/738169/9
Sergiy Byelozyorov 7 years ago committed by Commit Bot
parent 0a01aa6823
commit eba8347018

@ -1279,3 +1279,32 @@ def CheckCIPDPackages(input_api, output_api, platforms, packages):
for k, v in packages.iteritems():
manifest.append('%s %s' % (k, v))
return CheckCIPDManifest(input_api, output_api, content='\n'.join(manifest))
def CheckVPythonSpec(input_api, output_api, file_filter=None):
"""Validates any changed .vpython files with vpython verification tool.
Args:
input_api: Bag of input related interfaces.
output_api: Bag of output related interfaces.
file_filter: Custom function that takes a path (relative to client root) and
returns boolean, which is used to filter files for which to apply the
verification to. Defaults to any path ending with .vpython, which captures
both global .vpython and <script>.vpython files.
Returns:
A list of input_api.Command objects containing verification commands.
"""
file_filter = file_filter or (lambda f: f.LocalPath().endswith('.vpython'))
affected_files = input_api.AffectedFiles(file_filter=file_filter)
affected_files = map(lambda f: f.AbsoluteLocalPath(), affected_files)
commands = []
for f in affected_files:
commands.append(input_api.Command(
'Verify %s' % f,
['vpython', '-vpython-spec', f, '-vpython-tool', 'verify'],
{'stderr': input_api.subprocess.STDOUT},
output_api.PresubmitError))
return commands

@ -1707,6 +1707,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
'CheckGNFormatted',
'CheckRietveldTryJobExecution',
'CheckSingletonInHeaders',
'CheckVPythonSpec',
'RunPythonUnitTests', 'RunPylint',
'RunUnitTests', 'RunUnitTestsInDirectory',
'GetCodereviewOwnerAndReviewers',
@ -2832,6 +2833,31 @@ class CannedChecksUnittest(PresubmitTestsBase):
['cipd', 'ensure-file-verify', '-ensure-file=-'])
self.assertEquals(command.kwargs, {'stdin': content})
def testCannedCheckVPythonSpec(self):
change = presubmit.Change('a', 'b', self.fake_root_dir, None, 0, 0, None)
input_api = self.MockInputApi(change, False)
affected_file = self.mox.CreateMock(presubmit.GitAffectedFile)
affected_file.AbsoluteLocalPath().AndReturn('/path1/to/.vpython')
input_api.AffectedFiles(
file_filter=mox.IgnoreArg()).AndReturn([affected_file])
self.mox.ReplayAll()
commands = presubmit_canned_checks.CheckVPythonSpec(
input_api, presubmit.OutputApi)
self.assertEqual(len(commands), 1)
self.assertEqual(commands[0].name, 'Verify /path1/to/.vpython')
self.assertEqual(commands[0].cmd, [
'vpython',
'-vpython-spec', '/path1/to/.vpython',
'-vpython-tool', 'verify'
])
self.assertDictEqual(
commands[0].kwargs, {'stderr': input_api.subprocess.STDOUT})
self.assertEqual(commands[0].message, presubmit.OutputApi.PresubmitError)
self.assertIsNone(commands[0].info)
if __name__ == '__main__':
import unittest

Loading…
Cancel
Save