downloads: Allow for the developer to prevent downloads

Not all developers need to check for the latest version of the IREE
toolchain, or the latest version of the Renode emulator to do their
day-to-day work, and keeping up to date with these tools often causes
significant downtime or delays in a build.

This change adjusts the scripts that do the downloading to honor the
PIN_TOOLCHAINS environment variable, allowing builds to continue
without the latest IREE or Renode toolchains.

PIN_TOOLCHAINS is expected to be a space-delimited list of toolchain
names.

Change-Id: I68ec58a3726e6b8130571e02b99d7b86b561b94d
diff --git a/download_iree_compiler.py b/download_iree_compiler.py
index 39e624e..79cccb9 100755
--- a/download_iree_compiler.py
+++ b/download_iree_compiler.py
@@ -48,6 +48,19 @@
 
 def main():
     """ Download IREE host compiler from the snapshot release."""
+    pin_toolchains = os.getenv("PIN_TOOLCHAINS", '').lower().split(' ')
+    if "iree" in pin_toolchains:
+        print()
+        print("****************************************************")
+        print("*                                                  *")
+        print("*  PIN_TOOLCHAINS includes iree! Skipping the      *")
+        print("*  download of the latest IREE compiler binaries.  *")
+        print("*  Please DO NOT file bugs for IREE mis-behavior!  *")
+        print("*                                                  *")
+        print("****************************************************")
+        print()
+        sys.exit(0)
+
     parser = argparse.ArgumentParser(
         description="Download IREE host compiler from snapshot releases")
     parser.add_argument(
diff --git a/download_renode.py b/download_renode.py
index 4858cb4..9eb48cc 100755
--- a/download_renode.py
+++ b/download_renode.py
@@ -49,6 +49,19 @@
 
 def main():
     """Download and install renode release package."""
+    pin_toolchains = os.getenv('PIN_TOOLCHAINS', '').lower().split(' ')
+    if "renode" in pin_toolchains:
+        print()
+        print("****************************************************")
+        print("*                                                  *")
+        print("*  PIN_TOOLCHAINS includes renode! Skipping the    *")
+        print("*  download of the latest Renode binaries.         *")
+        print("*  PLEASE DON'T file bugs for Renode mis-behavior! *")
+        print("*                                                  *")
+        print("****************************************************")
+        print()
+        sys.exit(0)
+
     out_dir = os.getenv("OUT")
     if not out_dir:
         out_dir = "/tmp"
@@ -92,8 +105,8 @@
             "(.+?).linux-portable.tar.gz", files[1]).group(1)
 
     if not release_found:
-        print(f"!!!!!Renode can't be found with release {args.release_name}, please try a "
-              "different release!!!!!")
+        print(f"!!!!!Renode can't be found with release {args.release_name}, "
+              "please try a different release!!!!!")
         sys.exit(1)
 
     print(f"Release: {release_name}")
@@ -129,10 +142,9 @@
     tar_file = download_artifact(args.release_url, artifact_name, tmp_dir)
 
     # Extract the tarball
-    tar = tarfile.open(tar_file)
-    _, members = strip_top_directory(tar)
-    tar.extractall(members=members, path=renode_dir)
-    tar.close()
+    with tarfile.open(tar_file) as tar:
+        _, members = strip_top_directory(tar)
+        tar.extractall(members=members, path=renode_dir)
 
     os.remove(tar_file)
     print("\nRenode is installed")