Merge #15258: Scripts and tools: Fix devtools/copyright_header.py to always honor exclusions
ad5e5a105e
Scripts and tools: Drop no-longer-relevant copyright holder names (Ben Woosley)2434ab5c2a
Scripts and tools: Fix devtools/copyright_header.py to always honor exclusions (Ben Woosley) Pull request description: This script compared paths relative to the report directory to test for exclusion, meaning the `EXCLUDE_DIRS` directory exclusions did not work properly, as they were relative to the project root. Fix this by creating absolute paths through the combination of: 'git ls-files --full-name' and 'git rev-parse --show-toplevel' Once this is done, we can stop testing for the names that would otherwise appear when exclusion of leveldb, secp256k1, etc., did not work as intended. Tree-SHA512: 0fa9b0a627e8ddb2d899eedee927ea8a809cb2ceee87c0920c151e5ca2103f7d8c463e3b379d5e2eb925fc3d7d8003082ffd9cbc03907ca0c448e8238e3a2684
This commit is contained in:
commit
b78f6c61c4
1 changed files with 18 additions and 29 deletions
|
@ -48,15 +48,22 @@ def applies_to_file(filename):
|
||||||
# obtain list of files in repo according to INCLUDE and EXCLUDE
|
# obtain list of files in repo according to INCLUDE and EXCLUDE
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
GIT_LS_CMD = 'git ls-files'
|
GIT_LS_CMD = 'git ls-files --full-name'.split(' ')
|
||||||
|
GIT_TOPLEVEL_CMD = 'git rev-parse --show-toplevel'.split(' ')
|
||||||
|
|
||||||
def call_git_ls():
|
def call_git_ls(base_directory):
|
||||||
out = subprocess.check_output(GIT_LS_CMD.split(' '))
|
out = subprocess.check_output([*GIT_LS_CMD, base_directory])
|
||||||
return [f for f in out.decode("utf-8").split('\n') if f != '']
|
return [f for f in out.decode("utf-8").split('\n') if f != '']
|
||||||
|
|
||||||
def get_filenames_to_examine():
|
def call_git_toplevel():
|
||||||
filenames = call_git_ls()
|
"Returns the absolute path to the project root"
|
||||||
return sorted([filename for filename in filenames if
|
return subprocess.check_output(GIT_TOPLEVEL_CMD).strip().decode("utf-8")
|
||||||
|
|
||||||
|
def get_filenames_to_examine(base_directory):
|
||||||
|
"Returns an array of absolute paths to any project files in the base_directory that pass the include/exclude filters"
|
||||||
|
root = call_git_toplevel()
|
||||||
|
filenames = call_git_ls(base_directory)
|
||||||
|
return sorted([os.path.join(root, filename) for filename in filenames if
|
||||||
applies_to_file(filename)])
|
applies_to_file(filename)])
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -83,24 +90,12 @@ def compile_copyright_regex(copyright_style, year_style, name):
|
||||||
EXPECTED_HOLDER_NAMES = [
|
EXPECTED_HOLDER_NAMES = [
|
||||||
"Satoshi Nakamoto\n",
|
"Satoshi Nakamoto\n",
|
||||||
"The Bitcoin Core developers\n",
|
"The Bitcoin Core developers\n",
|
||||||
"The Bitcoin Core developers \n",
|
|
||||||
"Bitcoin Core Developers\n",
|
"Bitcoin Core Developers\n",
|
||||||
"the Bitcoin Core developers\n",
|
|
||||||
"The Bitcoin developers\n",
|
|
||||||
"The LevelDB Authors\. All rights reserved\.\n",
|
|
||||||
"BitPay Inc\.\n",
|
"BitPay Inc\.\n",
|
||||||
"BitPay, Inc\.\n",
|
|
||||||
"University of Illinois at Urbana-Champaign\.\n",
|
"University of Illinois at Urbana-Champaign\.\n",
|
||||||
"MarcoFalke\n",
|
|
||||||
"Pieter Wuille\n",
|
"Pieter Wuille\n",
|
||||||
"Pieter Wuille +\*\n",
|
|
||||||
"Pieter Wuille, Gregory Maxwell +\*\n",
|
|
||||||
"Pieter Wuille, Andrew Poelstra +\*\n",
|
|
||||||
"Andrew Poelstra +\*\n",
|
|
||||||
"Wladimir J. van der Laan\n",
|
"Wladimir J. van der Laan\n",
|
||||||
"Jeff Garzik\n",
|
"Jeff Garzik\n",
|
||||||
"Diederik Huys, Pieter Wuille +\*\n",
|
|
||||||
"Thomas Daede, Cory Fields +\*\n",
|
|
||||||
"Jan-Klaas Kollhof\n",
|
"Jan-Klaas Kollhof\n",
|
||||||
"Sam Rushing\n",
|
"Sam Rushing\n",
|
||||||
"ArtForz -- public domain half-a-node\n",
|
"ArtForz -- public domain half-a-node\n",
|
||||||
|
@ -146,7 +141,7 @@ def file_has_without_c_style_copyright_for_holder(contents, holder_name):
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
def read_file(filename):
|
def read_file(filename):
|
||||||
return open(os.path.abspath(filename), 'r', encoding="utf8").read()
|
return open(filename, 'r', encoding="utf8").read()
|
||||||
|
|
||||||
def gather_file_info(filename):
|
def gather_file_info(filename):
|
||||||
info = {}
|
info = {}
|
||||||
|
@ -260,12 +255,9 @@ def print_report(file_infos, verbose):
|
||||||
print(SEPARATOR)
|
print(SEPARATOR)
|
||||||
|
|
||||||
def exec_report(base_directory, verbose):
|
def exec_report(base_directory, verbose):
|
||||||
original_cwd = os.getcwd()
|
filenames = get_filenames_to_examine(base_directory)
|
||||||
os.chdir(base_directory)
|
|
||||||
filenames = get_filenames_to_examine()
|
|
||||||
file_infos = [gather_file_info(f) for f in filenames]
|
file_infos = [gather_file_info(f) for f in filenames]
|
||||||
print_report(file_infos, verbose)
|
print_report(file_infos, verbose)
|
||||||
os.chdir(original_cwd)
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# report cmd
|
# report cmd
|
||||||
|
@ -325,13 +317,13 @@ def get_most_recent_git_change_year(filename):
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
def read_file_lines(filename):
|
def read_file_lines(filename):
|
||||||
f = open(os.path.abspath(filename), 'r', encoding="utf8")
|
f = open(filename, 'r', encoding="utf8")
|
||||||
file_lines = f.readlines()
|
file_lines = f.readlines()
|
||||||
f.close()
|
f.close()
|
||||||
return file_lines
|
return file_lines
|
||||||
|
|
||||||
def write_file_lines(filename, file_lines):
|
def write_file_lines(filename, file_lines):
|
||||||
f = open(os.path.abspath(filename), 'w', encoding="utf8")
|
f = open(filename, 'w', encoding="utf8")
|
||||||
f.write(''.join(file_lines))
|
f.write(''.join(file_lines))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
@ -399,11 +391,8 @@ def update_updatable_copyright(filename):
|
||||||
"Copyright updated! -> %s" % last_git_change_year)
|
"Copyright updated! -> %s" % last_git_change_year)
|
||||||
|
|
||||||
def exec_update_header_year(base_directory):
|
def exec_update_header_year(base_directory):
|
||||||
original_cwd = os.getcwd()
|
for filename in get_filenames_to_examine(base_directory):
|
||||||
os.chdir(base_directory)
|
|
||||||
for filename in get_filenames_to_examine():
|
|
||||||
update_updatable_copyright(filename)
|
update_updatable_copyright(filename)
|
||||||
os.chdir(original_cwd)
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# update cmd
|
# update cmd
|
||||||
|
|
Loading…
Reference in a new issue