1 #! /usr/bin/env nix-shell
2 #! nix-shell -p common-updater-scripts python3
10 from os
.path
import abspath
, dirname
, splitext
11 from urllib
.request
import urlopen
13 # CrOS version numbers look like this:
14 # [<chrome-major-version>.]<tip-build>.<branch-build>.<branch-branch-build>
16 # As far as I can tell, branches are where internal Google
17 # modifications are added to turn Chromium OS into Chrome OS, and
18 # branch branches are used for fixes for specific devices. So for
19 # Chromium OS they will always be 0. This is a best guess, and is not
21 with
urlopen('https://chromiumdash.appspot.com/cros/download_serving_builds_csv?deviceCategory=ChromeOS') as resp
:
22 reader
= csv
.reader(map(bytes
.decode
, resp
))
23 header
= reader
.__next
__()
24 cr_stable_index
= header
.index('cr_stable')
25 cros_stable_index
= header
.index('cros_stable')
30 this_chrome_version
= list(map(int, line
[cr_stable_index
].split('.')))
31 this_platform_version
= list(map(int, line
[cros_stable_index
].split('.')))
32 chrome_version
= max(chrome_version
, this_chrome_version
)
33 platform_version
= max(platform_version
, this_platform_version
)
35 chrome_major_version
= chrome_version
[0]
36 chromeos_tip_build
= platform_version
[0]
37 release_branch
= f
'release-R{chrome_major_version}-{chromeos_tip_build}.B'
39 # Determine the git revision.
40 with
urlopen(f
'https://chromium.googlesource.com/chromiumos/platform2/+/refs/heads/{release_branch}?format=JSON') as resp
:
41 resp
.readline() # Remove )]}' header
42 rev
= json
.load(resp
)['commit']
44 # Determine the patch version by counting the commits that have been
45 # added to the release branch since it forked off the chromeos branch.
46 with
urlopen(f
'https://chromium.googlesource.com/chromiumos/platform2/+log/refs/heads/main..{rev}/vm_tools/sommelier?format=JSON') as resp
:
47 resp
.readline() # Remove )]}' header
48 branch_commits
= json
.load(resp
)['log']
49 version
= f
'{chrome_major_version}.{len(branch_commits)}'
51 # Update the version, git revision, and hash in sommelier's default.nix.
52 subprocess
.run(['update-source-version', 'sommelier', f
'--rev={rev}', version
])
54 # Find the path to sommelier's default.nix, so Cargo.lock can be written
55 # into the same directory.
56 argv
= ['nix-instantiate', '--eval', '--json', '-A', 'sommelier.meta.position']
57 position
= json
.loads(subprocess
.check_output(argv
).decode('utf-8'))
58 filename
= re
.match(r
'[^:]*', position
)[0]