scripts: Add IREE compiler download script Download the latest snapshot from https://github.com/google/iree/releases Change-Id: Ia44acfa77b07e9e7923b798a3101faf492480506
diff --git a/download_iree_compiler.py b/download_iree_compiler.py new file mode 100755 index 0000000..e18aa1d --- /dev/null +++ b/download_iree_compiler.py
@@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +"""Download IREE host compiler from the snapshot release.""" + +import os +import sys +import tarfile +import requests +import wget + +iree_compiler_dir = os.getenv("IREE_COMPILER_DIR") +if not iree_compiler_dir: + print("Please run 'source build/setup.sh' first") + sys.exit(-1) + +r = requests.get( + "https://api.github.com/repos/google/iree/releases?per_page=1", auth=( + 'user', 'pass')) + +if r.status_code != 200: + print("Not getting the right snapshot information. Status code: %d", r.status_code) + sys.exit(-1) + +snapshot = r.json()[0] + +tag_name = snapshot["tag_name"] +commit_sha = snapshot["target_commitish"] + +print("Latest snapshot: %s" % tag_name) + +tag_file = os.path.join(iree_compiler_dir, "tag") + +# Check the tag of the existing download. +TAG_MATCH = False +if os.path.isfile(tag_file): + file = open(tag_file, "r") + for line in file: + if tag_name == line.replace("\n", ""): + TAG_MATCH = True + file.close() + break + file.close() + +if TAG_MATCH: + print("IREE compiler is up-to-date") + sys.exit(0) + +# Find the linux tarball and download it. +TAR_MATCH = False +for asset in snapshot["assets"]: + download_url = asset["browser_download_url"] + tar_name = asset["name"] + if "linux-x86_64.tar" in tar_name: + TAR_MATCH = True + break + +if not TAR_MATCH: + print("linux-x86_64 tarball is not found") + sys.exit(-1) + +print("Download %s from %s" % (tar_name, download_url)) + +tmp_dir = os.path.join(os.getenv("OUT"), "tmp") + +if not os.path.isdir(tmp_dir): + os.mkdir(tmp_dir) + +tar_file = os.path.join(tmp_dir, tar_name) +wget.download(download_url, out=tar_file) + +# Extract the tarball to ${iree_compiler_dir}/install +install_dir = os.path.join(iree_compiler_dir, "install") +if not install_dir: + os.mkdir(install_dir) + +tar = tarfile.open(tar_file) +tar.extractall(path=install_dir) +tar.close() + +os.remove(tar_file) +print("\nIREE compiler is installed") + +# Add tag file for future checks +with open(tag_file, "w") as f: + f.write("%s\ncommit_sha: %s\n" % (tag_name, commit_sha))
diff --git a/install-prereqs.sh b/install-prereqs.sh index 02b78bc..2a3154a 100755 --- a/install-prereqs.sh +++ b/install-prereqs.sh
@@ -94,6 +94,7 @@ mako matplotlib requests + wget ) PYTHON3_PACKAGES=(