From c5a26a769e69377391ed9bf71ca74d7eae5e6717 Mon Sep 17 00:00:00 2001 From: Henrique Ferreiro Date: Fri, 22 Jun 2018 12:44:05 +0000 Subject: [PATCH] [win-cross] Support using a zip file for the Windows SDK Renames DEPOT_TOOLS_WIN_TOOLCHAIN_HTTP_BASE_URL to DEPOT_TOOLS_WIN_TOOLCHAIN_BASE_LOCATION. This environment variable can now point to a local directory where the Windows SDK zip file is stored. This allows non-Googlers to cross-compile Chromium for Windows. Bug: 852347 Change-Id: I00650e84247f35b4b8cfba204e0f2afd0882b69b Reviewed-on: https://chromium-review.googlesource.com/1098256 Commit-Queue: Nico Weber Reviewed-by: Scott Graham Reviewed-by: Nico Weber --- win_toolchain/get_toolchain_if_necessary.py | 45 ++++++++++++++------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/win_toolchain/get_toolchain_if_necessary.py b/win_toolchain/get_toolchain_if_necessary.py index 8ae3d083b1..f72e28c7b5 100755 --- a/win_toolchain/get_toolchain_if_necessary.py +++ b/win_toolchain/get_toolchain_if_necessary.py @@ -238,8 +238,20 @@ def CanAccessToolchainBucket(): return code == 0 +def ToolchainBaseURL(): + base_url = os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN_BASE_URL', '') + if base_url.startswith('file://'): + base_url = base_url[len('file://'):] + return base_url + + +def UsesToolchainFromFile(): + return os.path.isdir(ToolchainBaseURL()) + + def UsesToolchainFromHttp(): - return os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN_HTTP_BASE_URL') != None + url = ToolchainBaseURL() + return url.startswith('http://') or url.startswith('https://') def RequestGsAuthentication(): @@ -282,17 +294,14 @@ def DelayBeforeRemoving(target_dir): def DownloadUsingHttp(filename): """Downloads the given file from a url defined in - DEPOT_TOOLS_WIN_TOOLCHAIN_HTTP_BASE_URL environment variable.""" + DEPOT_TOOLS_WIN_TOOLCHAIN_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') + base_url = ToolchainBaseURL() src_url = urlparse.urljoin(base_url, filename) try: with closing(urllib2.urlopen(src_url)) as fsrc, \ @@ -330,10 +339,11 @@ def DoTreeMirror(target_dir, tree_sha1): """In order to save temporary space on bots that do not have enough space to download ISOs, unpack them, and copy to the target location, the whole tree is uploaded as a zip to internal storage, and then mirrored here.""" - use_local_zip = bool(int(os.environ.get('USE_LOCAL_ZIP', 0))) - if use_local_zip: + if UsesToolchainFromFile(): temp_dir = None - local_zip = tree_sha1 + '.zip' + local_zip = os.path.join(ToolchainBaseURL(), tree_sha1 + '.zip') + if not os.path.isfile(local_zip): + sys.exit('%s is not a valid file.' % local_zip) elif UsesToolchainFromHttp(): temp_dir, local_zip = DownloadUsingHttp(tree_sha1 + '.zip') else: @@ -482,9 +492,12 @@ 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_file = False should_use_http = False should_use_gs = False - if UsesToolchainFromHttp(): + if UsesToolchainFromFile(): + should_use_file = True + elif UsesToolchainFromHttp(): should_use_http = True elif (HaveSrcInternalAccess() or LooksLikeGoogler() or @@ -492,10 +505,14 @@ def main(): should_use_gs = True if not CanAccessToolchainBucket(): RequestGsAuthentication() - 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') + if not should_use_file and not should_use_gs and not should_use_http: + if sys.platform not in ('win32', 'cygwin'): + doc = 'https://chromium.googlesource.com/chromium/src/+/master/docs/' \ + 'win_cross.md' + else: + doc = 'https://chromium.googlesource.com/chromium/src/+/master/docs/' \ + 'windows_build_instructions.md' + print('\n\n\nPlease follow the instructions at %s\n\n' % doc) return 1 print('Windows toolchain out of date or doesn\'t exist, updating (Pro)...') print(' current_hashes: %s' % ', '.join(current_hashes))