Merge pull request #16203 from electron/alkuzmin/add-external-binaries-config
build: extract external binaries config
This commit is contained in:
commit
a3e5173c47
3 changed files with 100 additions and 37 deletions
2
DEPS
2
DEPS
|
@ -99,8 +99,6 @@ hooks = [
|
||||||
'action': [
|
'action': [
|
||||||
'python',
|
'python',
|
||||||
'src/electron/script/update-external-binaries.py',
|
'src/electron/script/update-external-binaries.py',
|
||||||
'--root-url=http://github.com/electron/electron-frameworks/releases/download',
|
|
||||||
'--version=v1.4.0',
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
40
script/external-binaries.json
Normal file
40
script/external-binaries.json
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
{
|
||||||
|
"baseUrl": "http://github.com/electron/electron-frameworks/releases/download",
|
||||||
|
"version": "v1.4.0",
|
||||||
|
"binaries": [
|
||||||
|
{
|
||||||
|
"url": "Mantle.zip",
|
||||||
|
"platform": "darwin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "ReactiveCocoa.zip",
|
||||||
|
"platform": "darwin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "Squirrel.zip",
|
||||||
|
"platform": "darwin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "directxsdk-ia32.zip",
|
||||||
|
"platform": "win32",
|
||||||
|
"targetArch": "ia32"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "directxsdk-x64.zip",
|
||||||
|
"platform": "win32",
|
||||||
|
"targetArch": "x64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "sccache-darwin-x64.zip",
|
||||||
|
"platform": "darwin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "sccache-linux-x64.zip",
|
||||||
|
"platform": "linux"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "sccache-win32-x64.zip",
|
||||||
|
"platform": "win32"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import errno
|
import errno
|
||||||
import sys
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from lib.config import PLATFORM, get_target_arch
|
from lib.config import PLATFORM, get_target_arch
|
||||||
|
@ -11,46 +11,55 @@ from lib.util import add_exec_bit, download, extract_zip, rm_rf, \
|
||||||
|
|
||||||
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='Download binaries for Electron build')
|
description='Download binaries for Electron build')
|
||||||
|
|
||||||
parser.add_argument('-u', '--root-url', required=True,
|
parser.add_argument('--base-url', required=False,
|
||||||
help="Root URL for all downloads.")
|
help="Base URL for all downloads")
|
||||||
parser.add_argument('-v', '--version', required=True,
|
|
||||||
help="Version string, e.g. 'v1.0.0'.")
|
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def parse_config():
|
||||||
|
config_path = os.path.join(SOURCE_ROOT, 'script', 'external-binaries.json')
|
||||||
|
with open(config_path, 'r') as config_file:
|
||||||
|
config = json.load(config_file)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
url_prefix = "{root_url}/{version}".format(**vars(args))
|
config = parse_config()
|
||||||
|
|
||||||
os.chdir(SOURCE_ROOT)
|
base_url = args.base_url if args.base_url is not None else config['baseUrl']
|
||||||
version_file = os.path.join(SOURCE_ROOT, 'external_binaries', '.version')
|
version = config['version']
|
||||||
|
output_dir = os.path.join(SOURCE_ROOT, 'external_binaries')
|
||||||
|
version_file = os.path.join(output_dir, '.version')
|
||||||
|
|
||||||
if (is_updated(version_file, args.version)):
|
if (is_updated(version_file, version)):
|
||||||
return
|
return
|
||||||
|
|
||||||
rm_rf('external_binaries')
|
rm_rf(output_dir)
|
||||||
safe_mkdir('external_binaries')
|
safe_mkdir(output_dir)
|
||||||
|
|
||||||
if sys.platform == 'darwin':
|
for binary in config['binaries']:
|
||||||
download_and_unzip(url_prefix, 'Mantle')
|
if not binary_should_be_downloaded(binary):
|
||||||
download_and_unzip(url_prefix, 'ReactiveCocoa')
|
continue
|
||||||
download_and_unzip(url_prefix, 'Squirrel')
|
|
||||||
elif sys.platform in ['cygwin', 'win32']:
|
|
||||||
download_and_unzip(url_prefix, 'directxsdk-' + get_target_arch())
|
|
||||||
|
|
||||||
# get sccache & set exec bit. https://bugs.python.org/issue15795
|
temp_path = download_binary(base_url, version, binary['url'])
|
||||||
download_and_unzip(url_prefix, 'sccache-{0}-x64'.format(PLATFORM))
|
|
||||||
appname = 'sccache'
|
# We assume that all binaries are in zip archives.
|
||||||
if sys.platform == 'win32':
|
extract_zip(temp_path, output_dir)
|
||||||
appname += '.exe'
|
|
||||||
add_exec_bit(os.path.join('external_binaries', appname))
|
# Hack alert. Set exec bit for sccache binaries.
|
||||||
|
# https://bugs.python.org/issue15795
|
||||||
|
if 'sccache' in binary['url']:
|
||||||
|
add_exec_bit_to_sccache_binary(output_dir)
|
||||||
|
|
||||||
with open(version_file, 'w') as f:
|
with open(version_file, 'w') as f:
|
||||||
f.write(args.version)
|
f.write(version)
|
||||||
|
|
||||||
|
|
||||||
def is_updated(version_file, version):
|
def is_updated(version_file, version):
|
||||||
|
@ -64,21 +73,37 @@ def is_updated(version_file, version):
|
||||||
return existing_version == version
|
return existing_version == version
|
||||||
|
|
||||||
|
|
||||||
def download_and_unzip(url_prefix, framework):
|
def binary_should_be_downloaded(binary):
|
||||||
zip_path = download_framework(url_prefix, framework)
|
if 'platform' in binary and binary['platform'] != PLATFORM:
|
||||||
if zip_path:
|
return False
|
||||||
extract_zip(zip_path, 'external_binaries')
|
|
||||||
|
if 'targetArch' in binary and binary['targetArch'] != get_target_arch():
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def download_framework(url_prefix, framework):
|
def download_binary(base_url, version, binary_url):
|
||||||
filename = framework + '.zip'
|
full_url = '{0}/{1}/{2}'.format(base_url, version, binary_url)
|
||||||
url = url_prefix + '/' + filename
|
temp_path = download_to_temp_dir(full_url, filename=binary_url)
|
||||||
|
return temp_path
|
||||||
|
|
||||||
|
|
||||||
|
def download_to_temp_dir(url, filename):
|
||||||
download_dir = tempdir(prefix='electron-')
|
download_dir = tempdir(prefix='electron-')
|
||||||
path = os.path.join(download_dir, filename)
|
file_path = os.path.join(download_dir, filename)
|
||||||
|
download(text='Download ' + filename, url=url, path=file_path)
|
||||||
|
return file_path
|
||||||
|
|
||||||
download('Download ' + framework, url, path)
|
|
||||||
return path
|
def add_exec_bit_to_sccache_binary(binary_dir):
|
||||||
|
binary_name = 'sccache'
|
||||||
|
if PLATFORM == 'win32':
|
||||||
|
binary_name += '.exe'
|
||||||
|
|
||||||
|
binary_path = os.path.join(binary_dir, binary_name)
|
||||||
|
add_exec_bit(binary_path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
main()
|
||||||
|
|
Loading…
Reference in a new issue