From 54a81e45ddfc976a037e01ca71c9f02d614c1f43 Mon Sep 17 00:00:00 2001 From: Kimmo Kinnunen Date: Thu, 12 Apr 2018 09:08:27 +0300 Subject: [PATCH] Add support for downloading Windows VS toolchain from a HTTP URL Add support for downloading Windows VS toolchain from a HTTP URL. This is useful for developers that do not have access to the Chrome toolchain. If the developer specifies DEPOT_TOOLS_WIN_TOOLCHAIN_HTTP_BASE_URL environment variable, the toolchain will be downloaded from that url. Bug: 830569 Change-Id: I41d815a4460085c3b028f56f2e01adc68d8410fe Reviewed-on: https://chromium-review.googlesource.com/1002892 Commit-Queue: Kimmo Kinnunen FI Reviewed-by: Scott Graham --- win_toolchain/get_toolchain_if_necessary.py | 37 +++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/win_toolchain/get_toolchain_if_necessary.py b/win_toolchain/get_toolchain_if_necessary.py index a44ddb000..8ae3d083b 100755 --- a/win_toolchain/get_toolchain_if_necessary.py +++ b/win_toolchain/get_toolchain_if_necessary.py @@ -238,6 +238,10 @@ def CanAccessToolchainBucket(): return code == 0 +def UsesToolchainFromHttp(): + return os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN_HTTP_BASE_URL') != None + + def RequestGsAuthentication(): """Requests that the user authenticate to be able to access gs:// as a Googler. This allows much faster downloads, and pulling (old) toolchains @@ -276,6 +280,30 @@ def DelayBeforeRemoving(target_dir): print +def DownloadUsingHttp(filename): + """Downloads the given file from a url defined in + DEPOT_TOOLS_WIN_TOOLCHAIN_HTTP_BASE_URL environment variable.""" + import urlparse + import urllib2 + from contextlib import closing + temp_dir = tempfile.mkdtemp() + assert os.path.basename(filename) == filename + target_path = os.path.join(temp_dir, filename) + base_url = os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN_HTTP_BASE_URL') + if base_url == None: + sys.exit('Missing DEPOT_TOOLS_WIN_TOOLCHAIN_HTTP_BASE_URL environment ' + 'variable') + src_url = urlparse.urljoin(base_url, filename) + try: + with closing(urllib2.urlopen(src_url)) as fsrc, \ + open(target_path, 'wb') as fdst: + shutil.copyfileobj(fsrc, fdst) + except urllib2.URLError as e: + RmDir(temp_dir) + sys.exit('Failed to retrieve file: %s' % e) + return temp_dir, target_path + + def DownloadUsingGsutil(filename): """Downloads the given file from Google Storage chrome-wintoolchain bucket.""" temp_dir = tempfile.mkdtemp() @@ -306,6 +334,8 @@ def DoTreeMirror(target_dir, tree_sha1): if use_local_zip: temp_dir = None local_zip = tree_sha1 + '.zip' + elif UsesToolchainFromHttp(): + temp_dir, local_zip = DownloadUsingHttp(tree_sha1 + '.zip') else: temp_dir, local_zip = DownloadUsingGsutil(tree_sha1 + '.zip') sys.stdout.write('Extracting %s...\n' % local_zip) @@ -452,14 +482,17 @@ def main(): # based on timestamps to make that case fast. current_hashes = CalculateToolchainHashes(target_dir, True) if desired_hash not in current_hashes: + should_use_http = False should_use_gs = False - if (HaveSrcInternalAccess() or + if UsesToolchainFromHttp(): + should_use_http = True + elif (HaveSrcInternalAccess() or LooksLikeGoogler() or CanAccessToolchainBucket()): should_use_gs = True if not CanAccessToolchainBucket(): RequestGsAuthentication() - if not should_use_gs: + if not should_use_gs and not should_use_http: print('\n\n\nPlease follow the instructions at ' 'https://www.chromium.org/developers/how-tos/' 'build-instructions-windows\n\n')