2012-08-01 23:06:31 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import errno
|
2013-01-14 22:24:30 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
import json
|
|
|
|
except ImportError:
|
|
|
|
import simplejson as json
|
|
|
|
|
2012-08-01 23:06:31 +00:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# set at init time
|
2013-04-23 18:17:09 +00:00
|
|
|
node_prefix = '/usr/local' # PREFIX variable from Makefile
|
|
|
|
install_path = None # base target directory (DESTDIR + PREFIX from Makefile)
|
2012-08-01 23:06:31 +00:00
|
|
|
target_defaults = None
|
|
|
|
variables = None
|
|
|
|
|
|
|
|
def abspath(*args):
|
|
|
|
path = os.path.join(*args)
|
|
|
|
return os.path.abspath(path)
|
|
|
|
|
|
|
|
def load_config():
|
|
|
|
s = open('config.gypi').read()
|
|
|
|
s = re.sub(r'#.*?\n', '', s) # strip comments
|
|
|
|
s = re.sub(r'\'', '"', s) # convert quotes
|
|
|
|
return json.loads(s)
|
|
|
|
|
|
|
|
def try_unlink(path):
|
|
|
|
try:
|
|
|
|
os.unlink(path)
|
|
|
|
except OSError, e:
|
|
|
|
if e.errno != errno.ENOENT: raise
|
|
|
|
|
|
|
|
def try_symlink(source_path, link_path):
|
|
|
|
print 'symlinking %s -> %s' % (source_path, link_path)
|
|
|
|
try_unlink(link_path)
|
|
|
|
os.symlink(source_path, link_path)
|
|
|
|
|
|
|
|
def try_mkdir_r(path):
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except OSError, e:
|
|
|
|
if e.errno != errno.EEXIST: raise
|
|
|
|
|
|
|
|
def try_rmdir_r(path):
|
|
|
|
path = abspath(path)
|
2013-04-23 18:17:09 +00:00
|
|
|
while path.startswith(install_path):
|
2012-08-01 23:06:31 +00:00
|
|
|
try:
|
|
|
|
os.rmdir(path)
|
|
|
|
except OSError, e:
|
|
|
|
if e.errno == errno.ENOTEMPTY: return
|
|
|
|
if e.errno == errno.ENOENT: return
|
|
|
|
raise
|
|
|
|
path = abspath(path, '..')
|
|
|
|
|
|
|
|
def mkpaths(path, dst):
|
|
|
|
if dst.endswith('/'):
|
2013-04-23 18:17:09 +00:00
|
|
|
target_path = abspath(install_path, dst, os.path.basename(path))
|
2012-08-01 23:06:31 +00:00
|
|
|
else:
|
2013-04-23 18:17:09 +00:00
|
|
|
target_path = abspath(install_path, dst)
|
2012-08-01 23:06:31 +00:00
|
|
|
return path, target_path
|
|
|
|
|
|
|
|
def try_copy(path, dst):
|
|
|
|
source_path, target_path = mkpaths(path, dst)
|
|
|
|
print 'installing %s' % target_path
|
|
|
|
try_mkdir_r(os.path.dirname(target_path))
|
2012-08-04 00:41:32 +00:00
|
|
|
try_unlink(target_path) # prevent ETXTBSY errors
|
2012-08-01 23:06:31 +00:00
|
|
|
return shutil.copy2(source_path, target_path)
|
|
|
|
|
|
|
|
def try_remove(path, dst):
|
|
|
|
source_path, target_path = mkpaths(path, dst)
|
|
|
|
print 'removing %s' % target_path
|
|
|
|
try_unlink(target_path)
|
|
|
|
try_rmdir_r(os.path.dirname(target_path))
|
|
|
|
|
|
|
|
def install(paths, dst): map(lambda path: try_copy(path, dst), paths)
|
|
|
|
def uninstall(paths, dst): map(lambda path: try_remove(path, dst), paths)
|
|
|
|
|
|
|
|
def update_shebang(path, shebang):
|
2012-08-04 07:12:52 +00:00
|
|
|
print 'updating shebang of %s to %s' % (path, shebang)
|
2012-08-01 23:06:31 +00:00
|
|
|
s = open(path, 'r').read()
|
|
|
|
s = re.sub(r'#!.*\n', '#!' + shebang + '\n', s)
|
|
|
|
open(path, 'w').write(s)
|
|
|
|
|
|
|
|
def npm_files(action):
|
|
|
|
target_path = 'lib/node_modules/npm/'
|
|
|
|
|
|
|
|
# don't install npm if the target path is a symlink, it probably means
|
|
|
|
# that a dev version of npm is installed there
|
2013-04-23 18:17:09 +00:00
|
|
|
if os.path.islink(abspath(install_path, target_path)): return
|
2012-08-01 23:06:31 +00:00
|
|
|
|
|
|
|
# npm has a *lot* of files and it'd be a pain to maintain a fixed list here
|
|
|
|
# so we walk its source directory instead...
|
|
|
|
for dirname, subdirs, basenames in os.walk('deps/npm', topdown=True):
|
|
|
|
subdirs[:] = filter('test'.__ne__, subdirs) # skip test suites
|
|
|
|
paths = [os.path.join(dirname, basename) for basename in basenames]
|
|
|
|
action(paths, target_path + dirname[9:] + '/')
|
|
|
|
|
|
|
|
# create/remove symlink
|
2013-04-23 18:17:09 +00:00
|
|
|
link_path = abspath(install_path, 'bin/npm')
|
2012-08-01 23:06:31 +00:00
|
|
|
if action == uninstall:
|
|
|
|
action([link_path], 'bin/npm')
|
|
|
|
elif action == install:
|
|
|
|
try_symlink('../lib/node_modules/npm/bin/npm-cli.js', link_path)
|
2012-08-06 20:22:05 +00:00
|
|
|
if os.environ.get('PORTABLE'):
|
2012-08-06 17:18:27 +00:00
|
|
|
# This crazy hack is necessary to make the shebang execute the copy
|
|
|
|
# of node relative to the same directory as the npm script. The precompiled
|
2015-08-13 16:14:34 +00:00
|
|
|
# binary tarballs use a prefix of "/" which gets translated to "/bin/node"
|
2012-08-06 17:18:27 +00:00
|
|
|
# in the regular shebang modifying logic, which is incorrect since the
|
|
|
|
# precompiled bundle should be able to be extracted anywhere and "just work"
|
2015-08-13 16:14:34 +00:00
|
|
|
shebang = '/bin/sh\n// 2>/dev/null; exec "`dirname "$0"`/node" "$0" "$@"'
|
2012-08-06 17:18:27 +00:00
|
|
|
else:
|
2015-08-13 16:14:34 +00:00
|
|
|
shebang = os.path.join(node_prefix or '/', 'bin/node')
|
2012-08-04 07:12:52 +00:00
|
|
|
update_shebang(link_path, shebang)
|
2012-08-01 23:06:31 +00:00
|
|
|
else:
|
|
|
|
assert(0) # unhandled action type
|
|
|
|
|
2013-10-10 21:42:41 +00:00
|
|
|
def subdir_files(path, dest, action):
|
|
|
|
ret = {}
|
|
|
|
for dirpath, dirnames, filenames in os.walk(path):
|
|
|
|
files = [dirpath + '/' + f for f in filenames if f.endswith('.h')]
|
|
|
|
ret[dest + dirpath.replace(path, '')] = files
|
|
|
|
for subdir, files in ret.items():
|
|
|
|
action(files, subdir + '/')
|
|
|
|
|
2012-08-01 23:06:31 +00:00
|
|
|
def files(action):
|
2015-01-08 13:21:26 +00:00
|
|
|
is_windows = sys.platform == 'win32'
|
|
|
|
|
|
|
|
exeext = '.exe' if is_windows else ''
|
2015-08-13 16:14:34 +00:00
|
|
|
action(['out/Release/node' + exeext], 'bin/node' + exeext)
|
2012-08-01 23:06:31 +00:00
|
|
|
|
2014-02-20 21:03:03 +00:00
|
|
|
if 'true' == variables.get('node_use_dtrace'):
|
|
|
|
action(['out/Release/node.d'], 'lib/dtrace/node.d')
|
2012-08-01 23:06:31 +00:00
|
|
|
|
2013-03-31 03:56:39 +00:00
|
|
|
# behave similarly for systemtap
|
|
|
|
action(['src/node.stp'], 'share/systemtap/tapset/')
|
|
|
|
|
2015-07-06 16:41:04 +00:00
|
|
|
action(['deps/v8/tools/gdbinit'], 'share/doc/node/')
|
|
|
|
|
2012-12-17 11:05:14 +00:00
|
|
|
if 'freebsd' in sys.platform or 'openbsd' in sys.platform:
|
2015-08-13 16:14:34 +00:00
|
|
|
action(['doc/node.1'], 'man/man1/')
|
2012-12-02 01:54:14 +00:00
|
|
|
else:
|
2015-08-13 16:14:34 +00:00
|
|
|
action(['doc/node.1'], 'share/man/man1/')
|
2012-12-02 01:54:14 +00:00
|
|
|
|
2012-09-04 13:08:29 +00:00
|
|
|
if 'true' == variables.get('node_install_npm'): npm_files(action)
|
2012-08-01 23:06:31 +00:00
|
|
|
|
2015-06-14 10:23:43 +00:00
|
|
|
headers(action)
|
|
|
|
|
|
|
|
def headers(action):
|
2013-10-10 21:42:41 +00:00
|
|
|
action([
|
2013-12-20 08:29:06 +00:00
|
|
|
'common.gypi',
|
2013-10-10 21:42:41 +00:00
|
|
|
'config.gypi',
|
|
|
|
'src/node.h',
|
|
|
|
'src/node_buffer.h',
|
|
|
|
'src/node_internals.h',
|
|
|
|
'src/node_object_wrap.h',
|
|
|
|
'src/node_version.h',
|
|
|
|
], 'include/node/')
|
|
|
|
|
2015-09-29 14:22:00 +00:00
|
|
|
# Add the expfile that is created on AIX
|
|
|
|
if sys.platform.startswith('aix'):
|
|
|
|
action(['out/Release/node.exp'], 'include/node/')
|
|
|
|
|
2014-12-03 07:28:40 +00:00
|
|
|
subdir_files('deps/cares/include', 'include/node/', action)
|
2015-04-02 23:13:43 +00:00
|
|
|
subdir_files('deps/v8/include', 'include/node/', action)
|
2013-10-10 21:42:41 +00:00
|
|
|
|
|
|
|
if 'false' == variables.get('node_shared_libuv'):
|
|
|
|
subdir_files('deps/uv/include', 'include/node/', action)
|
|
|
|
|
|
|
|
if 'false' == variables.get('node_shared_openssl'):
|
2015-04-06 07:14:27 +00:00
|
|
|
subdir_files('deps/openssl/openssl/include/openssl', 'include/node/openssl/', action)
|
2015-04-08 08:56:52 +00:00
|
|
|
subdir_files('deps/openssl/config/archs', 'include/node/openssl/archs', action)
|
2013-10-10 21:42:41 +00:00
|
|
|
action(['deps/openssl/config/opensslconf.h'], 'include/node/openssl/')
|
|
|
|
|
|
|
|
if 'false' == variables.get('node_shared_zlib'):
|
|
|
|
action([
|
|
|
|
'deps/zlib/zconf.h',
|
|
|
|
'deps/zlib/zlib.h',
|
|
|
|
], 'include/node/')
|
|
|
|
|
2012-08-01 23:06:31 +00:00
|
|
|
def run(args):
|
2013-04-23 18:17:09 +00:00
|
|
|
global node_prefix, install_path, target_defaults, variables
|
2012-08-01 23:06:31 +00:00
|
|
|
|
|
|
|
# chdir to the project's top-level directory
|
|
|
|
os.chdir(abspath(os.path.dirname(__file__), '..'))
|
|
|
|
|
|
|
|
conf = load_config()
|
|
|
|
variables = conf['variables']
|
|
|
|
target_defaults = conf['target_defaults']
|
|
|
|
|
|
|
|
# argv[2] is a custom install prefix for packagers (think DESTDIR)
|
2013-04-23 18:17:09 +00:00
|
|
|
# argv[3] is a custom install prefix (think PREFIX)
|
|
|
|
# Difference is that dst_dir won't be included in shebang lines etc.
|
2015-05-05 17:23:56 +00:00
|
|
|
dst_dir = args[2] if len(args) > 2 else ''
|
|
|
|
|
2013-04-23 18:17:09 +00:00
|
|
|
if len(args) > 3:
|
|
|
|
node_prefix = args[3]
|
|
|
|
|
|
|
|
# install_path thus becomes the base target directory.
|
|
|
|
install_path = dst_dir + node_prefix + '/'
|
2012-08-01 23:06:31 +00:00
|
|
|
|
|
|
|
cmd = args[1] if len(args) > 1 else 'install'
|
2015-06-14 10:23:43 +00:00
|
|
|
|
|
|
|
if os.environ.get('HEADERS_ONLY'):
|
|
|
|
if cmd == 'install': return headers(install)
|
|
|
|
if cmd == 'uninstall': return headers(uninstall)
|
|
|
|
else:
|
|
|
|
if cmd == 'install': return files(install)
|
|
|
|
if cmd == 'uninstall': return files(uninstall)
|
|
|
|
|
2012-08-01 23:06:31 +00:00
|
|
|
raise RuntimeError('Bad command: %s\n' % cmd)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run(sys.argv[:])
|