| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
1 |
#!/usr/bin/env python3 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
2 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
3 |
"""Compile source on a range of commits |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
4 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
5 |
Usage: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
6 |
check-commits <start> <source> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
7 |
""" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
8 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
9 |
import docopt, os, sys, tempfile |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
10 |
from subprocess import check_call, check_output, run |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
11 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
12 |
args = docopt.docopt(__doc__) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
13 |
start = args.get('<start>') |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
14 |
source = args.get('<source>') |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
15 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
16 |
cwd = os.getcwd() |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
17 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
18 |
with tempfile.TemporaryDirectory() as work_dir: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
19 |
check_call(['git', 'clone', 'https://github.com/fmtlib/fmt.git'], |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
20 |
cwd=work_dir) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
21 |
repo_dir = os.path.join(work_dir, 'fmt') |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
22 |
commits = check_output( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
23 |
['git', 'rev-list', f'{start}..HEAD', '--abbrev-commit', |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
24 |
'--', 'include', 'src'], |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
25 |
text=True, cwd=repo_dir).rstrip().split('\n') |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
26 |
commits.reverse() |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
27 |
print('Time\tCommit') |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
28 |
for commit in commits: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
29 |
check_call(['git', '-c', 'advice.detachedHead=false', 'checkout', commit], |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
30 |
cwd=repo_dir) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
31 |
returncode = run( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
32 |
['c++', '-std=c++11', '-O3', '-DNDEBUG', '-I', 'include', |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
33 |
'src/format.cc', os.path.join(cwd, source)], cwd=repo_dir).returncode |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
34 |
if returncode != 0: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
35 |
continue |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
36 |
times = [] |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
37 |
for i in range(5): |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
38 |
output = check_output([os.path.join(repo_dir, 'a.out')], text=True) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
39 |
times.append(float(output)) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
40 |
message = check_output(['git', 'log', '-1', '--pretty=format:%s', commit], |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
41 |
cwd=repo_dir, text=True) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
42 |
print(f'{min(times)}\t{commit} {message[:40]}') |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
43 |
sys.stdout.flush() |
|
|
1970-01-01 00:00 |
44 |
|