Browse Source

build: make external binaries download action more flexible (#14982)

* build: make external binaries download action more flexible

* chore: reformat DEPS

Make it look more like Chromium //DEPS:
 - use name-pattern-condition-action order for hooks
 - add trailing commas
 - remove some line breaks

Also remove redundant entry from "recursedeps".
Alexey Kuzmin 6 years ago
parent
commit
5525f34363
2 changed files with 52 additions and 53 deletions
  1. 27 39
      DEPS
  2. 25 14
      script/update-external-binaries.py

+ 27 - 39
DEPS

@@ -1,40 +1,30 @@
 vars = {
-  'chromium_version':
-    '68.0.3440.128',
-  'node_version':
-    '18a9880b70039f5d41ee860a95fe84e5ef928973',
+  'chromium_version': '68.0.3440.128',
+  'node_version': '18a9880b70039f5d41ee860a95fe84e5ef928973',
 
   'boto_version': 'f7574aa6cc2c819430c1f05e9a1a1a666ef8169b',
+  'pyyaml_version': '3.12',
   'requests_version': 'e4d59bedfd3c7f4f254f4f5d036587bcd8152458',
 
-  'pyyaml_version':
-    '3.12',
-
   'boto_git': 'https://github.com/boto',
-
-  'chromium_git':
-    'https://chromium.googlesource.com',
-
-  'electron_git':
-    'https://github.com/electron',
-
-  'yaml_git':
-    'https://github.com/yaml',
-
+  'chromium_git': 'https://chromium.googlesource.com',
+  'electron_git': 'https://github.com/electron',
   'requests_git': 'https://github.com/kennethreitz',
+  'yaml_git': 'https://github.com/yaml',
 
   # Python interface to Amazon Web Services. Is used for releases only.
   'checkout_boto': False,
 
-  'checkout_nacl':
-    False,
-  'checkout_libaom':
-    True,
-  'checkout_oculus_sdk':
-    False,
+  'checkout_nacl': False,
+  'checkout_libaom': True,
+  'checkout_oculus_sdk': False,
 
   # Python "requests" module is used for releases only.
   'checkout_requests': False,
+
+  # It is always needed for normal Electron builds,
+  # but might be impossible for custom in-house builds.
+  'download_external_binaries': True,
 }
 
 deps = {
@@ -56,66 +46,64 @@ deps = {
 
 hooks = [
   {
+    'name': 'patch_chromium',
+    'pattern': 'src/electron',
     'action': [
       'python',
       'src/electron/script/apply-patches',
       '--project-root=.',
-      '--commit'
+      '--commit',
     ],
-    'pattern':
-      'src/electron',
-    'name':
-      'patch_chromium'
   },
   {
+    'name': 'electron_external_binaries',
+    'pattern': 'src/electron/script/update-external-binaries.py',
+    'condition': 'download_external_binaries',
     'action': [
       'python',
-      'src/electron/script/update-external-binaries.py'
-    ],
-    'pattern':
       'src/electron/script/update-external-binaries.py',
-    'name':
-      'electron_external_binaries'
+      '--root-url=http://github.com/electron/electron-frameworks/releases/download',
+      '--version=v1.4.0',
+    ],
   },
   {
+    'name': 'electron_npm_deps',
+    'pattern': 'src/electron/package.json',
     'action': [
       'python',
       '-c',
       'import os; os.chdir("src"); os.chdir("electron"); os.system("npm install")',
     ],
-    'pattern': 'src/electron/package.json',
-    'name': 'electron_npm_deps'
   },
   {
     'name': 'setup_boto',
+    'pattern': 'src/electron',
     'condition': 'checkout_boto',
     'action': [
       'python',
       '-c',
       'import os; os.chdir("src"); os.chdir("electron"); os.chdir("vendor"); os.chdir("boto"); os.system("python setup.py build");',
     ],
-    'pattern': 'src/electron',
   },
   {
     'name': 'setup_requests',
+    'pattern': 'src/electron',
     'condition': 'checkout_requests',
     'action': [
       'python',
       '-c',
       'import os; os.chdir("src"); os.chdir("electron"); os.chdir("vendor"); os.chdir("requests"); os.system("python setup.py build");',
     ],
-    'pattern': 'src/electron',
   }
 ]
 
 recursedeps = [
   'src',
-  'src/libchromiumcontent',
 ]
 
 gclient_gn_args = [
   'checkout_libaom',
   'checkout_nacl',
-  'checkout_oculus_sdk'
+  'checkout_oculus_sdk',
 ]
 gclient_gn_args_file =  'src/build/config/gclient_args.gni'

+ 25 - 14
script/update-external-binaries.py

@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+import argparse
 import errno
 import sys
 import os
@@ -8,38 +9,48 @@ from lib.config import PLATFORM, get_target_arch
 from lib.util import add_exec_bit, download, extract_zip, rm_rf, \
                      safe_mkdir, tempdir
 
-VERSION = 'v1.4.0'
 SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
-FRAMEWORKS_URL = 'http://github.com/electron/electron-frameworks/releases' \
-                 '/download/' + VERSION
 
+def parse_args():
+  parser = argparse.ArgumentParser(
+      description='Download binaries for Electron build')
+
+  parser.add_argument('-u', '--root-url', required=True,
+                      help="Root URL for all downloads.")
+  parser.add_argument('-v', '--version', required=True,
+                      help="Version string, e.g. 'v1.0.0'.")
+
+  return parser.parse_args()
 
 def main():
+  args = parse_args()
+  url_prefix = "{root_url}/{version}".format(**vars(args))
+
   os.chdir(SOURCE_ROOT)
   version_file = os.path.join(SOURCE_ROOT, 'external_binaries', '.version')
 
-  if (is_updated(version_file, VERSION)):
+  if (is_updated(version_file, args.version)):
     return
 
   rm_rf('external_binaries')
   safe_mkdir('external_binaries')
 
   if sys.platform == 'darwin':
-    download_and_unzip('Mantle')
-    download_and_unzip('ReactiveCocoa')
-    download_and_unzip('Squirrel')
+    download_and_unzip(url_prefix, 'Mantle')
+    download_and_unzip(url_prefix, 'ReactiveCocoa')
+    download_and_unzip(url_prefix, 'Squirrel')
   elif sys.platform in ['cygwin', 'win32']:
-    download_and_unzip('directxsdk-' + get_target_arch())
+    download_and_unzip(url_prefix, 'directxsdk-' + get_target_arch())
 
   # get sccache & set exec bit. https://bugs.python.org/issue15795
-  download_and_unzip('sccache-{0}-x64'.format(PLATFORM))
+  download_and_unzip(url_prefix, 'sccache-{0}-x64'.format(PLATFORM))
   appname = 'sccache'
   if sys.platform == 'win32':
     appname += '.exe'
   add_exec_bit(os.path.join('external_binaries', appname))
 
   with open(version_file, 'w') as f:
-    f.write(VERSION)
+    f.write(args.version)
 
 
 def is_updated(version_file, version):
@@ -53,15 +64,15 @@ def is_updated(version_file, version):
   return existing_version == version
 
 
-def download_and_unzip(framework):
-  zip_path = download_framework(framework)
+def download_and_unzip(url_prefix, framework):
+  zip_path = download_framework(url_prefix, framework)
   if zip_path:
     extract_zip(zip_path, 'external_binaries')
 
 
-def download_framework(framework):
+def download_framework(url_prefix, framework):
   filename = framework + '.zip'
-  url = FRAMEWORKS_URL + '/' + filename
+  url = url_prefix + '/' + filename
   download_dir = tempdir(prefix='electron-')
   path = os.path.join(download_dir, filename)