2013-06-20 15:10:00 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2019-06-15 17:26:09 +00:00
|
|
|
from __future__ import print_function
|
2013-06-29 03:36:02 +00:00
|
|
|
import contextlib
|
2013-06-20 15:10:00 +00:00
|
|
|
import errno
|
2018-09-27 18:53:08 +00:00
|
|
|
import json
|
|
|
|
import os
|
2013-06-20 14:51:58 +00:00
|
|
|
import shutil
|
2013-06-21 02:32:57 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2019-11-19 14:08:20 +00:00
|
|
|
# Python 3 / 2 compat import
|
|
|
|
try:
|
|
|
|
from urllib.request import urlopen
|
|
|
|
except ImportError:
|
|
|
|
from urllib2 import urlopen
|
2013-06-20 15:23:22 +00:00
|
|
|
import zipfile
|
2013-06-20 14:51:58 +00:00
|
|
|
|
2022-04-04 09:32:57 +00:00
|
|
|
from lib.config import is_verbose_mode, s3_config
|
2013-06-20 14:51:58 +00:00
|
|
|
|
2019-06-24 17:18:04 +00:00
|
|
|
ELECTRON_DIR = os.path.abspath(
|
|
|
|
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
)
|
2020-11-09 21:57:53 +00:00
|
|
|
TS_NODE = os.path.join(ELECTRON_DIR, 'node_modules', '.bin', 'ts-node')
|
2018-10-08 20:19:40 +00:00
|
|
|
SRC_DIR = os.path.abspath(os.path.join(__file__, '..', '..', '..', '..'))
|
2016-08-01 02:00:19 +00:00
|
|
|
|
2017-05-25 21:53:42 +00:00
|
|
|
NPM = 'npm'
|
|
|
|
if sys.platform in ['win32', 'cygwin']:
|
|
|
|
NPM += '.cmd'
|
2020-11-09 21:57:53 +00:00
|
|
|
TS_NODE += '.cmd'
|
2017-05-25 21:53:42 +00:00
|
|
|
|
2015-07-01 09:17:44 +00:00
|
|
|
|
2013-06-29 03:36:02 +00:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def scoped_cwd(path):
|
|
|
|
cwd = os.getcwd()
|
|
|
|
os.chdir(path)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
os.chdir(cwd)
|
|
|
|
|
|
|
|
|
2014-08-09 01:22:06 +00:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def scoped_env(key, value):
|
|
|
|
origin = ''
|
|
|
|
if key in os.environ:
|
|
|
|
origin = os.environ[key]
|
|
|
|
os.environ[key] = value
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
os.environ[key] = origin
|
|
|
|
|
|
|
|
|
2013-06-20 15:10:00 +00:00
|
|
|
def download(text, url, path):
|
2014-07-21 08:31:51 +00:00
|
|
|
safe_mkdir(os.path.dirname(path))
|
2014-08-08 06:08:01 +00:00
|
|
|
with open(path, 'wb') as local_file:
|
2019-06-15 17:26:09 +00:00
|
|
|
print("Downloading %s to %s" % (url, path))
|
2019-11-19 14:08:20 +00:00
|
|
|
web_file = urlopen(url)
|
|
|
|
info = web_file.info()
|
|
|
|
if hasattr(info, 'getheader'):
|
|
|
|
file_size = int(info.getheaders("Content-Length")[0])
|
|
|
|
else:
|
|
|
|
file_size = int(info.get("Content-Length")[0])
|
2013-06-20 15:10:00 +00:00
|
|
|
downloaded_size = 0
|
2019-03-27 01:22:54 +00:00
|
|
|
block_size = 4096
|
2013-06-20 14:51:58 +00:00
|
|
|
|
2018-07-30 22:34:38 +00:00
|
|
|
ci = os.environ.get('CI') is not None
|
2014-02-17 09:50:25 +00:00
|
|
|
|
2013-06-20 14:51:58 +00:00
|
|
|
while True:
|
|
|
|
buf = web_file.read(block_size)
|
|
|
|
if not buf:
|
|
|
|
break
|
|
|
|
|
|
|
|
downloaded_size += len(buf)
|
|
|
|
local_file.write(buf)
|
|
|
|
|
2014-02-17 09:50:25 +00:00
|
|
|
if not ci:
|
|
|
|
percent = downloaded_size * 100. / file_size
|
|
|
|
status = "\r%s %10d [%3.1f%%]" % (text, downloaded_size, percent)
|
2019-06-15 17:26:09 +00:00
|
|
|
print(status, end=' ')
|
2013-06-20 14:51:58 +00:00
|
|
|
|
2014-02-17 09:50:25 +00:00
|
|
|
if ci:
|
2019-06-15 17:26:09 +00:00
|
|
|
print("%s done." % (text))
|
2014-02-17 09:50:25 +00:00
|
|
|
else:
|
2019-06-15 17:26:09 +00:00
|
|
|
print()
|
2014-07-21 08:31:51 +00:00
|
|
|
return path
|
2013-06-20 14:51:58 +00:00
|
|
|
|
|
|
|
|
2013-10-26 09:23:16 +00:00
|
|
|
def make_zip(zip_file_path, files, dirs):
|
2013-08-31 01:37:02 +00:00
|
|
|
safe_unlink(zip_file_path)
|
|
|
|
if sys.platform == 'darwin':
|
2020-02-17 00:45:41 +00:00
|
|
|
allfiles = files + dirs
|
|
|
|
execute(['zip', '-r', '-y', zip_file_path] + allfiles)
|
2013-08-31 01:37:02 +00:00
|
|
|
else:
|
2019-11-21 01:21:44 +00:00
|
|
|
zip_file = zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED,
|
|
|
|
allowZip64=True)
|
2013-08-31 01:37:02 +00:00
|
|
|
for filename in files:
|
|
|
|
zip_file.write(filename, filename)
|
2013-10-26 09:23:16 +00:00
|
|
|
for dirname in dirs:
|
|
|
|
for root, _, filenames in os.walk(dirname):
|
|
|
|
for f in filenames:
|
|
|
|
zip_file.write(os.path.join(root, f))
|
2013-08-31 01:37:02 +00:00
|
|
|
zip_file.close()
|
|
|
|
|
2013-06-20 14:51:58 +00:00
|
|
|
|
2013-06-24 09:51:48 +00:00
|
|
|
def rm_rf(path):
|
|
|
|
try:
|
|
|
|
shutil.rmtree(path)
|
2015-07-03 07:07:11 +00:00
|
|
|
except OSError:
|
|
|
|
pass
|
2013-06-24 09:51:48 +00:00
|
|
|
|
|
|
|
|
2013-06-20 14:51:58 +00:00
|
|
|
def safe_unlink(path):
|
|
|
|
try:
|
|
|
|
os.unlink(path)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
def safe_mkdir(path):
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
raise
|
2013-08-12 07:01:05 +00:00
|
|
|
|
|
|
|
|
2018-09-16 17:24:07 +00:00
|
|
|
def execute(argv, env=None, cwd=None):
|
|
|
|
if env is None:
|
|
|
|
env = os.environ
|
2014-12-08 17:02:08 +00:00
|
|
|
if is_verbose_mode():
|
2019-06-15 17:26:09 +00:00
|
|
|
print(' '.join(argv))
|
2014-02-26 14:08:01 +00:00
|
|
|
try:
|
2018-09-16 17:24:07 +00:00
|
|
|
output = subprocess.check_output(argv, stderr=subprocess.STDOUT,
|
|
|
|
env=env, cwd=cwd)
|
2014-12-08 17:02:08 +00:00
|
|
|
if is_verbose_mode():
|
2019-06-15 17:26:09 +00:00
|
|
|
print(output)
|
2014-08-12 12:23:59 +00:00
|
|
|
return output
|
2014-02-26 14:08:01 +00:00
|
|
|
except subprocess.CalledProcessError as e:
|
2019-06-15 17:26:09 +00:00
|
|
|
print(e.output)
|
2014-02-26 14:08:01 +00:00
|
|
|
raise e
|
|
|
|
|
|
|
|
|
2018-09-27 18:53:08 +00:00
|
|
|
def get_electron_branding():
|
2015-04-12 04:45:18 +00:00
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', '..'))
|
2019-06-19 21:05:56 +00:00
|
|
|
branding_file_path = os.path.join(
|
|
|
|
SOURCE_ROOT, 'shell', 'app', 'BRANDING.json')
|
2018-09-27 18:53:08 +00:00
|
|
|
with open(branding_file_path) as f:
|
|
|
|
return json.load(f)
|
2014-12-07 23:42:55 +00:00
|
|
|
|
2016-05-24 17:27:46 +00:00
|
|
|
def get_electron_version():
|
2018-09-27 18:53:08 +00:00
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', '..'))
|
2019-01-12 01:00:43 +00:00
|
|
|
version_file = os.path.join(SOURCE_ROOT, 'ELECTRON_VERSION')
|
2018-09-27 18:53:08 +00:00
|
|
|
with open(version_file) as f:
|
|
|
|
return 'v' + f.read().strip()
|
2014-07-21 08:31:51 +00:00
|
|
|
|
2022-04-04 09:32:57 +00:00
|
|
|
def store_artifact(prefix, key_prefix, files):
|
|
|
|
# Legacy S3 Bucket
|
|
|
|
s3put(prefix, key_prefix, files)
|
|
|
|
# New AZ Storage
|
|
|
|
azput(prefix, key_prefix, files)
|
|
|
|
|
|
|
|
def s3put(prefix, key_prefix, files):
|
|
|
|
bucket, access_key, secret_key = s3_config()
|
2016-08-01 02:00:19 +00:00
|
|
|
env = os.environ.copy()
|
|
|
|
env['AWS_ACCESS_KEY_ID'] = access_key
|
|
|
|
env['AWS_SECRET_ACCESS_KEY'] = secret_key
|
2020-09-30 20:30:10 +00:00
|
|
|
output = execute([
|
|
|
|
'node',
|
|
|
|
os.path.join(os.path.dirname(__file__), 's3put.js'),
|
2014-07-21 08:31:51 +00:00
|
|
|
'--bucket', bucket,
|
|
|
|
'--prefix', prefix,
|
|
|
|
'--key_prefix', key_prefix,
|
2020-09-30 20:30:10 +00:00
|
|
|
'--grant', 'public-read',
|
|
|
|
] + files, env)
|
|
|
|
print(output)
|
2016-05-10 03:44:56 +00:00
|
|
|
|
2022-04-04 09:32:57 +00:00
|
|
|
def azput(prefix, key_prefix, files):
|
|
|
|
env = os.environ.copy()
|
|
|
|
output = execute([
|
|
|
|
'node',
|
|
|
|
os.path.join(os.path.dirname(__file__), 'azput.js'),
|
|
|
|
'--prefix', prefix,
|
|
|
|
'--key_prefix', key_prefix,
|
|
|
|
] + files, env)
|
|
|
|
print(output)
|
|
|
|
|
2018-09-27 05:38:06 +00:00
|
|
|
def get_out_dir():
|
|
|
|
out_dir = 'Debug'
|
|
|
|
override = os.environ.get('ELECTRON_OUT_DIR')
|
|
|
|
if override is not None:
|
|
|
|
out_dir = override
|
2018-10-08 20:19:40 +00:00
|
|
|
return os.path.join(SRC_DIR, 'out', out_dir)
|
2018-09-27 05:38:06 +00:00
|
|
|
|
2018-09-28 01:24:25 +00:00
|
|
|
# NOTE: This path is not created by gn, it is used as a scratch zone by our
|
|
|
|
# upload scripts
|
2018-09-27 06:48:07 +00:00
|
|
|
def get_dist_dir():
|
|
|
|
return os.path.join(get_out_dir(), 'gen', 'electron_dist')
|
2018-09-27 20:14:13 +00:00
|
|
|
|
|
|
|
def get_electron_exec():
|
2018-10-08 20:19:40 +00:00
|
|
|
out_dir = get_out_dir()
|
|
|
|
|
2018-09-27 20:14:13 +00:00
|
|
|
if sys.platform == 'darwin':
|
2018-10-08 20:19:40 +00:00
|
|
|
return '{0}/Electron.app/Contents/MacOS/Electron'.format(out_dir)
|
2022-03-21 02:11:21 +00:00
|
|
|
if sys.platform == 'win32':
|
2018-10-08 20:19:40 +00:00
|
|
|
return '{0}/electron.exe'.format(out_dir)
|
2022-03-21 02:11:21 +00:00
|
|
|
if sys.platform == 'linux':
|
2018-10-08 20:19:40 +00:00
|
|
|
return '{0}/electron'.format(out_dir)
|
|
|
|
|
|
|
|
raise Exception(
|
|
|
|
"get_electron_exec: unexpected platform '{0}'".format(sys.platform))
|
2019-07-09 08:40:26 +00:00
|
|
|
|
|
|
|
def get_buildtools_executable(name):
|
|
|
|
buildtools = os.path.realpath(os.path.join(ELECTRON_DIR, '..', 'buildtools'))
|
|
|
|
chromium_platform = {
|
|
|
|
'darwin': 'mac',
|
2020-01-13 00:58:25 +00:00
|
|
|
'linux': 'linux64',
|
2019-07-09 08:40:26 +00:00
|
|
|
'linux2': 'linux64',
|
|
|
|
'win32': 'win',
|
2022-02-03 20:57:21 +00:00
|
|
|
'cygwin': 'win',
|
2019-07-09 08:40:26 +00:00
|
|
|
}[sys.platform]
|
|
|
|
path = os.path.join(buildtools, chromium_platform, name)
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
path += '.exe'
|
|
|
|
return path
|