#!/usr/bin/env python3 # Simpler reimplementation of Android's sdkmanager # Extra features of this implementation are pinning and mirroring # These URLs are the Google repositories containing the list of available # packages and their versions. The list has been generated by listing the URLs # fetched while executing `tools/bin/sdkmanager --list` BASE_REPOSITORY = "https://dl.google.com/android/repository/" REPOSITORIES = [ "sys-img/android/sys-img2-1.xml", "sys-img/android-wear/sys-img2-1.xml", "sys-img/android-wear-cn/sys-img2-1.xml", "sys-img/android-tv/sys-img2-1.xml", "sys-img/google_apis/sys-img2-1.xml", "sys-img/google_apis_playstore/sys-img2-1.xml", "addon2-1.xml", "glass/addon2-1.xml", "extras/intel/addon2-1.xml", "repository2-1.xml", ] # Available hosts: linux, macosx and windows HOST_OS = "linux" # Mirroring options MIRROR_BUCKET = "rust-lang-ci-mirrors" MIRROR_BUCKET_REGION = "us-west-1" MIRROR_BASE_DIR = "rustc/android/" import argparse import hashlib import os import subprocess import sys import tempfile import urllib.request import xml.etree.ElementTree as ET class Package: def __init__(self, path, url, sha1, deps=None): if deps is None: deps = [] self.path = path.strip() self.url = url.strip() self.sha1 = sha1.strip() self.deps = deps def download(self, base_url): _, file = tempfile.mkstemp() url = base_url + self.url subprocess.run(["curl", "-o", file, url], check=True) # Ensure there are no hash mismatches with open(file, "rb") as f: sha1 = hashlib.sha1(f.read()).hexdigest() if sha1 != self.sha1: raise RuntimeError( "hash mismatch for package " + self.path + ": " + sha1 + " vs " + self.sha1 + " (known good)" ) return file def __repr__(self): return "