2021-08-09 15:42:31 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-11-28 14:26:24 +00:00
|
|
|
# Copyright 2018 the V8 project authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
from datetime import datetime
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2021-08-09 15:42:31 +00:00
|
|
|
from pathlib import Path
|
2018-11-28 14:26:24 +00:00
|
|
|
|
|
|
|
RE_GITHASH = re.compile(r"^[0-9a-f]{40}")
|
|
|
|
RE_AUTHOR_TIME = re.compile(r"^author-time (\d+)$")
|
|
|
|
RE_FILENAME = re.compile(r"^filename (.+)$")
|
|
|
|
|
2021-08-09 15:42:31 +00:00
|
|
|
VERSION_CACHE = dict()
|
|
|
|
RE_VERSION_MAJOR = re.compile(r".*V8_MAJOR_VERSION ([0-9]+)")
|
|
|
|
RE_VERSION_MINOR = re.compile(r".*V8_MINOR_VERSION ([0-9]+)")
|
|
|
|
|
|
|
|
|
|
|
|
def extract_version(hash):
|
|
|
|
if hash in VERSION_CACHE:
|
|
|
|
return VERSION_CACHE[hash]
|
2021-08-10 14:06:40 +00:00
|
|
|
if hash == '0000000000000000000000000000000000000000':
|
|
|
|
return 'HEAD'
|
2021-08-09 15:42:31 +00:00
|
|
|
result = subprocess.check_output(
|
|
|
|
['git', 'show', f"{hash}:include/v8-version.h"], encoding='UTF-8')
|
|
|
|
major = RE_VERSION_MAJOR.search(result).group(1)
|
|
|
|
minor = RE_VERSION_MINOR.search(result).group(1)
|
|
|
|
version = f"{major}.{minor}"
|
|
|
|
VERSION_CACHE[hash] = version
|
|
|
|
return version
|
|
|
|
|
2020-12-30 23:51:01 +00:00
|
|
|
|
2021-08-09 15:42:31 +00:00
|
|
|
def get_blame(file_path):
|
2018-11-28 14:26:24 +00:00
|
|
|
result = subprocess.check_output(
|
2021-08-09 15:42:31 +00:00
|
|
|
['git', 'blame', '-t', '--line-porcelain', file_path], encoding='UTF-8')
|
2018-11-28 14:26:24 +00:00
|
|
|
line_iter = iter(result.splitlines())
|
|
|
|
blame_list = list()
|
|
|
|
current_blame = None
|
|
|
|
while True:
|
|
|
|
line = next(line_iter, None)
|
|
|
|
if line is None:
|
|
|
|
break
|
|
|
|
if RE_GITHASH.match(line):
|
|
|
|
if current_blame is not None:
|
|
|
|
blame_list.append(current_blame)
|
2021-08-09 15:42:31 +00:00
|
|
|
hash = line.split(" ")[0]
|
|
|
|
current_blame = {
|
|
|
|
'datetime': 0,
|
|
|
|
'filename': None,
|
|
|
|
'content': None,
|
|
|
|
'hash': hash
|
|
|
|
}
|
2018-11-28 14:26:24 +00:00
|
|
|
continue
|
|
|
|
match = RE_AUTHOR_TIME.match(line)
|
|
|
|
if match:
|
2021-08-09 15:42:31 +00:00
|
|
|
current_blame['datetime'] = datetime.fromtimestamp(int(
|
|
|
|
match.groups()[0]))
|
2018-11-28 14:26:24 +00:00
|
|
|
continue
|
|
|
|
match = RE_FILENAME.match(line)
|
|
|
|
if match:
|
|
|
|
current_blame['filename'] = match.groups()[0]
|
|
|
|
current_blame['content'] = next(line_iter).strip()
|
|
|
|
continue
|
|
|
|
blame_list.append(current_blame)
|
|
|
|
return blame_list
|
|
|
|
|
2020-12-30 23:51:01 +00:00
|
|
|
|
|
|
|
RE_MACRO_END = re.compile(r"\);")
|
2018-11-28 14:26:24 +00:00
|
|
|
RE_DEPRECATE_MACRO = re.compile(r"\(.*?,(.*)\);", re.MULTILINE)
|
|
|
|
|
2020-12-30 23:51:01 +00:00
|
|
|
|
2021-08-09 15:42:31 +00:00
|
|
|
def filter_and_print(blame_list, macro, options):
|
2020-12-30 23:51:01 +00:00
|
|
|
before = options.before
|
2018-11-28 14:26:24 +00:00
|
|
|
index = 0
|
|
|
|
re_macro = re.compile(macro)
|
|
|
|
deprecated = list()
|
|
|
|
while index < len(blame_list):
|
|
|
|
blame = blame_list[index]
|
2021-08-09 15:42:31 +00:00
|
|
|
commit_datetime = blame['datetime']
|
|
|
|
if commit_datetime >= before:
|
2020-12-30 23:51:01 +00:00
|
|
|
index += 1
|
|
|
|
continue
|
|
|
|
line = blame['content']
|
2021-08-09 15:42:31 +00:00
|
|
|
commit_hash = blame['hash']
|
2020-12-30 23:51:01 +00:00
|
|
|
match = re_macro.search(line)
|
|
|
|
if match:
|
2018-11-28 14:26:24 +00:00
|
|
|
pos = match.end()
|
|
|
|
start = -1
|
|
|
|
parens = 0
|
|
|
|
while True:
|
|
|
|
if pos >= len(line):
|
2021-08-09 15:42:31 +00:00
|
|
|
# Extend to next line
|
2018-11-28 14:26:24 +00:00
|
|
|
index = index + 1
|
|
|
|
blame = blame_list[index]
|
|
|
|
line = line + blame['content']
|
|
|
|
if line[pos] == '(':
|
|
|
|
parens = parens + 1
|
|
|
|
elif line[pos] == ')':
|
|
|
|
parens = parens - 1
|
|
|
|
if parens == 0:
|
2021-08-09 15:42:31 +00:00
|
|
|
# Exclude closing ")
|
2020-12-30 23:51:01 +00:00
|
|
|
pos = pos - 2
|
2018-11-28 14:26:24 +00:00
|
|
|
break
|
2020-12-30 23:51:01 +00:00
|
|
|
elif line[pos] == '"' and start == -1:
|
2018-11-28 14:26:24 +00:00
|
|
|
start = pos + 1
|
|
|
|
pos = pos + 1
|
2020-12-30 23:51:01 +00:00
|
|
|
# Extract content and replace double quotes from merged lines
|
|
|
|
content = line[start:pos].strip().replace('""', '')
|
2021-08-09 15:42:31 +00:00
|
|
|
deprecated.append((index + 1, commit_datetime, commit_hash, content))
|
2018-11-28 14:26:24 +00:00
|
|
|
index = index + 1
|
2021-08-09 15:42:31 +00:00
|
|
|
print(f"# Marked as {macro}: {len(deprecated)}")
|
|
|
|
for linenumber, commit_datetime, commit_hash, content in deprecated:
|
|
|
|
commit_date = commit_datetime.date()
|
|
|
|
file_position = (
|
|
|
|
f"{options.v8_header}:{linenumber}").rjust(len(options.v8_header) + 5)
|
|
|
|
print(f" {file_position}\t{commit_date}\t{commit_hash[:8]}"
|
|
|
|
f"\t{extract_version(commit_hash)}\t{content}")
|
2018-11-28 14:26:24 +00:00
|
|
|
return len(deprecated)
|
|
|
|
|
2020-12-30 23:51:01 +00:00
|
|
|
|
2021-08-09 15:42:31 +00:00
|
|
|
def parse_options(args):
|
2020-12-30 23:51:01 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Collect deprecation statistics")
|
|
|
|
parser.add_argument("v8_header", nargs='?', help="Path to v8.h")
|
2018-11-28 14:26:24 +00:00
|
|
|
parser.add_argument("--before", help="Filter by date")
|
|
|
|
options = parser.parse_args(args)
|
|
|
|
if options.before:
|
|
|
|
options.before = datetime.strptime(options.before, '%Y-%m-%d')
|
|
|
|
else:
|
|
|
|
options.before = datetime.now()
|
2020-12-30 23:51:01 +00:00
|
|
|
if options.v8_header is None:
|
2021-08-09 15:42:31 +00:00
|
|
|
base_path = Path(__file__).parent.parent
|
|
|
|
options.v8_header = str(
|
|
|
|
(base_path / 'include' / 'v8.h').relative_to(base_path))
|
2018-11-28 14:26:24 +00:00
|
|
|
return options
|
|
|
|
|
2020-12-30 23:51:01 +00:00
|
|
|
|
2021-08-09 15:42:31 +00:00
|
|
|
def main(args):
|
|
|
|
options = parse_options(args)
|
|
|
|
blame_list = get_blame(options.v8_header)
|
|
|
|
filter_and_print(blame_list, "V8_DEPRECATE_SOON", options)
|
|
|
|
print("\n")
|
|
|
|
filter_and_print(blame_list, "V8_DEPRECATED", options)
|
2020-12-30 23:51:01 +00:00
|
|
|
|
2018-11-28 14:26:24 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-08-09 15:42:31 +00:00
|
|
|
main(sys.argv[1:])
|