2019-04-26 18:27:27 +03:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the Apache 2.0 License.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
2019-10-29 18:05:58 +03:00
|
|
|
NOTICE_LINES_CCF = [
|
2019-04-26 18:27:27 +03:00
|
|
|
"Copyright (c) Microsoft Corporation. All rights reserved.",
|
|
|
|
"Licensed under the Apache 2.0 License.",
|
|
|
|
]
|
|
|
|
|
2019-10-29 18:05:58 +03:00
|
|
|
PREFIXES_CCF = [
|
|
|
|
os.linesep.join([prefix + " " + line for line in NOTICE_LINES_CCF])
|
2019-04-26 18:27:27 +03:00
|
|
|
for prefix in ["//", "--", "#"]
|
|
|
|
]
|
2019-10-29 18:05:58 +03:00
|
|
|
PREFIXES_CCF.append("#!/bin/bash" + os.linesep + PREFIXES_CCF[-1])
|
|
|
|
|
|
|
|
NOTICE_LINES_PBFT = [
|
|
|
|
"Copyright (c) Microsoft Corporation.",
|
|
|
|
"Copyright (c) 1999 Miguel Castro, Barbara Liskov.",
|
|
|
|
"Copyright (c) 2000, 2001 Miguel Castro, Rodrigo Rodrigues, Barbara Liskov.",
|
|
|
|
"Licensed under the MIT license.",
|
|
|
|
]
|
|
|
|
|
|
|
|
PREFIXES_PBFT = [
|
|
|
|
os.linesep.join([prefix + " " + line for line in NOTICE_LINES_PBFT])
|
|
|
|
for prefix in ["//", "--", "#"]
|
|
|
|
] + [
|
|
|
|
os.linesep.join(
|
|
|
|
[prefix + " " + line for line in [NOTICE_LINES_PBFT[0], NOTICE_LINES_PBFT[3]]]
|
|
|
|
)
|
|
|
|
for prefix in ["//", "--", "#"]
|
|
|
|
]
|
|
|
|
|
|
|
|
PREFIXES_PBFT.append("#!/bin/bash" + os.linesep + PREFIXES_PBFT[-1])
|
2019-04-26 18:27:27 +03:00
|
|
|
|
|
|
|
|
2019-10-29 18:05:58 +03:00
|
|
|
def has_notice(path, prefixes):
|
2019-04-26 18:27:27 +03:00
|
|
|
with open(path) as f:
|
|
|
|
text = f.read()
|
2019-10-29 18:05:58 +03:00
|
|
|
for prefix in prefixes:
|
2019-04-26 18:27:27 +03:00
|
|
|
if text.startswith(prefix):
|
|
|
|
return True
|
2019-07-08 10:48:48 +03:00
|
|
|
return False
|
2019-04-26 18:27:27 +03:00
|
|
|
|
|
|
|
|
|
|
|
def is_src(name):
|
2019-11-20 14:18:15 +03:00
|
|
|
for suffix in [".c", ".cpp", ".h", ".hpp", ".py", ".sh", ".lua", ".cmake"]:
|
2019-04-26 18:27:27 +03:00
|
|
|
if name.endswith(suffix):
|
|
|
|
return True
|
2019-07-08 10:48:48 +03:00
|
|
|
return False
|
2019-04-26 18:27:27 +03:00
|
|
|
|
|
|
|
|
|
|
|
def submodules():
|
|
|
|
r = subprocess.run(["git", "submodule", "status"], capture_output=True, check=True)
|
|
|
|
return [
|
|
|
|
line.strip().split(" ")[1]
|
|
|
|
for line in r.stdout.decode().split(os.linesep)
|
|
|
|
if line
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-10-29 18:05:58 +03:00
|
|
|
def check_ccf():
|
2019-04-26 18:27:27 +03:00
|
|
|
missing = []
|
2019-10-29 18:05:58 +03:00
|
|
|
excluded = ["3rdparty", ".git", "libbyz", "build"] + submodules()
|
2019-04-26 18:27:27 +03:00
|
|
|
for root, dirs, files in os.walk("."):
|
|
|
|
for edir in excluded:
|
|
|
|
if edir in dirs:
|
|
|
|
dirs.remove(edir)
|
|
|
|
for name in files:
|
|
|
|
if name.startswith("."):
|
|
|
|
continue
|
|
|
|
if is_src(name):
|
|
|
|
path = os.path.join(root, name)
|
2019-10-29 18:05:58 +03:00
|
|
|
if not has_notice(path, PREFIXES_CCF):
|
2019-04-26 18:27:27 +03:00
|
|
|
missing.append(path)
|
2019-10-29 18:05:58 +03:00
|
|
|
return missing
|
|
|
|
|
|
|
|
|
|
|
|
def check_pbft():
|
|
|
|
missing = []
|
|
|
|
excluded = [] + submodules()
|
|
|
|
for root, dirs, files in os.walk("src/consensus/pbft/libbyz") and os.walk(
|
|
|
|
"tests/infra/libbyz"
|
|
|
|
):
|
|
|
|
for edir in excluded:
|
|
|
|
if edir in dirs:
|
|
|
|
dirs.remove(edir)
|
|
|
|
for name in files:
|
|
|
|
if name.startswith("."):
|
|
|
|
continue
|
|
|
|
if is_src(name):
|
|
|
|
path = os.path.join(root, name)
|
|
|
|
if not has_notice(path, PREFIXES_PBFT):
|
|
|
|
missing.append(path)
|
|
|
|
return missing
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
missing = []
|
|
|
|
missing.extend(check_ccf())
|
|
|
|
missing.extend(check_pbft())
|
|
|
|
|
2019-04-26 18:27:27 +03:00
|
|
|
for path in missing:
|
|
|
|
print("Copyright notice missing from {}".format(path))
|
|
|
|
sys.exit(len(missing))
|