2018-12-14 04:50:21 +01:00
|
|
|
#! /usr/bin/env nix-shell
|
2019-12-17 18:07:40 +01:00
|
|
|
#! nix-shell -p nix-prefetch-git "python3.withPackages (ps: with ps; [ lxml ])"
|
|
|
|
#! nix-shell -i python
|
2018-12-14 04:50:21 +01:00
|
|
|
|
|
|
|
import base64
|
|
|
|
import json
|
|
|
|
import re
|
2022-04-03 13:57:13 +02:00
|
|
|
import shlex
|
2018-12-14 04:50:21 +01:00
|
|
|
import subprocess
|
|
|
|
from codecs import iterdecode
|
2022-04-03 13:57:13 +02:00
|
|
|
from os.path import abspath, dirname, splitext
|
2019-12-17 18:07:40 +01:00
|
|
|
from lxml import etree
|
|
|
|
from lxml.etree import HTMLParser
|
2018-12-14 04:50:21 +01:00
|
|
|
from urllib.request import urlopen
|
|
|
|
|
2022-03-15 20:48:29 +01:00
|
|
|
git_path = 'chromiumos/platform/crosvm'
|
2018-12-14 04:50:21 +01:00
|
|
|
git_root = 'https://chromium.googlesource.com/'
|
|
|
|
manifest_versions = f'{git_root}chromiumos/manifest-versions'
|
2020-04-15 21:21:43 +02:00
|
|
|
buildspecs_url = f'{manifest_versions}/+/refs/heads/master/full/buildspecs/'
|
2018-12-14 04:50:21 +01:00
|
|
|
|
|
|
|
# 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.
|
2019-12-17 18:07:40 +01:00
|
|
|
with urlopen('https://cros-updates-serving.appspot.com/') as resp:
|
|
|
|
document = etree.parse(resp, HTMLParser())
|
|
|
|
# bgcolor="lightgreen" is set on the most up-to-date version for
|
|
|
|
# each channel, so find a lightgreen cell in the "Stable" column.
|
|
|
|
(platform_version, chrome_version) = document.xpath("""
|
|
|
|
(//table[@id="cros-updates"]/tr/td[1 + count(
|
|
|
|
//table[@id="cros-updates"]/thead/tr[1]/th[text() = "Stable"]
|
|
|
|
/preceding-sibling::*)
|
|
|
|
][@bgcolor="lightgreen"])[1]/text()
|
|
|
|
""")
|
2018-12-14 04:50:21 +01:00
|
|
|
|
2019-12-17 18:07:40 +01:00
|
|
|
chrome_major_version = re.match(r'\d+', chrome_version)[0]
|
|
|
|
chromeos_tip_build = re.match(r'\d+', platform_version)[0]
|
2018-12-14 04:50:21 +01:00
|
|
|
|
|
|
|
# Find the most recent buildspec for the stable Chrome version and
|
|
|
|
# Chromium OS build number. Its branch build and branch branch build
|
|
|
|
# numbers will (almost?) certainly be 0. It will then end with an rc
|
|
|
|
# number -- presumably these are release candidates, one of which
|
|
|
|
# becomes the final release. Presumably the one with the highest rc
|
|
|
|
# number.
|
|
|
|
with urlopen(f'{buildspecs_url}{chrome_major_version}/?format=TEXT') as resp:
|
|
|
|
listing = base64.decodebytes(resp.read()).decode('utf-8')
|
|
|
|
buildspecs = [(line.split('\t', 1)[1]) for line in listing.splitlines()]
|
|
|
|
buildspecs = [s for s in buildspecs if s.startswith(chromeos_tip_build)]
|
|
|
|
buildspecs.sort(reverse=True)
|
|
|
|
buildspec = splitext(buildspecs[0])[0]
|
|
|
|
|
2022-03-15 20:48:29 +01:00
|
|
|
# Read the buildspec, and extract the git revision.
|
2018-12-14 04:50:21 +01:00
|
|
|
with urlopen(f'{buildspecs_url}{chrome_major_version}/{buildspec}.xml?format=TEXT') as resp:
|
2019-12-17 18:07:40 +01:00
|
|
|
xml = base64.decodebytes(resp.read())
|
|
|
|
root = etree.fromstring(xml)
|
2022-03-15 20:48:29 +01:00
|
|
|
revision = root.find(f'./project[@name="{git_path}"]').get('revision')
|
2018-12-14 04:50:21 +01:00
|
|
|
|
|
|
|
# Initialize the data that will be output from this script. Leave the
|
|
|
|
# rc number in buildspec so nobody else is subject to the same level
|
|
|
|
# of confusion I have been.
|
2022-03-15 20:48:29 +01:00
|
|
|
data = {'version': f'{chrome_major_version}.{buildspec}'}
|
2018-12-14 04:50:21 +01:00
|
|
|
|
2022-03-15 20:48:29 +01:00
|
|
|
# Fill in the 'src' key with the output from nix-prefetch-git, which
|
|
|
|
# can be passed straight to fetchGit when imported by Nix.
|
|
|
|
argv = ['nix-prefetch-git',
|
|
|
|
'--fetch-submodules',
|
|
|
|
'--url', git_root + git_path,
|
|
|
|
'--rev', revision]
|
|
|
|
output = subprocess.check_output(argv)
|
|
|
|
data['src'] = json.loads(output.decode('utf-8'))
|
2018-12-14 04:50:21 +01:00
|
|
|
|
2022-03-15 20:48:29 +01:00
|
|
|
# Find the path to crosvm's default.nix, so the src data can be
|
2018-12-14 04:50:21 +01:00
|
|
|
# written into the same directory.
|
|
|
|
argv = ['nix-instantiate', '--eval', '--json', '-A', 'crosvm.meta.position']
|
|
|
|
position = json.loads(subprocess.check_output(argv).decode('utf-8'))
|
|
|
|
filename = re.match(r'[^:]*', position)[0]
|
|
|
|
|
2022-04-03 13:57:13 +02:00
|
|
|
# Write the output.
|
2018-12-14 04:50:21 +01:00
|
|
|
with open(dirname(filename) + '/upstream-info.json', 'w') as out:
|
|
|
|
json.dump(data, out, indent=2)
|
|
|
|
out.write('\n')
|
2022-04-03 13:57:13 +02:00
|
|
|
|
|
|
|
# Generate a Cargo.lock
|
|
|
|
run = ['.',
|
|
|
|
dirname(abspath(__file__)) + '/generate-cargo.sh',
|
|
|
|
dirname(filename) + '/Cargo.lock']
|
|
|
|
expr = '(import ./. {}).crosvm.overrideAttrs (_: { dontCargoSetupPostUnpack = true; })'
|
|
|
|
subprocess.run(['nix-shell', '-E', expr, '--run', shlex.join(run)])
|