PRESUBMIT.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright 2018 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. """Check the basic functionalities of WPT tools.
  5. This PRESUBMIT guards against rolling a broken version of WPT tooling. It does
  6. some smoke checks of WPT functionality.
  7. """
  8. USE_PYTHON3 = True
  9. def _TestWPTLint(input_api, output_api):
  10. # We test 'wpt lint' by deferring to the web_tests/external presubmit test,
  11. # which runs 'wpt lint' against web_tests/external/wpt.
  12. abspath_to_test = input_api.os_path.join(
  13. input_api.change.RepositoryRoot(),
  14. 'third_party', 'blink', 'web_tests', 'external', 'PRESUBMIT_test.py'
  15. )
  16. command = input_api.Command(
  17. name='web_tests/external/PRESUBMIT_test.py',
  18. cmd=[abspath_to_test],
  19. kwargs={},
  20. message=output_api.PresubmitError,
  21. python3=True
  22. )
  23. if input_api.verbose:
  24. print('Running ' + abspath_to_test)
  25. return input_api.RunTests([command])
  26. def _TestWPTManifest(input_api, output_api):
  27. # We test 'wpt manifest' by making a copy of the base manifest and updating
  28. # it. A copy is used so that this PRESUBMIT doesn't change files in the tree.
  29. blink_path = input_api.os_path.join(
  30. input_api.change.RepositoryRoot(), 'third_party', 'blink')
  31. base_manifest = input_api.os_path.join(
  32. blink_path, 'web_tests', 'external', 'WPT_BASE_MANIFEST_8.json')
  33. with input_api.CreateTemporaryFile(mode = 'wt') as f:
  34. f.write(input_api.ReadFile(base_manifest))
  35. f.close()
  36. wpt_exec_path = input_api.os_path.join(
  37. input_api.change.RepositoryRoot(), 'third_party', 'wpt_tools', 'wpt', 'wpt')
  38. external_wpt = input_api.os_path.join(
  39. blink_path, 'web_tests', 'external', 'wpt')
  40. try:
  41. input_api.subprocess.check_output(
  42. ['python3', wpt_exec_path, 'manifest', '--no-download',
  43. '--path', f.name, '--tests-root', external_wpt])
  44. except input_api.subprocess.CalledProcessError as exc:
  45. return [output_api.PresubmitError('wpt manifest failed:', long_text=exc.output)]
  46. return []
  47. def CheckChangeOnUpload(input_api, output_api):
  48. results = []
  49. results += _TestWPTLint(input_api, output_api)
  50. results += _TestWPTManifest(input_api, output_api)
  51. return results
  52. def CheckChangeOnCommit(input_api, output_api):
  53. results = []
  54. results += _TestWPTLint(input_api, output_api)
  55. results += _TestWPTManifest(input_api, output_api)
  56. return results