electron/script/bootstrap.py

116 lines
3.3 KiB
Python
Raw Normal View History

2013-06-19 06:32:41 +00:00
#!/usr/bin/env python
2013-04-12 01:46:58 +00:00
2013-06-19 06:32:41 +00:00
import argparse
import os
import sys
2013-04-12 01:46:58 +00:00
2014-01-31 04:18:30 +00:00
from lib.config import LIBCHROMIUMCONTENT_COMMIT, BASE_URL
2014-03-28 09:25:53 +00:00
from lib.util import execute, scoped_cwd
2013-04-12 01:46:58 +00:00
2013-06-19 06:32:41 +00:00
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor')
PYTHON_26_URL = 'https://chromium.googlesource.com/chromium/deps/python_26'
2014-04-29 03:07:02 +00:00
NPM = 'npm.cmd' if sys.platform in ['win32', 'cygwin'] else 'npm'
2013-04-12 01:46:58 +00:00
2013-06-19 06:32:41 +00:00
def main():
os.chdir(SOURCE_ROOT)
2013-04-12 01:46:58 +00:00
2013-06-19 06:32:41 +00:00
args = parse_args()
2014-02-28 12:44:57 +00:00
update_submodules()
2014-04-28 02:05:22 +00:00
update_node_modules('.')
update_atom_modules('atom/browser/default_app')
update_atom_modules('spec')
2014-02-28 12:44:57 +00:00
bootstrap_brightray(args.url)
if sys.platform == 'cygwin':
update_win32_python()
2014-04-29 04:33:20 +00:00
if sys.platform in ['win32', 'cygwin']:
install_runas()
create_chrome_version_h()
touch_config_gypi()
2013-06-19 06:32:41 +00:00
update_atom_shell()
2013-04-12 01:46:58 +00:00
2013-04-14 14:48:35 +00:00
2013-06-19 06:32:41 +00:00
def parse_args():
parser = argparse.ArgumentParser(description='Bootstrap this project')
parser.add_argument('-u', '--url',
2013-06-19 06:32:41 +00:00
help='The base URL from which to download '
'libchromiumcontent (i.e., the URL you passed to '
'libchromiumcontent\'s script/upload script',
default=BASE_URL,
required=False)
return parser.parse_args()
2013-04-12 01:46:58 +00:00
2013-06-19 06:32:41 +00:00
def update_submodules():
2014-03-28 09:36:35 +00:00
execute(['git', 'submodule', 'sync'])
execute(['git', 'submodule', 'update', '--init', '--recursive'])
2013-06-19 06:32:41 +00:00
def bootstrap_brightray(url):
bootstrap = os.path.join(VENDOR_DIR, 'brightray', 'script', 'bootstrap')
2014-03-28 09:36:35 +00:00
execute([sys.executable, bootstrap, '--commit', LIBCHROMIUMCONTENT_COMMIT,
url])
2013-06-19 06:32:41 +00:00
2014-04-28 02:05:22 +00:00
def update_node_modules(dirname):
with scoped_cwd(dirname):
execute([NPM, 'install'])
2014-04-28 02:05:22 +00:00
def update_atom_modules(dirname):
with scoped_cwd(dirname):
2014-04-28 02:05:22 +00:00
apm = os.path.join(SOURCE_ROOT, 'node_modules', '.bin', 'apm')
2014-03-28 09:30:15 +00:00
if sys.platform in ['win32', 'cygwin']:
2014-04-29 03:12:41 +00:00
apm = os.path.join(SOURCE_ROOT, 'node_modules', 'atom-package-manager',
'bin', 'apm.cmd')
2014-04-28 02:05:22 +00:00
execute([apm, 'install'])
def update_win32_python():
with scoped_cwd(VENDOR_DIR):
if not os.path.exists('python_26'):
2014-03-28 09:36:35 +00:00
execute(['git', 'clone', PYTHON_26_URL])
2014-04-29 04:33:20 +00:00
def install_runas():
# TODO This is needed by the tools/win/register_msdia80_dll.js, should move
# this to a better place.
with scoped_cwd(os.path.join(SOURCE_ROOT, 'tools', 'win')):
execute([NPM, 'install', 'runas'])
def create_chrome_version_h():
version_file = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor',
'libchromiumcontent', 'VERSION')
target_file = os.path.join(SOURCE_ROOT, 'atom', 'common', 'chrome_version.h')
template_file = os.path.join(SOURCE_ROOT, 'script', 'chrome_version.h.in')
with open(version_file, 'r') as f:
version = f.read()
with open(template_file, 'r') as f:
template = f.read()
with open(target_file, 'w+') as f:
content = template.replace('{PLACEHOLDER}', version.strip())
if f.read() != content:
f.write(content)
def touch_config_gypi():
config_gypi = os.path.join(SOURCE_ROOT, 'vendor', 'node', 'config.gypi')
with open(config_gypi, 'w+') as f:
content = '\n{}'
if f.read() != content:
f.write(content)
2013-06-19 06:32:41 +00:00
def update_atom_shell():
2013-06-24 07:24:30 +00:00
update = os.path.join(SOURCE_ROOT, 'script', 'update.py')
2014-03-28 09:36:35 +00:00
execute([sys.executable, update])
2013-06-19 06:32:41 +00:00
if __name__ == '__main__':
sys.exit(main())