Skip to content

Commit 723ba69

Browse files
committed
fix llvm license for .py
1 parent f40e433 commit 723ba69

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

scripts/license.py

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,32 @@
4545
"===-*===",
4646
]
4747

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+
4855
def check_license(filepath: str, license: list[str], var: Dict[str, str], re_line: Set[int]):
4956
with open(filepath, 'r') as f:
5057
idx: int = 0
5158
for line in f.readlines():
5259
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
6064
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
6174
if idx == len(license):
6275
return True
6376
return False
@@ -82,22 +95,24 @@ def fix_intel_license(var: Dict[str, str]):
8295
def fix_llvm_license(var: Dict[str, str]):
8396
lang: str = var['$LANG']
8497
cmt: str = "//" # comment char
85-
if lang == "Python":
86-
cmt = "#"
87-
elif lang == "C\\+\\+":
98+
if lang == "C\\+\\+":
8899
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))
89108

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)
101116

102117
def use_llvm_license(path: str) -> bool:
103118
for folder in ["lib/gc/", 'include/gc/', 'unittests/', 'python/gc_mlir']:
@@ -131,15 +146,18 @@ def use_llvm_license(path: str) -> bool:
131146

132147
is_llvm_license = use_llvm_license(filepath)
133148
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"
143161
else:
144162
# intel license
145163
lic = intel_license

0 commit comments

Comments
 (0)