-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathlicense-check.py
More file actions
executable file
·153 lines (134 loc) · 5.6 KB
/
license-check.py
File metadata and controls
executable file
·153 lines (134 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python
import sys
import os
from pathlib import Path
import subprocess
BSL_HEADER = """
// Copyright {YEAR} Boundless Foundation, Inc.
//
// Use of this source code is governed by the Business Source License
// as found in the LICENSE-BSL file.
""".strip().splitlines()
APACHE_HEADER = """
// Copyright {YEAR} Boundless Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
""".strip().splitlines()
EXTENSIONS = [
".cpp",
".h",
".rs",
'.sol',
]
SKIP_PATHS = [
str(Path.cwd()) + "/blake3_groth16/src/seal_to_json.rs",
# ImageID.sol is automatically generated.
str(Path.cwd()) + "/contracts/src/SetBuilderImageID.sol",
str(Path.cwd()) + "/contracts/src/libraries/AssessorImageID.sol",
str(Path.cwd()) + "/contracts/src/libraries/UtilImageID.sol",
str(Path.cwd()) + "/contracts/src/verifier/RiscZeroVerifierRouter.sol",
str(Path.cwd()) + "/contracts/src/blake3-groth16/Groth16Verifier.sol",
str(Path.cwd()) + "/contracts/shanghai/src/SetBuilderImageID.sol",
str(Path.cwd()) + "/contracts/shanghai/src/libraries/AssessorImageID.sol",
str(Path.cwd()) + "/contracts/shanghai/src/libraries/UtilImageID.sol",
str(Path.cwd()) + "/contracts/shanghai/src/verifier/RiscZeroVerifierRouter.sol",
str(Path.cwd()) + "/contracts/shanghai/src/blake3-groth16/Groth16Verifier.sol",
str(Path.cwd()) + "/contracts/shanghai/src/compat/Bytes.sol",
str(Path.cwd()) + "/crates/boundless-market/src/contracts/artifacts",
str(Path.cwd()) + "/crates/boundless-market/src/contracts/bytecode.rs",
str(Path.cwd()) + "/crates/povw/src/contracts/artifacts",
str(Path.cwd()) + "/crates/zkc/src/contracts/artifacts",
str(Path.cwd()) + "/crates/povw/src/contracts/bytecode.rs",
]
APACHE_PATHS = [
str(Path.cwd()) + "/blake3_groth16",
str(Path.cwd()) + "/contracts/src/HitPoints.sol",
str(Path.cwd()) + "/contracts/src/IBoundlessMarket.sol",
str(Path.cwd()) + "/contracts/src/IHitPoints.sol",
str(Path.cwd()) + "/contracts/src/povw/IPovwAccounting.sol",
str(Path.cwd()) + "/contracts/src/povw/IPovwMint.sol",
str(Path.cwd()) + "/contracts/src/zkc/IStakingRewards.sol",
str(Path.cwd()) + "/contracts/shanghai/src/HitPoints.sol",
str(Path.cwd()) + "/contracts/shanghai/src/IBoundlessMarket.sol",
str(Path.cwd()) + "/contracts/shanghai/src/IHitPoints.sol",
str(Path.cwd()) + "/contracts/shanghai/src/povw/IPovwAccounting.sol",
str(Path.cwd()) + "/contracts/shanghai/src/povw/IPovwMint.sol",
str(Path.cwd()) + "/contracts/shanghai/src/zkc/IStakingRewards.sol",
str(Path.cwd()) + "/crates/bench",
str(Path.cwd()) + "/crates/boundless-cli",
str(Path.cwd()) + "/crates/boundless-market",
str(Path.cwd()) + "/crates/broker",
str(Path.cwd()) + "/crates/broker-stress",
str(Path.cwd()) + "/crates/distributor",
str(Path.cwd()) + "/crates/executor",
str(Path.cwd()) + "/crates/guest/util",
str(Path.cwd()) + "/crates/indexer",
str(Path.cwd()) + "/crates/ops-lambdas",
str(Path.cwd()) + "/crates/order-generator",
str(Path.cwd()) + "/crates/order-stream",
str(Path.cwd()) + "/crates/requestor-lists",
str(Path.cwd()) + "/crates/slasher",
str(Path.cwd()) + "/crates/test-utils",
str(Path.cwd()) + "/examples",
str(Path.cwd()) + "/crates/lambdas",
str(Path.cwd()) + "/crates/rewards",
str(Path.cwd()) + "/xtask",
]
def check_header(file, expected_year, lines_actual):
if any(map(lambda path: file.is_relative_to(path), APACHE_PATHS)):
header = APACHE_HEADER
else:
header = BSL_HEADER
for expected, actual in zip(header, lines_actual):
expected = expected.replace("{YEAR}", expected_year)
if expected != actual:
return (expected, actual)
return None
def check_file(root, file):
cmd = ["git", "log", "-1", "--format=%ad", "--date=format:%Y", file]
expected_year = subprocess.check_output(cmd, encoding="UTF-8").strip()
rel_path = file.relative_to(root)
lines = file.read_text().splitlines()
result = check_header(file, expected_year, lines)
if result:
print(f"{rel_path}: invalid header!")
print(f" expected: {result[0]}")
print(f" actual: {result[1]}")
return 1
return 0
def repo_root():
"""Return an absolute Path to the repo root"""
cmd = ["git", "rev-parse", "--show-toplevel"]
return Path(subprocess.check_output(cmd, encoding="UTF-8").strip())
def tracked_files():
"""Yield all file paths tracked by git"""
cmd = ["git", "ls-tree", "--full-tree", "--name-only", "-r", "HEAD"]
tree = subprocess.check_output(cmd, encoding="UTF-8").strip()
for path in tree.splitlines():
yield (repo_root() / Path(path)).absolute()
def main():
root = repo_root()
ret = 0
for path in tracked_files():
if path.suffix in EXTENSIONS:
skip = False
for path_start in SKIP_PATHS:
if str(path).startswith(path_start):
skip = True
break
if skip:
continue
ret |= check_file(root, path)
sys.exit(ret)
if __name__ == "__main__":
main()