• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #!/usr/bin/env python
2 
3 # Copyright JS Foundation and other contributors, http://js.foundation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 from __future__ import print_function
18 
19 import io
20 import os
21 import re
22 import sys
23 import settings
24 
25 LICENSE = re.compile(
26     r'((#|//|\*) Copyright .*\n'
27     r')+\s?\2\n'
28     r'\s?\2 Licensed under the Apache License, Version 2.0 \(the "License"\);\n'
29     r'\s?\2 you may not use this file except in compliance with the License.\n'
30     r'\s?\2 You may obtain a copy of the License at\n'
31     r'\s?\2\n'
32     r'\s?\2     http://www.apache.org/licenses/LICENSE-2.0\n'
33     r'\s?\2\n'
34     r'\s?\2 Unless required by applicable law or agreed to in writing, software\n'
35     r'\s?\2 distributed under the License is distributed on an "AS IS" BASIS\n'
36     r'\s?\2 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'
37     r'\s?\2 See the License for the specific language governing permissions and\n'
38     r'\s?\2 limitations under the License.\n'
39 )
40 
41 INCLUDE_DIRS = [
42     'cmake',
43     'jerry-core',
44     'jerry-ext',
45     'jerry-libm',
46     'jerry-main',
47     'jerry-port',
48     'targets',
49     'tests',
50     'tools',
51 ]
52 
53 EXCLUDE_DIRS = [
54     'targets/esp8266',
55     os.path.relpath(settings.TEST262_TEST_SUITE_DIR, settings.PROJECT_DIR),
56 ]
57 
58 EXTENSIONS = [
59     '.c',
60     '.cpp',
61     '.h',
62     '.S',
63     '.js',
64     '.py',
65     '.sh',
66     '.tcl',
67     '.cmake',
68 ]
69 
70 
71 def main():
72     is_ok = True
73 
74     for dname in INCLUDE_DIRS:
75         for root, _, files in os.walk(dname):
76             if any(root.startswith(exclude) for exclude in EXCLUDE_DIRS):
77                 continue
78             for fname in files:
79                 if any(fname.endswith(ext) for ext in EXTENSIONS):
80                     fpath = os.path.join(root, fname)
81                     with io.open(fpath, 'r', errors='ignore') as curr_file:
82                         if not LICENSE.search(curr_file.read()):
83                             print('%s: incorrect license' % fpath)
84                             is_ok = False
85 
86     if not is_ok:
87         sys.exit(1)
88 
89 
90 if __name__ == '__main__':
91     main()
92