-
Notifications
You must be signed in to change notification settings - Fork 18
/
update.py
executable file
·105 lines (85 loc) · 3.13 KB
/
update.py
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
#!/usr/bin/env python3
#
# Copyright 2020 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 subprocess
import tempfile
import os
import sys
from pathlib import Path
def run(*command, capture=False, **kwargs):
command = list(map(str, command))
print(f'CMD: {" ".join(command)}')
stdout = subprocess.PIPE if capture else None
result = subprocess.run(command, stdout=stdout, **kwargs)
result.check_returncode()
if capture:
return result.stdout.decode('utf-8')
return None
def git(*command, capture=False):
return run('git', '-C', GIT_DIR, *command, capture=capture)
def step(title):
print('=' * 80)
print(title)
print('-' * 80)
ROOT_DIR = Path(__file__).parent
GIT_DIR = ROOT_DIR / '.v8'
DIST_DIR = ROOT_DIR / 'dist'
DOXYFILE_PATH = ROOT_DIR / 'Doxyfile'
step(f'Update V8 checkout in: {GIT_DIR}')
if not GIT_DIR.exists():
run('git', 'clone', 'https://chromium.googlesource.com/v8/v8', GIT_DIR)
git('fetch', '--all')
step('List branches')
if len(sys.argv) == 1:
NAMES = ['refs/remotes/origin/*-lkgr', 'refs/remotes/origin/lkgr']
else:
NAMES = [
'refs/remotes/origin/lkgr' if name == "head" else f'refs/remotes/origin/{name}-lkgr'
for name in sys.argv[1:]
]
BRANCHES = git('for-each-ref', *NAMES, '--format=%(refname:strip=3) %(objectname)', capture=True).rstrip().split("\n")
BRANCHES = [ref.split(' ') for ref in BRANCHES]
BRANCHES = [(branch.split('-')[0], sha) for branch,sha in BRANCHES]
# Sort branches from old to new:
BRANCHES.sort(key=lambda branch_and_sha: (float("inf"),) if branch_and_sha[0] == 'lkgr' else tuple(map(int, branch_and_sha[0].split('.'))))
print(BRANCHES)
DIST_DIR.mkdir(exist_ok=True)
for branch,sha in BRANCHES:
step(f'Generating docs for branch: {branch}')
if branch == 'lkgr':
version_name = 'head'
else:
version_name = f'v{branch}'
branch_dir = DIST_DIR / version_name
branch_dir.mkdir(exist_ok=True)
stamp = branch_dir / '.sha'
def needs_update():
if not stamp.exists():
step(f'Needs update: no stamp file')
return True
stamp_mtime = stamp.stat().st_mtime
if stamp_mtime <= DOXYFILE_PATH.stat().st_mtime:
step(f'Needs update: stamp file older than Doxyfile')
return True
if stamp_mtime <= Path(__file__).stat().st_mtime:
step(f'Needs update: stamp file older than update script')
return True
stamp_sha = stamp.read_text()
if stamp_sha != sha:
step(f'Needs update: stamp SHA does not match branch SHA ({stamp_sha} vs. {sha})')
return True
return False
if not needs_update():
step(f'Docs already up-to-date.')
continue
stamp.write_text(sha)
git('switch', '--force', '--detach', sha)
git('clean', '--force', '-d')
doxyfile_data = DOXYFILE_PATH.read_text()
doxyfile_data += f"""
PROJECT_NUMBER={version_name}
HTML_OUTPUT={os.path.abspath(branch_dir)}
"""
run('doxygen', '-', cwd=GIT_DIR, input=doxyfile_data.encode('utf-8'))