PRESUBMIT.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (c) 2020 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. """Enforces workaround list is alphabetically sorted.
  5. See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
  6. for more details on the presubmit API built into depot_tools.
  7. """
  8. import difflib
  9. import os.path
  10. import io
  11. USE_PYTHON3 = True
  12. def _CheckGPUWorkaroundListSorted(input_api, output_api):
  13. """Check: gpu_workaround_list.txt feature list sorted alphabetically.
  14. """
  15. filename = os.path.join(input_api.PresubmitLocalPath(),
  16. 'gpu_workaround_list.txt')
  17. with io.open(filename, encoding='utf-8') as f:
  18. workaround_list = [line.rstrip('\n') for line in f]
  19. workaround_list_sorted = sorted(workaround_list, key=lambda s: s.lower())
  20. if workaround_list == workaround_list_sorted:
  21. return []
  22. # Diff the sorted/unsorted versions.
  23. differ = difflib.Differ()
  24. diff = differ.compare(workaround_list, workaround_list_sorted)
  25. return [output_api.PresubmitError(
  26. 'gpu_workaround_list.txt features must be sorted alphabetically. '
  27. 'Diff of feature order follows:', long_text='\n'.join(diff))]
  28. def CheckChangeOnUpload(input_api, output_api):
  29. return _CheckGPUWorkaroundListSorted(input_api, output_api)
  30. def CheckChangeOnCommit(input_api, output_api):
  31. return _CheckGPUWorkaroundListSorted(input_api, output_api)