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