2013-06-20 15:10:00 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2013-06-20 14:51:58 +00:00
|
|
|
import atexit
|
2013-06-29 03:36:02 +00:00
|
|
|
import contextlib
|
2018-08-17 17:42:45 +00:00
|
|
|
import datetime
|
2013-06-20 15:10:00 +00:00
|
|
|
import errno
|
2018-09-27 18:53:08 +00:00
|
|
|
import json
|
|
|
|
import os
|
2015-07-01 09:17:44 +00:00
|
|
|
import platform
|
|
|
|
import re
|
2013-06-20 14:51:58 +00:00
|
|
|
import shutil
|
2015-02-10 09:52:33 +00:00
|
|
|
import ssl
|
2018-08-21 19:40:06 +00:00
|
|
|
import stat
|
2013-06-21 02:32:57 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2013-06-20 14:51:58 +00:00
|
|
|
import tarfile
|
|
|
|
import tempfile
|
|
|
|
import urllib2
|
2013-06-20 15:23:22 +00:00
|
|
|
import zipfile
|
2013-06-20 14:51:58 +00:00
|
|
|
|
2018-09-16 17:24:07 +00:00
|
|
|
from lib.config import is_verbose_mode, PLATFORM
|
|
|
|
from lib.env_util import get_vs_env
|
2013-06-20 14:51:58 +00:00
|
|
|
|
2018-09-27 05:38:06 +00:00
|
|
|
GN_SRC_DIR = os.path.abspath(os.path.join(__file__, '..', '..', '..', '..'))
|
2016-08-01 02:00:19 +00:00
|
|
|
BOTO_DIR = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'vendor',
|
|
|
|
'boto'))
|
|
|
|
|
2017-05-25 21:53:42 +00:00
|
|
|
NPM = 'npm'
|
|
|
|
if sys.platform in ['win32', 'cygwin']:
|
|
|
|
NPM += '.cmd'
|
|
|
|
|
2015-07-01 09:17:44 +00:00
|
|
|
|
2013-06-20 15:10:00 +00:00
|
|
|
def tempdir(prefix=''):
|
|
|
|
directory = tempfile.mkdtemp(prefix=prefix)
|
2013-06-20 14:51:58 +00:00
|
|
|
atexit.register(shutil.rmtree, directory)
|
2013-06-20 15:10:00 +00:00
|
|
|
return directory
|
|
|
|
|
2014-08-12 12:28:18 +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:
|
2015-02-10 09:52:33 +00:00
|
|
|
if hasattr(ssl, '_create_unverified_context'):
|
|
|
|
ssl._create_default_https_context = ssl._create_unverified_context
|
|
|
|
|
2018-08-21 19:40:06 +00:00
|
|
|
print "Downloading %s to %s" % (url, path)
|
2013-06-20 15:10:00 +00:00
|
|
|
web_file = urllib2.urlopen(url)
|
|
|
|
file_size = int(web_file.info().getheaders("Content-Length")[0])
|
|
|
|
downloaded_size = 0
|
|
|
|
block_size = 128
|
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)
|
|
|
|
print status,
|
2013-06-20 14:51:58 +00:00
|
|
|
|
2014-02-17 09:50:25 +00:00
|
|
|
if ci:
|
|
|
|
print "%s done." % (text)
|
|
|
|
else:
|
|
|
|
print
|
2014-07-21 08:31:51 +00:00
|
|
|
return path
|
2013-06-20 14:51:58 +00:00
|
|
|
|
|
|
|
|
2013-06-20 15:23:22 +00:00
|
|
|
def extract_tarball(tarball_path, member, destination):
|
2013-06-20 14:51:58 +00:00
|
|
|
with tarfile.open(tarball_path) as tarball:
|
2013-06-20 15:23:22 +00:00
|
|
|
tarball.extract(member, destination)
|
|
|
|
|
|
|
|
|
|
|
|
def extract_zip(zip_path, destination):
|
2013-06-21 02:32:57 +00:00
|
|
|
if sys.platform == 'darwin':
|
|
|
|
# Use unzip command on Mac to keep symbol links in zip file work.
|
2014-02-26 14:08:01 +00:00
|
|
|
execute(['unzip', zip_path, '-d', destination])
|
2013-06-21 02:32:57 +00:00
|
|
|
else:
|
|
|
|
with zipfile.ZipFile(zip_path) as z:
|
|
|
|
z.extractall(destination)
|
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':
|
2013-10-26 09:23:16 +00:00
|
|
|
files += dirs
|
2014-02-26 14:08:01 +00:00
|
|
|
execute(['zip', '-r', '-y', zip_file_path] + files)
|
2013-08-31 01:37:02 +00:00
|
|
|
else:
|
2013-10-26 09:42:12 +00:00
|
|
|
zip_file = zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED)
|
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():
|
2014-12-07 15:42:59 +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():
|
2014-08-12 12:23:59 +00:00
|
|
|
print output
|
|
|
|
return output
|
2014-02-26 14:08:01 +00:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print e.output
|
|
|
|
raise e
|
|
|
|
|
|
|
|
|
2018-09-16 17:24:07 +00:00
|
|
|
def execute_stdout(argv, env=None, cwd=None):
|
|
|
|
if env is None:
|
|
|
|
env = os.environ
|
2014-12-08 17:02:08 +00:00
|
|
|
if is_verbose_mode():
|
2014-12-07 23:42:55 +00:00
|
|
|
print ' '.join(argv)
|
|
|
|
try:
|
2017-05-22 07:52:40 +00:00
|
|
|
subprocess.check_call(argv, env=env, cwd=cwd)
|
2014-12-07 23:42:55 +00:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print e.output
|
|
|
|
raise e
|
|
|
|
else:
|
2017-11-21 08:07:26 +00:00
|
|
|
execute(argv, env, cwd)
|
2015-04-12 04:45:18 +00:00
|
|
|
|
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__, '..', '..', '..'))
|
2018-09-27 18:53:08 +00:00
|
|
|
branding_file_path = os.path.join(SOURCE_ROOT, 'atom', 'app', 'BRANDING.json')
|
|
|
|
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__, '..', '..', '..'))
|
|
|
|
version_file = os.path.join(SOURCE_ROOT, 'VERSION')
|
|
|
|
with open(version_file) as f:
|
|
|
|
return 'v' + f.read().strip()
|
2014-07-21 08:31:51 +00:00
|
|
|
|
2016-08-01 02:00:19 +00:00
|
|
|
def boto_path_dirs():
|
|
|
|
return [
|
2015-07-03 14:52:26 +00:00
|
|
|
os.path.join(BOTO_DIR, 'build', 'lib'),
|
2016-08-01 02:00:19 +00:00
|
|
|
os.path.join(BOTO_DIR, 'build', 'lib.linux-x86_64-2.7')
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def run_boto_script(access_key, secret_key, script_name, *args):
|
|
|
|
env = os.environ.copy()
|
|
|
|
env['AWS_ACCESS_KEY_ID'] = access_key
|
|
|
|
env['AWS_SECRET_ACCESS_KEY'] = secret_key
|
|
|
|
env['PYTHONPATH'] = os.path.pathsep.join(
|
|
|
|
[env.get('PYTHONPATH', '')] + boto_path_dirs())
|
|
|
|
|
|
|
|
boto = os.path.join(BOTO_DIR, 'bin', script_name)
|
2016-08-01 12:54:03 +00:00
|
|
|
execute([sys.executable, boto] + list(args), env)
|
2016-08-01 02:00:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
def s3put(bucket, access_key, secret_key, prefix, key_prefix, files):
|
|
|
|
args = [
|
2014-07-21 08:31:51 +00:00
|
|
|
'--bucket', bucket,
|
|
|
|
'--prefix', prefix,
|
|
|
|
'--key_prefix', key_prefix,
|
|
|
|
'--grant', 'public-read'
|
|
|
|
] + files
|
|
|
|
|
2016-08-01 02:00:19 +00:00
|
|
|
run_boto_script(access_key, secret_key, 's3put', *args)
|
2016-05-10 03:44:56 +00:00
|
|
|
|
|
|
|
|
2018-08-21 19:40:06 +00:00
|
|
|
def add_exec_bit(filename):
|
|
|
|
os.chmod(filename, os.stat(filename).st_mode | stat.S_IEXEC)
|
|
|
|
|
2018-09-16 17:24:07 +00:00
|
|
|
def parse_version(version):
|
|
|
|
if version[0] == 'v':
|
|
|
|
version = version[1:]
|
|
|
|
|
|
|
|
vs = version.split('.')
|
|
|
|
if len(vs) > 4:
|
|
|
|
return vs[0:4]
|
|
|
|
else:
|
|
|
|
return vs + ['0'] * (4 - len(vs))
|
|
|
|
|
2018-08-17 17:42:45 +00:00
|
|
|
def clean_parse_version(v):
|
|
|
|
return parse_version(v.split("-")[0])
|
|
|
|
|
|
|
|
def is_stable(v):
|
|
|
|
return len(v.split(".")) == 3
|
|
|
|
|
|
|
|
def is_beta(v):
|
|
|
|
return 'beta' in v
|
|
|
|
|
|
|
|
def is_nightly(v):
|
|
|
|
return 'nightly' in v
|
|
|
|
|
|
|
|
def get_nightly_date():
|
|
|
|
return datetime.datetime.today().strftime('%Y%m%d')
|
|
|
|
|
|
|
|
def get_last_major():
|
|
|
|
return execute(['node', 'script/get-last-major-for-master.js'])
|
|
|
|
|
|
|
|
def get_next_nightly(v):
|
|
|
|
pv = clean_parse_version(v)
|
2018-09-16 17:24:07 +00:00
|
|
|
(major, minor, patch) = pv[0:3]
|
2018-08-17 17:42:45 +00:00
|
|
|
|
|
|
|
if (is_stable(v)):
|
|
|
|
patch = str(int(pv[2]) + 1)
|
|
|
|
|
|
|
|
if execute(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) == "master":
|
|
|
|
major = str(get_last_major() + 1)
|
|
|
|
minor = '0'
|
|
|
|
patch = '0'
|
|
|
|
|
|
|
|
pre = 'nightly.' + get_nightly_date()
|
|
|
|
return make_version(major, minor, patch, pre)
|
|
|
|
|
|
|
|
def non_empty(thing):
|
|
|
|
return thing.strip() != ''
|
|
|
|
|
2018-09-12 07:59:06 +00:00
|
|
|
def beta_tag_compare(tag1, tag2):
|
|
|
|
p1 = parse_version(tag1)
|
|
|
|
p2 = parse_version(tag2)
|
|
|
|
return int(p1[3]) - int(p2[3])
|
|
|
|
|
2018-08-17 17:42:45 +00:00
|
|
|
def get_next_beta(v):
|
|
|
|
pv = clean_parse_version(v)
|
|
|
|
tag_pattern = 'v' + pv[0] + '.' + pv[1] + '.' + pv[2] + '-beta.*'
|
2018-09-12 07:59:06 +00:00
|
|
|
tag_list = sorted(filter(
|
2018-08-17 17:42:45 +00:00
|
|
|
non_empty,
|
|
|
|
execute(['git', 'tag', '--list', '-l', tag_pattern]).strip().split('\n')
|
2018-09-12 07:59:06 +00:00
|
|
|
), cmp=beta_tag_compare)
|
2018-08-17 17:42:45 +00:00
|
|
|
if len(tag_list) == 0:
|
|
|
|
return make_version(pv[0] , pv[1], pv[2], 'beta.1')
|
|
|
|
|
|
|
|
lv = parse_version(tag_list[-1])
|
2018-08-17 20:00:43 +00:00
|
|
|
return make_version(pv[0] , pv[1], pv[2], 'beta.' + str(int(lv[3]) + 1))
|
2018-08-17 17:42:45 +00:00
|
|
|
|
|
|
|
def get_next_stable_from_pre(v):
|
|
|
|
pv = clean_parse_version(v)
|
2018-09-16 17:24:07 +00:00
|
|
|
(major, minor, patch) = pv[0:3]
|
2018-08-17 17:42:45 +00:00
|
|
|
return make_version(major, minor, patch)
|
|
|
|
|
|
|
|
def get_next_stable_from_stable(v):
|
|
|
|
pv = clean_parse_version(v)
|
2018-09-16 17:24:07 +00:00
|
|
|
(major, minor, patch) = pv[0:3]
|
2018-08-17 17:42:45 +00:00
|
|
|
return make_version(major, minor, str(int(patch) + 1))
|
|
|
|
|
|
|
|
def make_version(major, minor, patch, pre = None):
|
|
|
|
if pre is None:
|
|
|
|
return major + '.' + minor + '.' + patch
|
|
|
|
return major + "." + minor + "." + patch + '-' + pre
|
2018-09-16 17:24:07 +00:00
|
|
|
|
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
|
|
|
|
return os.path.join(GN_SRC_DIR, 'out', out_dir)
|
|
|
|
|
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():
|
|
|
|
if sys.platform == 'darwin':
|
|
|
|
return 'out/{0}/Electron.app/Contents/MacOS/Electron'.format(get_out_dir())
|
|
|
|
elif sys.platform == 'win32':
|
|
|
|
return 'out/{0}/electron.exe'.format(get_out_dir())
|
|
|
|
elif sys.platform == 'linux':
|
|
|
|
return 'out/{0}/electron'.format(get_out_dir())
|