2020-04-24 23:36:52 +00:00
|
|
|
#! /usr/bin/env nix-shell
|
2022-08-12 12:06:08 +00:00
|
|
|
#! nix-shell -p common-updater-scripts python3
|
2020-04-24 23:36:52 +00:00
|
|
|
#! nix-shell -i python
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
import csv
|
2020-04-24 23:36:52 +00:00
|
|
|
import json
|
|
|
|
import re
|
2022-04-15 01:41:22 +00:00
|
|
|
import shlex
|
2020-04-24 23:36:52 +00:00
|
|
|
import subprocess
|
2022-04-15 01:41:22 +00:00
|
|
|
from os.path import abspath, dirname, splitext
|
2020-04-24 23:36:52 +00:00
|
|
|
from urllib.request import urlopen
|
|
|
|
|
|
|
|
# CrOS version numbers look like this:
|
|
|
|
# [<chrome-major-version>.]<tip-build>.<branch-build>.<branch-branch-build>
|
|
|
|
#
|
|
|
|
# As far as I can tell, branches are where internal Google
|
|
|
|
# modifications are added to turn Chromium OS into Chrome OS, and
|
|
|
|
# branch branches are used for fixes for specific devices. So for
|
|
|
|
# Chromium OS they will always be 0. This is a best guess, and is not
|
|
|
|
# documented.
|
2022-08-12 12:06:08 +00:00
|
|
|
with urlopen('https://chromiumdash.appspot.com/cros/download_serving_builds_csv?deviceCategory=ChromeOS') as resp:
|
|
|
|
reader = csv.reader(map(bytes.decode, resp))
|
|
|
|
header = reader.__next__()
|
|
|
|
cr_stable_index = header.index('cr_stable')
|
|
|
|
cros_stable_index = header.index('cros_stable')
|
|
|
|
chrome_version = []
|
|
|
|
platform_version = []
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
for line in reader:
|
|
|
|
this_chrome_version = list(map(int, line[cr_stable_index].split('.')))
|
|
|
|
this_platform_version = list(map(int, line[cros_stable_index].split('.')))
|
|
|
|
chrome_version = max(chrome_version, this_chrome_version)
|
|
|
|
platform_version = max(platform_version, this_platform_version)
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
chrome_major_version = chrome_version[0]
|
|
|
|
chromeos_tip_build = platform_version[0]
|
2022-11-21 17:40:18 +00:00
|
|
|
release_branch = f'release-R{chrome_major_version}-{chromeos_tip_build}.B'
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
# Determine the git revision.
|
|
|
|
with urlopen(f'https://chromium.googlesource.com/chromiumos/platform/crosvm/+/refs/heads/{release_branch}?format=JSON') as resp:
|
|
|
|
resp.readline() # Remove )]}' header
|
|
|
|
rev = json.load(resp)['commit']
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
# Determine the patch version by counting the commits that have been
|
|
|
|
# added to the release branch since it forked off the chromeos branch.
|
|
|
|
with urlopen(f'https://chromium.googlesource.com/chromiumos/platform/crosvm/+log/refs/heads/chromeos..{rev}?format=JSON') as resp:
|
|
|
|
resp.readline() # Remove )]}' header
|
|
|
|
branch_commits = json.load(resp)['log']
|
|
|
|
version = f'{chrome_major_version}.{len(branch_commits)}'
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
# Update the version, git revision, and hash in crosvm's default.nix.
|
|
|
|
subprocess.run(['update-source-version', 'crosvm', f'--rev={rev}', version])
|