Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
check_licenses.py
Go to the documentation of this file.
1# Copyright 2013 The Flutter 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
5import argparse
6import os
7
8
9def contains_license_block(source_file):
10 # This check is somewhat easier than in the engine because all sources need to
11 # have the same license.
12 py_license = """# Copyright 2013 The Flutter Authors. All rights reserved.
13# Use of this source code is governed by a BSD-style license that can be
14# found in the LICENSE file."""
15 c_license = py_license.replace('#', '//')
16
17 # Make sure we don't read the entire file into memory.
18 read_size = (max(len(py_license), len(c_license)))
19
20 for lic in [c_license, py_license]:
21 with open(source_file) as source:
22 if source.read(read_size).startswith(lic):
23 return True
24
25 return False
26
27
29 known_extensions = [
30 '.cc',
31 '.cpp',
32 '.c',
33 '.h',
34 '.hpp',
35 '.py',
36 '.sh',
37 '.gn',
38 '.gni',
39 '.glsl',
40 '.sl.h',
41 '.vert',
42 '.frag',
43 '.tesc',
44 '.tese',
45 '.yaml',
46 '.dart',
47 ]
48 for extension in known_extensions:
49 if os.path.basename(path).endswith(extension):
50 return True
51 return False
52
53
54# Checks that all source files have the same license preamble.
55def main():
56 parser = argparse.ArgumentParser()
57 parser.add_argument('--source-root', type=str, required=True, help='The source root.')
58 args = parser.parse_args()
59
60 assert os.path.exists(args.source_root)
61
62 source_files = set()
63
64 for root, _, files in os.walk(os.path.abspath(args.source_root)):
65 for file in files:
66 file_path = os.path.join(root, file)
67 if is_source_file(file_path):
68 source_files.add(file_path)
69
70 for source_file in source_files:
71 if not contains_license_block(source_file):
72 raise Exception('Could not find valid license block in source ', source_file)
73
74
75if __name__ == '__main__':
76 main()
static float max(float r, float g, float b)
Definition hsl.cpp:49
contains_license_block(source_file)
Definition main.py:1