validate_config.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. # Copyright (c) 2019 The ungoogled-chromium Authors. All rights reserved.
  4. # Use of this source code is governed by a BSD-style license that can be
  5. # found in the LICENSE file.
  6. """Run sanity checking algorithms over ungoogled-chromium's config files
  7. NOTE: This script is hardcoded to run over ungoogled-chromium's config files only.
  8. To check other files, use the other scripts imported by this script.
  9. It checks the following:
  10. * All patches exist
  11. * All patches are referenced by the patch order
  12. * Each patch is used only once
  13. * GN flags in flags.gn are sorted and not duplicated
  14. * downloads.ini has the correct format (i.e. conforms to its schema)
  15. Exit codes:
  16. * 0 if no problems detected
  17. * 1 if warnings or errors occur
  18. """
  19. import sys
  20. from pathlib import Path
  21. from check_downloads_ini import check_downloads_ini
  22. from check_gn_flags import check_gn_flags
  23. from check_patch_files import (check_patch_readability, check_series_duplicates,
  24. check_unused_patches)
  25. def main():
  26. """CLI entrypoint"""
  27. warnings = False
  28. root_dir = Path(__file__).resolve().parent.parent
  29. patches_dir = root_dir / 'patches'
  30. # Check patches
  31. warnings |= check_patch_readability(patches_dir)
  32. warnings |= check_series_duplicates(patches_dir)
  33. warnings |= check_unused_patches(patches_dir)
  34. # Check GN flags
  35. warnings |= check_gn_flags(root_dir / 'flags.gn')
  36. # Check downloads.ini
  37. warnings |= check_downloads_ini([root_dir / 'downloads.ini'])
  38. if warnings:
  39. sys.exit(1)
  40. sys.exit(0)
  41. if __name__ == '__main__':
  42. if sys.argv[1:]:
  43. print(__doc__)
  44. else:
  45. main()