Skip to content
This repository was archived by the owner on Jul 21, 2022. It is now read-only.

Commit 4d2a036

Browse files
committed
Generator
1 parent a53a1b0 commit 4d2a036

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

.style.yapf

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[style]
2+
based_on_style = pep8

generate_api_list.py

+42-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /bin/env python3
22

33
from argparse import ArgumentParser
4-
from subprocess import check_call
4+
from subprocess import check_call, check_output
55
from pathlib import Path
66

77
import logging
@@ -11,26 +11,31 @@
1111
API_LIST_FILE = 'high_entropy_list.csv'
1212
API_LIST_TARGET_FILE = 'chromium_api_list.csv'
1313

14+
COMMIT_POSITION_HEADER = 'Cr-Commit-Position: '
15+
1416

1517
def Main():
1618
parser = ArgumentParser()
1719
parser.add_argument('--build_path', '-C', type=Path, required=True)
1820
parser.add_argument('--build',
1921
'-B',
20-
type=bool,
21-
help='Whether the API list should be rebuilt',
22-
default=False)
22+
action='store_true',
23+
help='Whether the API list should be rebuilt')
2324
parser.add_argument('--target_path', '-t', type=Path, default=Path.cwd())
25+
parser.add_argument('--verbose', '-v', action='store_true')
2426
parser.add_argument(
25-
'--commmit',
26-
type=bool,
27-
default=False,
27+
'--commit',
28+
action='store_true',
2829
help='Git commit after a successful extraction of the API list')
2930

3031
args = parser.parse_args()
3132

33+
if args.verbose:
34+
logging.basicConfig(level=logging.DEBUG)
35+
3236
if not args.build_path.exists():
33-
logging.critical('Build directory does not exist')
37+
logging.critical('Build directory does not exist. Checked {}'.format(
38+
args.build_path))
3439
sys.exit(1)
3540

3641
if not args.target_path.exists():
@@ -60,6 +65,35 @@ def Main():
6065
with target_file.open('w') as w:
6166
w.writelines(contents)
6267

68+
if args.commit:
69+
commit_position = check_output(['git', 'rev-parse', 'HEAD'],
70+
cwd=args.build_path)
71+
commit_message = check_output(['git', 'cat-file', '-p', 'HEAD'],
72+
cwd=args.build_path).splitlines()
73+
for l in commit_message:
74+
ls = l.decode()
75+
if ls.startswith(COMMIT_POSITION_HEADER):
76+
commit_position = ls[len(COMMIT_POSITION_HEADER):].trim()
77+
break
78+
79+
git_status = check_output(['git', 'status', '--porcelain=v1'],
80+
cwd=args.target_path).splitlines()
81+
if len(git_status) == 0:
82+
logging.info('No change to API list')
83+
elif len(git_status) != 1:
84+
logging.error(
85+
'There is more than one changed file in the repository. ' +
86+
'Can\'t commit changes.')
87+
elif git_status[0] != 'M\t{}'.format(API_LIST_TARGET_FILE):
88+
logging.error('Unexpected changes found in the repository')
89+
else:
90+
check_call([
91+
'git', 'commit', '-m',
92+
'\'API list update from {}\''.format(commit_position), '--',
93+
API_LIST_TARGET_FILE
94+
],
95+
cwd=args.target_path.parent())
96+
6397

6498
if __name__ == "__main__":
6599
Main()

0 commit comments

Comments
 (0)