45
45
"===-*===" ,
46
46
]
47
47
48
+ llvm_license_py : list [str ] = [
49
+ "# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions." ,
50
+ "# See https://llvm.org/LICENSE.txt for license information." ,
51
+ "# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception"
52
+ ]
53
+
54
+
48
55
def check_license (filepath : str , license : list [str ], var : Dict [str , str ], re_line : Set [int ]):
49
56
with open (filepath , 'r' ) as f :
50
57
idx : int = 0
51
58
for line in f .readlines ():
52
59
lic : str = license [idx ]
53
- # replace the variable defined in license
54
- for k , v in var .items ():
55
- lic = lic .replace (k , v )
56
- if idx in re_line :
57
- if re .search (lic , line ) is not None and ("RE_WIDTH" not in var or int (var ["RE_WIDTH" ]) + 1 == len (line )):
58
- idx += 1
59
- elif line .find (lic ) != - 1 :
60
+ # check the string directly
61
+ if license == llvm_license_py :
62
+ if lic != line [:- 1 ]:
63
+ return False
60
64
idx += 1
65
+ else :
66
+ # replace the variable defined in license
67
+ for k , v in var .items ():
68
+ lic = lic .replace (k , v )
69
+ if idx in re_line :
70
+ if re .search (lic , line ) is not None and ("RE_WIDTH" not in var or int (var ["RE_WIDTH" ]) + 1 == len (line )):
71
+ idx += 1
72
+ elif line .find (lic ) != - 1 :
73
+ idx += 1
61
74
if idx == len (license ):
62
75
return True
63
76
return False
@@ -82,22 +95,24 @@ def fix_intel_license(var: Dict[str, str]):
82
95
def fix_llvm_license (var : Dict [str , str ]):
83
96
lang : str = var ['$LANG' ]
84
97
cmt : str = "//" # comment char
85
- if lang == "Python" :
86
- cmt = "#"
87
- elif lang == "C\\ +\\ +" :
98
+ if lang == "C\\ +\\ +" :
88
99
lang = "C++"
100
+
101
+ if lang == "Python" :
102
+ for i in range (len (llvm_license_py )):
103
+ print ((llvm_license_py [i ]))
104
+ else :
105
+ part1 = "%s===-- %s - DESC " % (cmt , var ['$FILE' ])
106
+ part3 = "-*- %s -*-===%s" % (lang , cmt )
107
+ part2 = "-" * (WIDTH - len (part1 ) - len (part3 ))
89
108
90
- part1 = "%s===-- %s - DESC " % (cmt , var ['$FILE' ])
91
- part3 = "-*- %s -*-===%s" % (lang , cmt )
92
- part2 = "-" * (WIDTH - len (part1 ) - len (part3 ))
93
-
94
- print (part1 + part2 + part3 )
95
- for i in range (1 , len (llvm_license ) - 1 ):
96
- print ((cmt + " " + llvm_license [i ]).rstrip ())
97
- part1 = cmt + "==="
98
- part3 = "===" + cmt
99
- part2 = "-" * (WIDTH - len (part1 ) - len (part3 ))
100
- print (part1 + part2 + part3 )
109
+ print (part1 + part2 + part3 )
110
+ for i in range (1 , len (llvm_license ) - 1 ):
111
+ print ((cmt + " " + llvm_license [i ]).rstrip ())
112
+ part1 = cmt + "==="
113
+ part3 = "===" + cmt
114
+ part2 = "-" * (WIDTH - len (part1 ) - len (part3 ))
115
+ print (part1 + part2 + part3 )
101
116
102
117
def use_llvm_license (path : str ) -> bool :
103
118
for folder in ["lib/gc/" , 'include/gc/' , 'unittests/' , 'python/gc_mlir' ]:
@@ -131,15 +146,18 @@ def use_llvm_license(path: str) -> bool:
131
146
132
147
is_llvm_license = use_llvm_license (filepath )
133
148
if is_llvm_license :
134
- # llvm license, only check python/cpp now
135
- lic = llvm_license
136
- re_line .add (0 )
137
- re_line .add (6 )
138
- var ['$FILE' ] = name
139
- # the line we read contains a '\n' character, so the expected length should be 81
140
- var ['RE_WIDTH' ] = str (WIDTH )
141
- if name .endswith (".td" ):
142
- var ['$LANG' ] = "tablegen"
149
+ # llvm license, only check python/cpp now
150
+ if name .endswith (".py" ):
151
+ lic = llvm_license_py
152
+ else :
153
+ lic = llvm_license
154
+ re_line .add (0 )
155
+ re_line .add (6 )
156
+ var ['$FILE' ] = name
157
+ # the line we read contains a '\n' character, so the expected length should be 81
158
+ var ['RE_WIDTH' ] = str (WIDTH )
159
+ if name .endswith (".td" ):
160
+ var ['$LANG' ] = "tablegen"
143
161
else :
144
162
# intel license
145
163
lic = intel_license
0 commit comments