Move npm helpers to lib/util
This commit is contained in:
parent
7e867f478e
commit
22bc1b004e
2 changed files with 45 additions and 38 deletions
|
@ -9,7 +9,8 @@ import sys
|
||||||
|
|
||||||
from lib.config import BASE_URL, PLATFORM, enable_verbose_mode, \
|
from lib.config import BASE_URL, PLATFORM, enable_verbose_mode, \
|
||||||
is_verbose_mode, get_target_arch
|
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__)))
|
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')
|
DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download')
|
||||||
PYTHON_26_URL = 'https://chromium.googlesource.com/chromium/deps/python_26'
|
PYTHON_26_URL = 'https://chromium.googlesource.com/chromium/deps/python_26'
|
||||||
|
|
||||||
NPM = 'npm'
|
|
||||||
if sys.platform in ['win32', 'cygwin']:
|
|
||||||
NPM += '.cmd'
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
os.chdir(SOURCE_ROOT)
|
os.chdir(SOURCE_ROOT)
|
||||||
|
@ -65,7 +62,6 @@ def main():
|
||||||
create_chrome_version_h()
|
create_chrome_version_h()
|
||||||
touch_config_gypi()
|
touch_config_gypi()
|
||||||
run_update(defines, args.msvs)
|
run_update(defines, args.msvs)
|
||||||
update_electron_modules('spec', args.target_arch)
|
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
|
@ -167,37 +163,6 @@ def set_clang_env(env):
|
||||||
env['CXX'] = os.path.join(llvm_dir, 'clang++')
|
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():
|
def update_win32_python():
|
||||||
with scoped_cwd(VENDOR_DIR):
|
with scoped_cwd(VENDOR_DIR):
|
||||||
if not os.path.exists('python_26'):
|
if not os.path.exists('python_26'):
|
||||||
|
|
|
@ -15,12 +15,16 @@ import urllib2
|
||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
from config import is_verbose_mode
|
from config import is_verbose_mode, PLATFORM
|
||||||
from env_util import get_vs_env
|
from env_util import get_vs_env
|
||||||
|
|
||||||
BOTO_DIR = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'vendor',
|
BOTO_DIR = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'vendor',
|
||||||
'boto'))
|
'boto'))
|
||||||
|
|
||||||
|
NPM = 'npm'
|
||||||
|
if sys.platform in ['win32', 'cygwin']:
|
||||||
|
NPM += '.cmd'
|
||||||
|
|
||||||
|
|
||||||
def get_host_arch():
|
def get_host_arch():
|
||||||
"""Returns the host architecture with a predictable string."""
|
"""Returns the host architecture with a predictable string."""
|
||||||
|
@ -244,3 +248,41 @@ def import_vs_env(target_arch):
|
||||||
vs_arch = 'x86_amd64'
|
vs_arch = 'x86_amd64'
|
||||||
env = get_vs_env('14.0', vs_arch)
|
env = get_vs_env('14.0', vs_arch)
|
||||||
os.environ.update(env)
|
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue