Skip to content

Commit bad9ff6

Browse files
trop[bot]alexeykuzmin
authored andcommitted
build: extract external binaries config (electron#16316)
1 parent 26adc6f commit bad9ff6

File tree

3 files changed

+100
-37
lines changed

3 files changed

+100
-37
lines changed

DEPS

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ hooks = [
9999
'action': [
100100
'python',
101101
'src/electron/script/update-external-binaries.py',
102-
'--root-url=http://github.com/electron/electron-frameworks/releases/download',
103-
'--version=v1.4.0',
104102
],
105103
},
106104
{

script/external-binaries.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"baseUrl": "http://github.com/electron/electron-frameworks/releases/download",
3+
"version": "v1.4.0",
4+
"binaries": [
5+
{
6+
"url": "Mantle.zip",
7+
"platform": "darwin"
8+
},
9+
{
10+
"url": "ReactiveCocoa.zip",
11+
"platform": "darwin"
12+
},
13+
{
14+
"url": "Squirrel.zip",
15+
"platform": "darwin"
16+
},
17+
{
18+
"url": "directxsdk-ia32.zip",
19+
"platform": "win32",
20+
"targetArch": "ia32"
21+
},
22+
{
23+
"url": "directxsdk-x64.zip",
24+
"platform": "win32",
25+
"targetArch": "x64"
26+
},
27+
{
28+
"url": "sccache-darwin-x64.zip",
29+
"platform": "darwin"
30+
},
31+
{
32+
"url": "sccache-linux-x64.zip",
33+
"platform": "linux"
34+
},
35+
{
36+
"url": "sccache-win32-x64.zip",
37+
"platform": "win32"
38+
}
39+
]
40+
}

script/update-external-binaries.py

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import argparse
44
import errno
5-
import sys
5+
import json
66
import os
77

88
from lib.config import PLATFORM, get_target_arch
@@ -11,46 +11,55 @@
1111

1212
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
1313

14+
1415
def parse_args():
1516
parser = argparse.ArgumentParser(
1617
description='Download binaries for Electron build')
1718

18-
parser.add_argument('-u', '--root-url', required=True,
19-
help="Root URL for all downloads.")
20-
parser.add_argument('-v', '--version', required=True,
21-
help="Version string, e.g. 'v1.0.0'.")
19+
parser.add_argument('--base-url', required=False,
20+
help="Base URL for all downloads")
2221

2322
return parser.parse_args()
2423

24+
25+
def parse_config():
26+
config_path = os.path.join(SOURCE_ROOT, 'script', 'external-binaries.json')
27+
with open(config_path, 'r') as config_file:
28+
config = json.load(config_file)
29+
return config
30+
31+
2532
def main():
2633
args = parse_args()
27-
url_prefix = "{root_url}/{version}".format(**vars(args))
34+
config = parse_config()
2835

29-
os.chdir(SOURCE_ROOT)
30-
version_file = os.path.join(SOURCE_ROOT, 'external_binaries', '.version')
36+
base_url = args.base_url if args.base_url is not None else config['baseUrl']
37+
version = config['version']
38+
output_dir = os.path.join(SOURCE_ROOT, 'external_binaries')
39+
version_file = os.path.join(output_dir, '.version')
3140

32-
if (is_updated(version_file, args.version)):
41+
if (is_updated(version_file, version)):
3342
return
3443

35-
rm_rf('external_binaries')
36-
safe_mkdir('external_binaries')
44+
rm_rf(output_dir)
45+
safe_mkdir(output_dir)
46+
47+
for binary in config['binaries']:
48+
if not binary_should_be_downloaded(binary):
49+
continue
50+
51+
temp_path = download_binary(base_url, version, binary['url'])
3752

38-
if sys.platform == 'darwin':
39-
download_and_unzip(url_prefix, 'Mantle')
40-
download_and_unzip(url_prefix, 'ReactiveCocoa')
41-
download_and_unzip(url_prefix, 'Squirrel')
42-
elif sys.platform in ['cygwin', 'win32']:
43-
download_and_unzip(url_prefix, 'directxsdk-' + get_target_arch())
53+
# We assume that all binaries are in zip archives.
54+
extract_zip(temp_path, output_dir)
4455

45-
# get sccache & set exec bit. https://bugs.python.org/issue15795
46-
download_and_unzip(url_prefix, 'sccache-{0}-x64'.format(PLATFORM))
47-
appname = 'sccache'
48-
if sys.platform == 'win32':
49-
appname += '.exe'
50-
add_exec_bit(os.path.join('external_binaries', appname))
56+
# Hack alert. Set exec bit for sccache binaries.
57+
# https://bugs.python.org/issue15795
58+
if 'sccache' in binary['url']:
59+
add_exec_bit_to_sccache_binary(output_dir)
5160

5261
with open(version_file, 'w') as f:
53-
f.write(args.version)
62+
f.write(version)
5463

5564

5665
def is_updated(version_file, version):
@@ -64,21 +73,37 @@ def is_updated(version_file, version):
6473
return existing_version == version
6574

6675

67-
def download_and_unzip(url_prefix, framework):
68-
zip_path = download_framework(url_prefix, framework)
69-
if zip_path:
70-
extract_zip(zip_path, 'external_binaries')
76+
def binary_should_be_downloaded(binary):
77+
if 'platform' in binary and binary['platform'] != PLATFORM:
78+
return False
7179

80+
if 'targetArch' in binary and binary['targetArch'] != get_target_arch():
81+
return False
7282

73-
def download_framework(url_prefix, framework):
74-
filename = framework + '.zip'
75-
url = url_prefix + '/' + filename
83+
return True
84+
85+
86+
def download_binary(base_url, version, binary_url):
87+
full_url = '{0}/{1}/{2}'.format(base_url, version, binary_url)
88+
temp_path = download_to_temp_dir(full_url, filename=binary_url)
89+
return temp_path
90+
91+
92+
def download_to_temp_dir(url, filename):
7693
download_dir = tempdir(prefix='electron-')
77-
path = os.path.join(download_dir, filename)
94+
file_path = os.path.join(download_dir, filename)
95+
download(text='Download ' + filename, url=url, path=file_path)
96+
return file_path
97+
98+
99+
def add_exec_bit_to_sccache_binary(binary_dir):
100+
binary_name = 'sccache'
101+
if PLATFORM == 'win32':
102+
binary_name += '.exe'
78103

79-
download('Download ' + framework, url, path)
80-
return path
104+
binary_path = os.path.join(binary_dir, binary_name)
105+
add_exec_bit(binary_path)
81106

82107

83108
if __name__ == '__main__':
84-
sys.exit(main())
109+
main()

0 commit comments

Comments
 (0)