From 22bc1b004ec7cd0078c657749da9a7372614be17 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 25 May 2017 14:53:42 -0700 Subject: [PATCH] Move npm helpers to lib/util --- script/bootstrap.py | 39 ++------------------------------------- script/lib/util.py | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 38 deletions(-) diff --git a/script/bootstrap.py b/script/bootstrap.py index 3e9d34a48a70..b30f23961182 100755 --- a/script/bootstrap.py +++ b/script/bootstrap.py @@ -9,7 +9,8 @@ import sys from lib.config import BASE_URL, PLATFORM, enable_verbose_mode, \ is_verbose_mode, get_target_arch -from lib.util import execute, execute_stdout, get_electron_version, scoped_cwd +from lib.util import execute, execute_stdout, get_electron_version, \ + scoped_cwd, update_node_modules SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) @@ -17,10 +18,6 @@ VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor') DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download') PYTHON_26_URL = 'https://chromium.googlesource.com/chromium/deps/python_26' -NPM = 'npm' -if sys.platform in ['win32', 'cygwin']: - NPM += '.cmd' - def main(): os.chdir(SOURCE_ROOT) @@ -65,7 +62,6 @@ def main(): create_chrome_version_h() touch_config_gypi() run_update(defines, args.msvs) - update_electron_modules('spec', args.target_arch) def parse_args(): @@ -167,37 +163,6 @@ def set_clang_env(env): env['CXX'] = os.path.join(llvm_dir, 'clang++') -def update_node_modules(dirname, env=None): - if env is None: - env = os.environ.copy() - if PLATFORM == 'linux': - # Use prebuilt clang for building native modules. - set_clang_env(env) - env['npm_config_clang'] = '1' - with scoped_cwd(dirname): - args = [NPM, 'install'] - if is_verbose_mode(): - args += ['--verbose'] - # Ignore npm install errors when running in CI. - if os.environ.has_key('CI'): - try: - execute_stdout(args, env) - except subprocess.CalledProcessError: - pass - else: - execute_stdout(args, env) - - -def update_electron_modules(dirname, target_arch): - env = os.environ.copy() - version = get_electron_version() - env['npm_config_arch'] = target_arch - env['npm_config_target'] = version - env['npm_config_nodedir'] = os.path.join(SOURCE_ROOT, 'dist', - 'node-{0}'.format(version)) - update_node_modules(dirname, env) - - def update_win32_python(): with scoped_cwd(VENDOR_DIR): if not os.path.exists('python_26'): diff --git a/script/lib/util.py b/script/lib/util.py index b40ccd0cce61..27355803fa70 100644 --- a/script/lib/util.py +++ b/script/lib/util.py @@ -15,12 +15,16 @@ import urllib2 import os import zipfile -from config import is_verbose_mode +from config import is_verbose_mode, PLATFORM from env_util import get_vs_env BOTO_DIR = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'vendor', 'boto')) +NPM = 'npm' +if sys.platform in ['win32', 'cygwin']: + NPM += '.cmd' + def get_host_arch(): """Returns the host architecture with a predictable string.""" @@ -244,3 +248,41 @@ def import_vs_env(target_arch): vs_arch = 'x86_amd64' env = get_vs_env('14.0', vs_arch) os.environ.update(env) + + +def set_clang_env(env): + SOURCE_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', '..')) + llvm_dir = os.path.join(SOURCE_ROOT, 'vendor', 'llvm-build', + 'Release+Asserts', 'bin') + env['CC'] = os.path.join(llvm_dir, 'clang') + env['CXX'] = os.path.join(llvm_dir, 'clang++') + + +def update_electron_modules(dirname, target_arch, nodedir): + env = os.environ.copy() + version = get_electron_version() + env['npm_config_arch'] = target_arch + env['npm_config_target'] = version + env['npm_config_nodedir'] = nodedir + update_node_modules(dirname, env) + + +def update_node_modules(dirname, env=None): + if env is None: + env = os.environ.copy() + if PLATFORM == 'linux': + # Use prebuilt clang for building native modules. + set_clang_env(env) + env['npm_config_clang'] = '1' + with scoped_cwd(dirname): + args = [NPM, 'install'] + if is_verbose_mode(): + args += ['--verbose'] + # Ignore npm install errors when running in CI. + if os.environ.has_key('CI'): + try: + execute_stdout(args, env) + except subprocess.CalledProcessError: + pass + else: + execute_stdout(args, env)