checklicenses.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. # Copyright 2015 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import json
  6. import os
  7. import sys
  8. # Add src/testing/ into sys.path for importing common without pylint errors.
  9. sys.path.append(
  10. os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
  11. from scripts import common
  12. def main_run(args):
  13. with common.temporary_file() as tempfile_path:
  14. rc = common.run_command([
  15. os.path.join(common.SRC_DIR, 'tools', 'checklicenses',
  16. 'checklicenses.py'),
  17. '--json', tempfile_path
  18. ])
  19. with open(tempfile_path) as f:
  20. checklicenses_results = json.load(f)
  21. result_set = set()
  22. for result in checklicenses_results:
  23. result_set.add((result['filename'], result['license']))
  24. json.dump({
  25. 'valid': True,
  26. 'failures': ['%s: %s' % (r[0], r[1]) for r in result_set],
  27. }, args.output)
  28. return rc
  29. def main_compile_targets(args):
  30. json.dump([], args.output)
  31. if __name__ == '__main__':
  32. funcs = {
  33. 'run': main_run,
  34. 'compile_targets': main_compile_targets,
  35. }
  36. sys.exit(common.run_script(sys.argv[1:], funcs))