2019-11-06 20:37:25 +01:00
|
|
|
#! /usr/bin/env nix-shell
|
2020-11-03 13:08:09 +01:00
|
|
|
#! nix-shell -i python -p python3 nix nix-prefetch-git
|
2019-11-06 20:37:25 +01:00
|
|
|
|
2020-12-18 17:52:21 +01:00
|
|
|
"""This script automatically updates chromium, google-chrome, chromedriver, and ungoogled-chromium
|
|
|
|
via upstream-info.json."""
|
|
|
|
|
2019-11-06 20:37:25 +01:00
|
|
|
import csv
|
|
|
|
import json
|
2020-11-03 13:08:09 +01:00
|
|
|
import re
|
2019-11-06 20:37:25 +01:00
|
|
|
import subprocess
|
2020-09-10 12:01:01 +02:00
|
|
|
import sys
|
|
|
|
|
2019-11-06 20:37:25 +01:00
|
|
|
from codecs import iterdecode
|
2020-09-10 12:01:01 +02:00
|
|
|
from collections import OrderedDict
|
2020-11-03 13:08:09 +01:00
|
|
|
from datetime import datetime
|
2019-11-06 20:37:25 +01:00
|
|
|
from os.path import abspath, dirname
|
|
|
|
from urllib.request import urlopen
|
|
|
|
|
|
|
|
HISTORY_URL = 'https://omahaproxy.appspot.com/history?os=linux'
|
|
|
|
DEB_URL = 'https://dl.google.com/linux/chrome/deb/pool/main/g'
|
|
|
|
BUCKET_URL = 'https://commondatastorage.googleapis.com/chromium-browser-official'
|
|
|
|
|
|
|
|
JSON_PATH = dirname(abspath(__file__)) + '/upstream-info.json'
|
|
|
|
|
2020-12-18 17:52:21 +01:00
|
|
|
|
2019-11-06 20:37:25 +01:00
|
|
|
def load_json(path):
|
2020-12-18 17:52:21 +01:00
|
|
|
"""Loads the given JSON file."""
|
2019-11-06 20:37:25 +01:00
|
|
|
with open(path, 'r') as f:
|
|
|
|
return json.load(f)
|
|
|
|
|
2020-12-18 17:52:21 +01:00
|
|
|
|
2019-11-06 20:37:25 +01:00
|
|
|
def nix_prefetch_url(url, algo='sha256'):
|
2020-12-18 17:52:21 +01:00
|
|
|
"""Prefetches the content of the given URL."""
|
2019-11-06 20:37:25 +01:00
|
|
|
print(f'nix-prefetch-url {url}')
|
|
|
|
out = subprocess.check_output(['nix-prefetch-url', '--type', algo, url])
|
|
|
|
return out.decode('utf-8').rstrip()
|
|
|
|
|
2020-12-18 17:52:21 +01:00
|
|
|
|
2020-11-03 13:08:09 +01:00
|
|
|
def nix_prefetch_git(url, rev):
|
2020-12-18 17:52:21 +01:00
|
|
|
"""Prefetches the requested Git revision of the given repository URL."""
|
2020-11-03 13:08:09 +01:00
|
|
|
print(f'nix-prefetch-git {url} {rev}')
|
|
|
|
out = subprocess.check_output(['nix-prefetch-git', '--quiet', '--url', url, '--rev', rev])
|
|
|
|
return json.loads(out)
|
|
|
|
|
2020-12-18 17:52:21 +01:00
|
|
|
|
2020-11-03 13:08:09 +01:00
|
|
|
def get_file_revision(revision, file_path):
|
2020-12-18 17:52:21 +01:00
|
|
|
"""Fetches the requested Git revision of the given Chromium file."""
|
2020-11-03 13:08:09 +01:00
|
|
|
url = f'https://raw.githubusercontent.com/chromium/chromium/{revision}/{file_path}'
|
|
|
|
with urlopen(url) as http_response:
|
|
|
|
return http_response.read()
|
|
|
|
|
2020-12-18 17:52:21 +01:00
|
|
|
|
2020-11-27 12:38:07 +01:00
|
|
|
def get_matching_chromedriver(version):
|
2020-12-18 17:52:21 +01:00
|
|
|
"""Gets the matching chromedriver version for the given Chromium version."""
|
2020-11-27 12:38:07 +01:00
|
|
|
# See https://chromedriver.chromium.org/downloads/version-selection
|
|
|
|
build = re.sub('.[0-9]+$', '', version)
|
|
|
|
chromedriver_version_url = f'https://chromedriver.storage.googleapis.com/LATEST_RELEASE_{build}'
|
|
|
|
with urlopen(chromedriver_version_url) as http_response:
|
|
|
|
chromedriver_version = http_response.read().decode()
|
|
|
|
def get_chromedriver_url(system):
|
2020-12-18 17:52:21 +01:00
|
|
|
return ('https://chromedriver.storage.googleapis.com/' +
|
|
|
|
f'{chromedriver_version}/chromedriver_{system}.zip')
|
2020-11-27 12:38:07 +01:00
|
|
|
return {
|
|
|
|
'version': chromedriver_version,
|
|
|
|
'sha256_linux': nix_prefetch_url(get_chromedriver_url('linux64')),
|
|
|
|
'sha256_darwin': nix_prefetch_url(get_chromedriver_url('mac64'))
|
|
|
|
}
|
|
|
|
|
2020-12-18 17:52:21 +01:00
|
|
|
|
2020-12-18 19:08:37 +01:00
|
|
|
def get_channel_dependencies(version):
|
2020-12-18 17:52:21 +01:00
|
|
|
"""Gets all dependencies for the given Chromium version."""
|
2020-12-18 19:08:37 +01:00
|
|
|
deps = get_file_revision(version, 'DEPS')
|
2020-11-03 13:08:09 +01:00
|
|
|
gn_pattern = b"'gn_version': 'git_revision:([0-9a-f]{40})'"
|
|
|
|
gn_commit = re.search(gn_pattern, deps).group(1).decode()
|
|
|
|
gn = nix_prefetch_git('https://gn.googlesource.com/gn', gn_commit)
|
|
|
|
return {
|
|
|
|
'gn': {
|
|
|
|
'version': datetime.fromisoformat(gn['date']).date().isoformat(),
|
|
|
|
'url': gn['url'],
|
|
|
|
'rev': gn['rev'],
|
|
|
|
'sha256': gn['sha256']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 19:08:37 +01:00
|
|
|
|
|
|
|
def get_latest_ungoogled_chromium_tag():
|
|
|
|
"""Returns the latest ungoogled-chromium tag using the GitHub API."""
|
|
|
|
api_tag_url = 'https://api.github.com/repos/Eloston/ungoogled-chromium/tags?per_page=1'
|
|
|
|
with urlopen(api_tag_url) as http_response:
|
|
|
|
tag_data = json.load(http_response)
|
|
|
|
return tag_data[0]['name']
|
|
|
|
|
|
|
|
|
2020-12-22 13:21:12 +01:00
|
|
|
def get_latest_ungoogled_chromium_build():
|
|
|
|
"""Returns a dictionary for the latest ungoogled-chromium build."""
|
|
|
|
tag = get_latest_ungoogled_chromium_tag()
|
|
|
|
version = tag.split('-')[0]
|
|
|
|
return {
|
|
|
|
'channel': 'ungoogled-chromium',
|
2020-12-18 19:08:37 +01:00
|
|
|
'version': version,
|
2020-12-22 13:21:12 +01:00
|
|
|
'ungoogled_tag': tag
|
2020-12-18 19:08:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-14 20:37:01 +01:00
|
|
|
def channel_name_to_attr_name(channel_name):
|
|
|
|
"""Maps a channel name to the corresponding main Nixpkgs attribute name."""
|
|
|
|
if channel_name == 'stable':
|
|
|
|
return 'chromium'
|
|
|
|
if channel_name == 'beta':
|
|
|
|
return 'chromiumBeta'
|
|
|
|
if channel_name == 'dev':
|
|
|
|
return 'chromiumDev'
|
|
|
|
if channel_name == 'ungoogled-chromium':
|
|
|
|
return 'ungoogled-chromium'
|
|
|
|
print(f'Error: Unexpected channel: {channel_name}', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def print_updates(channels_old, channels_new):
|
|
|
|
"""Print a summary of the updates."""
|
|
|
|
print('Updates:')
|
|
|
|
for channel_name in channels_old:
|
|
|
|
version_old = channels_old[channel_name]["version"]
|
|
|
|
version_new = channels_new[channel_name]["version"]
|
|
|
|
if version_old < version_new:
|
|
|
|
attr_name = channel_name_to_attr_name(channel_name)
|
|
|
|
print(f'- {attr_name}: {version_old} -> {version_new}')
|
|
|
|
|
|
|
|
|
2019-11-06 20:37:25 +01:00
|
|
|
channels = {}
|
|
|
|
last_channels = load_json(JSON_PATH)
|
|
|
|
|
2020-12-18 17:52:21 +01:00
|
|
|
|
2020-09-10 12:01:01 +02:00
|
|
|
print(f'GET {HISTORY_URL}', file=sys.stderr)
|
2019-11-06 20:37:25 +01:00
|
|
|
with urlopen(HISTORY_URL) as resp:
|
|
|
|
builds = csv.DictReader(iterdecode(resp, 'utf-8'))
|
2020-12-22 13:21:12 +01:00
|
|
|
builds = list(builds)
|
|
|
|
builds.append(get_latest_ungoogled_chromium_build())
|
2019-11-06 20:37:25 +01:00
|
|
|
for build in builds:
|
|
|
|
channel_name = build['channel']
|
|
|
|
|
|
|
|
# If we've already found a newer build for this channel, we're
|
|
|
|
# no longer interested in it.
|
|
|
|
if channel_name in channels:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# If we're back at the last build we used, we don't need to
|
|
|
|
# keep going -- there's no new version available, and we can
|
|
|
|
# just reuse the info from last time.
|
|
|
|
if build['version'] == last_channels[channel_name]['version']:
|
|
|
|
channels[channel_name] = last_channels[channel_name]
|
|
|
|
continue
|
|
|
|
|
|
|
|
channel = {'version': build['version']}
|
2020-12-22 13:21:12 +01:00
|
|
|
if channel_name == 'dev':
|
|
|
|
google_chrome_suffix = 'unstable'
|
|
|
|
elif channel_name == 'ungoogled-chromium':
|
|
|
|
google_chrome_suffix = 'stable'
|
|
|
|
else:
|
|
|
|
google_chrome_suffix = channel_name
|
2019-11-06 20:37:25 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
channel['sha256'] = nix_prefetch_url(f'{BUCKET_URL}/chromium-{build["version"]}.tar.xz')
|
2020-12-18 17:52:21 +01:00
|
|
|
channel['sha256bin64'] = nix_prefetch_url(
|
2020-12-22 13:21:12 +01:00
|
|
|
f'{DEB_URL}/google-chrome-{google_chrome_suffix}/' +
|
|
|
|
f'google-chrome-{google_chrome_suffix}_{build["version"]}-1_amd64.deb')
|
2019-11-06 20:37:25 +01:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
# This build isn't actually available yet. Continue to
|
|
|
|
# the next one.
|
|
|
|
continue
|
|
|
|
|
2020-12-18 19:08:37 +01:00
|
|
|
channel['deps'] = get_channel_dependencies(channel['version'])
|
2020-11-27 12:38:07 +01:00
|
|
|
if channel_name == 'stable':
|
|
|
|
channel['chromedriver'] = get_matching_chromedriver(channel['version'])
|
2020-12-22 13:21:12 +01:00
|
|
|
elif channel_name == 'ungoogled-chromium':
|
|
|
|
ungoogled_repo_url = 'https://github.com/Eloston/ungoogled-chromium.git'
|
|
|
|
channel['deps']['ungoogled-patches'] = {
|
|
|
|
'rev': build['ungoogled_tag'],
|
|
|
|
'sha256': nix_prefetch_git(ungoogled_repo_url, build['ungoogled_tag'])['sha256']
|
|
|
|
}
|
2020-11-03 13:08:09 +01:00
|
|
|
|
2019-11-06 20:37:25 +01:00
|
|
|
channels[channel_name] = channel
|
|
|
|
|
2020-12-18 17:52:21 +01:00
|
|
|
|
2019-11-06 20:37:25 +01:00
|
|
|
with open(JSON_PATH, 'w') as out:
|
2020-09-10 12:01:01 +02:00
|
|
|
def get_channel_key(item):
|
2020-12-18 17:52:21 +01:00
|
|
|
"""Orders Chromium channels by their name."""
|
2020-09-10 12:01:01 +02:00
|
|
|
channel_name = item[0]
|
|
|
|
if channel_name == 'stable':
|
|
|
|
return 0
|
2020-12-18 17:52:21 +01:00
|
|
|
if channel_name == 'beta':
|
2020-09-10 12:01:01 +02:00
|
|
|
return 1
|
2020-12-18 17:52:21 +01:00
|
|
|
if channel_name == 'dev':
|
2020-09-10 12:01:01 +02:00
|
|
|
return 2
|
2020-12-18 17:52:21 +01:00
|
|
|
if channel_name == 'ungoogled-chromium':
|
2020-12-09 19:29:31 +01:00
|
|
|
return 3
|
2020-12-18 17:52:21 +01:00
|
|
|
print(f'Error: Unexpected channel: {channel_name}', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2020-09-10 12:01:01 +02:00
|
|
|
sorted_channels = OrderedDict(sorted(channels.items(), key=get_channel_key))
|
|
|
|
json.dump(sorted_channels, out, indent=2)
|
2019-11-06 20:37:25 +01:00
|
|
|
out.write('\n')
|
2021-01-14 20:37:01 +01:00
|
|
|
print_updates(last_channels, sorted_channels)
|