blob: 663f298ba03be7c62f48db82b0ac53fb9a14aa5c [file] [log] [blame]
yang.li8c78ed62022-03-08 13:50:52 +08001#!/usr/bin/python3
2#coding:utf-8
3#
4# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
5#
6# SPDX-License-Identifier: MIT
7#
8
9import os
10import sys
11import string
12import re
13
14#file type contains .[chS]/.ld
15def src_file_check_license(line):
16 license =\
17'''/*
18 * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
19 *
20 * SPDX-License-Identifier: MIT
21 */\n
22'''
23 if(line.find('\r\n') > 0):
24 line_new = re.sub("\r\n", "\n", line)
25 return line_new.find(license)
26 else:
27 return line.find(license)
28
29#file type contains Script/defconfig/prj.conf
30def script_file_check_license(line):
31 license =\
32'''#
33# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
34#
35# SPDX-License-Identifier: MIT
36#\n
37'''
38 if(line.find('\r\n') > 0):
39 line_new = re.sub("\r\n", "\n", line)
40 return line_new.find(license)
41 else:
42 return line.find(license)
43
44#file type contains Kconfig/CMakeLists.txt
45def cfg_file_check_license(line):
46 license =\
47'''# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
48
49# SPDX-License-Identifier: MIT\n
50'''
51 if(line.find('\r\n') > 0):
52 line_new = re.sub("\r\n", "\n", line)
53 return line_new.find(license)
54 else:
55 return line.find(license)
56
57if __name__ == '__main__':
58 check_ret = 0
59 src_type = ['.c','.h','.S', '.ld']
60 cfg_type = ['Kconfig', 'CMakeLists.txt', '.cmake']
61 script_type = ['.sh', '.py', '.conf', 'defconfig']
62 line = sys.stdin.readline()
63 while line:
64 if 'diff --git' in line:
65 #diff start of file, and get the file name
66 file = line.split(' ')[-1].strip()
67 file = file.split('/', 1)[1]
68 line = sys.stdin.readline()
69 patch_str = ''
70 if 'new file mode' in line:
71 #new file in patch, and save the patch string
72 try:
73 for line in sys.stdin:
74 if 'diff --git' in line:
75 break
76 patch_str += line[1:]
77 except:
78 print("read patch exception!!")
79
80 if file.split('/')[-1] in cfg_type:
81 ret = cfg_file_check_license(patch_str)
82 if ret < 0:
83 print(file + ' license error\r\n')
84 check_ret = 1
85 continue
86
87 if os.path.splitext(file)[-1] in src_type:
88 ret = src_file_check_license(patch_str)
89 if ret < 0:
90 print(file + ' license error\r\n')
91 check_ret = 1
92 continue
93
94 if os.path.splitext(file)[-1] in script_type:
95 ret = script_file_check_license(patch_str)
96 if ret < 0:
97 print(file + ' license error\r\n')
98 check_ret = 1
99 continue
100 line = sys.stdin.readline()
101
102 if check_ret != 0:
103 print('\nRTOS Opensource License Check Failed, ')
104 print('refs http://tee.amlogic.com:8000/Documents/Ecosystem/RTOS/rtos-sdk/licensing.html')
105 else:
106 print('\nRTOS Opensource License Check Success\n')