-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupdate-baselines.py
72 lines (53 loc) · 2.34 KB
/
update-baselines.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
import json
import os
import subprocess
ENCODING = 'utf-8'
VCPKG_FILE = 'vcpkg.json'
VCPKG_CFG_FILE = 'vcpkg-configuration.json'
VCPKG_URL = r'https://github.com/microsoft/vcpkg.git/'
VCPKG_COLORGLASS_URL = r'https://gitlab.com/colorglass/vcpkg-colorglass.git/'
VCPKG_INSTALLATION_ROOT = os.path.expanduser(os.path.expandvars('%VCPKG_INSTALLATION_ROOT%'))
def get_latest_baseline_commit(url: str, refs: str) -> str:
process = subprocess.Popen(f'git ls-remote {url} {refs}',
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
encoding=ENCODING,
text=True,
shell=False)
while process.poll() is None:
if line := process.stdout.readline().strip():
commit, _ = line.split()
return commit
return ''
def update_local_vcpkg() -> bool:
os.chdir(VCPKG_INSTALLATION_ROOT)
process = subprocess.Popen(f'git pull --rebase origin',
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
encoding=ENCODING,
text=True,
shell=False)
while process.poll() is None:
if line := process.stdout.readline().strip():
if line == 'Already up to date.':
return False
return True
def run() -> None:
if commit := get_latest_baseline_commit(VCPKG_URL, 'master'):
with open(VCPKG_FILE, encoding=ENCODING) as f:
data = json.load(f)
if data['builtin-baseline'] != commit:
data['builtin-baseline'] = commit
with open(VCPKG_FILE, encoding=ENCODING, mode='w') as f:
json.dump(data, f, indent=2)
if commit := get_latest_baseline_commit(VCPKG_COLORGLASS_URL, 'main'):
with open(VCPKG_CFG_FILE, encoding=ENCODING) as f:
data = json.load(f)
if data['registries'][0]['baseline'] != commit:
data['registries'][0]['baseline'] = commit
with open(VCPKG_CFG_FILE, encoding=ENCODING, mode='w') as f:
json.dump(data, f, indent=2)
if update_local_vcpkg():
print('Updated local repo: "%s"' % VCPKG_INSTALLATION_ROOT)
if __name__ == '__main__':
run()