2012-08-02 01:06:31 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2018-12-03 12:28:31 +01:00
|
|
|
from __future__ import print_function
|
2019-04-14 00:09:45 +02:00
|
|
|
|
2018-04-30 14:08:28 +02:00
|
|
|
import ast
|
2012-08-02 01:06:31 +02:00
|
|
|
import errno
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# set at init time
|
2013-04-23 20:17:09 +02:00
|
|
|
node_prefix = '/usr/local' # PREFIX variable from Makefile
|
2019-04-14 00:09:45 +02:00
|
|
|
install_path = '' # base target directory (DESTDIR + PREFIX from Makefile)
|
2012-08-02 01:06:31 +02:00
|
|
|
target_defaults = None
|
|
|
|
variables = None
|
|
|
|
|
|
|
|
def abspath(*args):
|
|
|
|
path = os.path.join(*args)
|
|
|
|
return os.path.abspath(path)
|
|
|
|
|
|
|
|
def load_config():
|
2020-12-25 14:05:28 +01:00
|
|
|
with open('config.gypi') as f:
|
|
|
|
return ast.literal_eval(f.read())
|
2012-08-02 01:06:31 +02:00
|
|
|
|
|
|
|
def try_unlink(path):
|
|
|
|
try:
|
|
|
|
os.unlink(path)
|
2018-12-03 12:28:31 +01:00
|
|
|
except OSError as e:
|
2012-08-02 01:06:31 +02:00
|
|
|
if e.errno != errno.ENOENT: raise
|
|
|
|
|
|
|
|
def try_symlink(source_path, link_path):
|
2018-12-03 12:28:31 +01:00
|
|
|
print('symlinking %s -> %s' % (source_path, link_path))
|
2012-08-02 01:06:31 +02:00
|
|
|
try_unlink(link_path)
|
2017-10-24 13:01:50 +02:00
|
|
|
try_mkdir_r(os.path.dirname(link_path))
|
2012-08-02 01:06:31 +02:00
|
|
|
os.symlink(source_path, link_path)
|
|
|
|
|
|
|
|
def try_mkdir_r(path):
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
2018-12-03 12:28:31 +01:00
|
|
|
except OSError as e:
|
2012-08-02 01:06:31 +02:00
|
|
|
if e.errno != errno.EEXIST: raise
|
|
|
|
|
|
|
|
def try_rmdir_r(path):
|
|
|
|
path = abspath(path)
|
2013-04-23 20:17:09 +02:00
|
|
|
while path.startswith(install_path):
|
2012-08-02 01:06:31 +02:00
|
|
|
try:
|
|
|
|
os.rmdir(path)
|
2018-12-03 12:28:31 +01:00
|
|
|
except OSError as e:
|
2012-08-02 01:06:31 +02:00
|
|
|
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 20:17:09 +02:00
|
|
|
target_path = abspath(install_path, dst, os.path.basename(path))
|
2012-08-02 01:06:31 +02:00
|
|
|
else:
|
2013-04-23 20:17:09 +02:00
|
|
|
target_path = abspath(install_path, dst)
|
2012-08-02 01:06:31 +02:00
|
|
|
return path, target_path
|
|
|
|
|
|
|
|
def try_copy(path, dst):
|
|
|
|
source_path, target_path = mkpaths(path, dst)
|
2018-12-03 12:28:31 +01:00
|
|
|
print('installing %s' % target_path)
|
2012-08-02 01:06:31 +02:00
|
|
|
try_mkdir_r(os.path.dirname(target_path))
|
2012-08-04 02:41:32 +02:00
|
|
|
try_unlink(target_path) # prevent ETXTBSY errors
|
2012-08-02 01:06:31 +02:00
|
|
|
return shutil.copy2(source_path, target_path)
|
|
|
|
|
|
|
|
def try_remove(path, dst):
|
|
|
|
source_path, target_path = mkpaths(path, dst)
|
2018-12-03 12:28:31 +01:00
|
|
|
print('removing %s' % target_path)
|
2012-08-02 01:06:31 +02:00
|
|
|
try_unlink(target_path)
|
|
|
|
try_rmdir_r(os.path.dirname(target_path))
|
|
|
|
|
2019-01-19 11:07:54 +01:00
|
|
|
def install(paths, dst):
|
|
|
|
for path in paths:
|
|
|
|
try_copy(path, dst)
|
|
|
|
|
|
|
|
def uninstall(paths, dst):
|
|
|
|
for path in paths:
|
|
|
|
try_remove(path, dst)
|
2012-08-02 01:06:31 +02:00
|
|
|
|
|
|
|
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 20:17:09 +02:00
|
|
|
if os.path.islink(abspath(install_path, target_path)): return
|
2012-08-02 01:06:31 +02: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):
|
2019-01-19 11:07:54 +01:00
|
|
|
subdirs[:] = [subdir for subdir in subdirs if subdir != 'test']
|
2012-08-02 01:06:31 +02:00
|
|
|
paths = [os.path.join(dirname, basename) for basename in basenames]
|
|
|
|
action(paths, target_path + dirname[9:] + '/')
|
|
|
|
|
|
|
|
# create/remove symlink
|
2013-04-23 20:17:09 +02:00
|
|
|
link_path = abspath(install_path, 'bin/npm')
|
2012-08-02 01:06:31 +02:00
|
|
|
if action == uninstall:
|
|
|
|
action([link_path], 'bin/npm')
|
|
|
|
elif action == install:
|
|
|
|
try_symlink('../lib/node_modules/npm/bin/npm-cli.js', link_path)
|
|
|
|
else:
|
2019-04-14 00:09:45 +02:00
|
|
|
assert 0 # unhandled action type
|
2012-08-02 01:06:31 +02:00
|
|
|
|
2017-07-11 03:53:58 +02:00
|
|
|
# create/remove symlink
|
|
|
|
link_path = abspath(install_path, 'bin/npx')
|
|
|
|
if action == uninstall:
|
|
|
|
action([link_path], 'bin/npx')
|
|
|
|
elif action == install:
|
|
|
|
try_symlink('../lib/node_modules/npm/bin/npx-cli.js', link_path)
|
|
|
|
else:
|
2019-04-14 00:09:45 +02:00
|
|
|
assert 0 # unhandled action type
|
2017-07-11 03:53:58 +02:00
|
|
|
|
2013-10-10 23:42:41 +02:00
|
|
|
def subdir_files(path, dest, action):
|
|
|
|
ret = {}
|
|
|
|
for dirpath, dirnames, filenames in os.walk(path):
|
2019-04-14 00:09:45 +02:00
|
|
|
files_in_path = [dirpath + '/' + f for f in filenames if f.endswith('.h')]
|
|
|
|
ret[dest + dirpath.replace(path, '')] = files_in_path
|
|
|
|
for subdir, files_in_path in ret.items():
|
|
|
|
action(files_in_path, subdir + '/')
|
2013-10-10 23:42:41 +02:00
|
|
|
|
2012-08-02 01:06:31 +02:00
|
|
|
def files(action):
|
2015-01-08 14:21:26 +01:00
|
|
|
is_windows = sys.platform == 'win32'
|
2016-03-27 01:17:55 +01:00
|
|
|
output_file = 'node'
|
|
|
|
output_prefix = 'out/Release/'
|
2015-01-08 14:21:26 +01:00
|
|
|
|
2016-03-27 01:17:55 +01:00
|
|
|
if 'false' == variables.get('node_shared'):
|
|
|
|
if is_windows:
|
|
|
|
output_file += '.exe'
|
|
|
|
else:
|
|
|
|
if is_windows:
|
|
|
|
output_file += '.dll'
|
|
|
|
else:
|
2016-07-12 20:04:29 +02:00
|
|
|
output_file = 'lib' + output_file + '.' + variables.get('shlib_suffix')
|
2016-03-27 01:17:55 +01:00
|
|
|
|
2017-09-02 14:30:14 +02:00
|
|
|
if 'false' == variables.get('node_shared'):
|
|
|
|
action([output_prefix + output_file], 'bin/' + output_file)
|
|
|
|
else:
|
|
|
|
action([output_prefix + output_file], 'lib/' + output_file)
|
2012-08-02 01:06:31 +02:00
|
|
|
|
2014-02-20 22:03:03 +01:00
|
|
|
if 'true' == variables.get('node_use_dtrace'):
|
|
|
|
action(['out/Release/node.d'], 'lib/dtrace/node.d')
|
2012-08-02 01:06:31 +02:00
|
|
|
|
2013-03-31 05:56:39 +02:00
|
|
|
# behave similarly for systemtap
|
|
|
|
action(['src/node.stp'], 'share/systemtap/tapset/')
|
|
|
|
|
2015-07-06 18:41:04 +02:00
|
|
|
action(['deps/v8/tools/gdbinit'], 'share/doc/node/')
|
2017-03-27 09:37:42 +02:00
|
|
|
action(['deps/v8/tools/lldb_commands.py'], 'share/doc/node/')
|
2015-07-06 18:41:04 +02:00
|
|
|
|
2012-12-17 12:05:14 +01:00
|
|
|
if 'freebsd' in sys.platform or 'openbsd' in sys.platform:
|
2015-08-13 18:14:34 +02:00
|
|
|
action(['doc/node.1'], 'man/man1/')
|
2012-12-02 02:54:14 +01:00
|
|
|
else:
|
2015-08-13 18:14:34 +02:00
|
|
|
action(['doc/node.1'], 'share/man/man1/')
|
2012-12-02 02:54:14 +01:00
|
|
|
|
2012-09-04 15:08:29 +02:00
|
|
|
if 'true' == variables.get('node_install_npm'): npm_files(action)
|
2012-08-02 01:06:31 +02:00
|
|
|
|
2015-06-14 12:23:43 +02:00
|
|
|
headers(action)
|
|
|
|
|
|
|
|
def headers(action):
|
build: include minimal V8 headers in distribution
Because Node.js currently distributes all V8 headers, it is not clear
which ones are part of our API and ABI compatibility contract. V8 may
add, remove, or change headers at any time, preventing us sometimes
from updating because the change could affect addons which may depend
on them. Moreover, the `cppgc` library, included in V8, is exposed
even though it is still in active development and doesn't have a
stable API.
Node.js should choose exactly which headers are exposed and part of
our native API, so that it's easier to reason about changes during V8
updates and to prevent us from automatically increasing the API
surface when new headers are added by V8.
Instead of specifically excluding v8-inspector, only include `v8.h`,
`v8-platform.h` (used in `node.h`) and `v8-profiler.h`.
PR-URL: https://github.com/nodejs/node/pull/37570
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: Mary Marchini <oss@mmarchini.me>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
2021-03-02 14:44:49 +01:00
|
|
|
def wanted_v8_headers(files_arg, dest):
|
|
|
|
v8_headers = [
|
|
|
|
'deps/v8/include/cppgc/common.h',
|
|
|
|
'deps/v8/include/v8.h',
|
|
|
|
'deps/v8/include/v8-internal.h',
|
|
|
|
'deps/v8/include/v8-platform.h',
|
|
|
|
'deps/v8/include/v8-profiler.h',
|
|
|
|
'deps/v8/include/v8-version.h',
|
|
|
|
'deps/v8/include/v8config.h',
|
2018-08-29 18:31:25 +02:00
|
|
|
]
|
build: include minimal V8 headers in distribution
Because Node.js currently distributes all V8 headers, it is not clear
which ones are part of our API and ABI compatibility contract. V8 may
add, remove, or change headers at any time, preventing us sometimes
from updating because the change could affect addons which may depend
on them. Moreover, the `cppgc` library, included in V8, is exposed
even though it is still in active development and doesn't have a
stable API.
Node.js should choose exactly which headers are exposed and part of
our native API, so that it's easier to reason about changes during V8
updates and to prevent us from automatically increasing the API
surface when new headers are added by V8.
Instead of specifically excluding v8-inspector, only include `v8.h`,
`v8-platform.h` (used in `node.h`) and `v8-profiler.h`.
PR-URL: https://github.com/nodejs/node/pull/37570
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: Mary Marchini <oss@mmarchini.me>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
2021-03-02 14:44:49 +01:00
|
|
|
files_arg = [name for name in files_arg if name in v8_headers]
|
2019-04-14 00:09:45 +02:00
|
|
|
action(files_arg, dest)
|
2018-08-29 18:31:25 +02:00
|
|
|
|
2013-10-10 23:42:41 +02:00
|
|
|
action([
|
2013-12-20 09:29:06 +01:00
|
|
|
'common.gypi',
|
2013-10-10 23:42:41 +02:00
|
|
|
'config.gypi',
|
|
|
|
'src/node.h',
|
2017-03-20 22:55:26 +01:00
|
|
|
'src/node_api.h',
|
2018-10-19 21:10:59 +02:00
|
|
|
'src/js_native_api.h',
|
|
|
|
'src/js_native_api_types.h',
|
2017-03-20 22:55:26 +01:00
|
|
|
'src/node_api_types.h',
|
2013-10-10 23:42:41 +02:00
|
|
|
'src/node_buffer.h',
|
|
|
|
'src/node_object_wrap.h',
|
|
|
|
'src/node_version.h',
|
|
|
|
], 'include/node/')
|
|
|
|
|
2015-09-29 16:22:00 +02:00
|
|
|
# Add the expfile that is created on AIX
|
|
|
|
if sys.platform.startswith('aix'):
|
|
|
|
action(['out/Release/node.exp'], 'include/node/')
|
|
|
|
|
build: include minimal V8 headers in distribution
Because Node.js currently distributes all V8 headers, it is not clear
which ones are part of our API and ABI compatibility contract. V8 may
add, remove, or change headers at any time, preventing us sometimes
from updating because the change could affect addons which may depend
on them. Moreover, the `cppgc` library, included in V8, is exposed
even though it is still in active development and doesn't have a
stable API.
Node.js should choose exactly which headers are exposed and part of
our native API, so that it's easier to reason about changes during V8
updates and to prevent us from automatically increasing the API
surface when new headers are added by V8.
Instead of specifically excluding v8-inspector, only include `v8.h`,
`v8-platform.h` (used in `node.h`) and `v8-profiler.h`.
PR-URL: https://github.com/nodejs/node/pull/37570
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: Mary Marchini <oss@mmarchini.me>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
2021-03-02 14:44:49 +01:00
|
|
|
subdir_files('deps/v8/include', 'include/node/', wanted_v8_headers)
|
2013-10-10 23:42:41 +02:00
|
|
|
|
|
|
|
if 'false' == variables.get('node_shared_libuv'):
|
|
|
|
subdir_files('deps/uv/include', 'include/node/', action)
|
|
|
|
|
2017-03-09 10:31:54 +01:00
|
|
|
if 'true' == variables.get('node_use_openssl') and \
|
|
|
|
'false' == variables.get('node_shared_openssl'):
|
2015-04-06 09:14:27 +02:00
|
|
|
subdir_files('deps/openssl/openssl/include/openssl', 'include/node/openssl/', action)
|
2015-04-08 10:56:52 +02:00
|
|
|
subdir_files('deps/openssl/config/archs', 'include/node/openssl/archs', action)
|
2018-03-14 03:25:48 +01:00
|
|
|
subdir_files('deps/openssl/config', 'include/node/openssl', action)
|
2013-10-10 23:42:41 +02:00
|
|
|
|
|
|
|
if 'false' == variables.get('node_shared_zlib'):
|
|
|
|
action([
|
|
|
|
'deps/zlib/zconf.h',
|
|
|
|
'deps/zlib/zlib.h',
|
|
|
|
], 'include/node/')
|
|
|
|
|
2012-08-02 01:06:31 +02:00
|
|
|
def run(args):
|
2013-04-23 20:17:09 +02:00
|
|
|
global node_prefix, install_path, target_defaults, variables
|
2012-08-02 01:06:31 +02: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 20:17:09 +02: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 19:23:56 +02:00
|
|
|
dst_dir = args[2] if len(args) > 2 else ''
|
|
|
|
|
2013-04-23 20:17:09 +02: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-02 01:06:31 +02:00
|
|
|
|
|
|
|
cmd = args[1] if len(args) > 1 else 'install'
|
2015-06-14 12:23:43 +02:00
|
|
|
|
|
|
|
if os.environ.get('HEADERS_ONLY'):
|
2020-12-25 14:05:28 +01:00
|
|
|
if cmd == 'install':
|
|
|
|
headers(install)
|
|
|
|
return
|
|
|
|
if cmd == 'uninstall':
|
|
|
|
headers(uninstall)
|
|
|
|
return
|
2015-06-14 12:23:43 +02:00
|
|
|
else:
|
2020-12-25 14:05:28 +01:00
|
|
|
if cmd == 'install':
|
|
|
|
files(install)
|
|
|
|
return
|
|
|
|
if cmd == 'uninstall':
|
|
|
|
files(uninstall)
|
|
|
|
return
|
2015-06-14 12:23:43 +02:00
|
|
|
|
2012-08-02 01:06:31 +02:00
|
|
|
raise RuntimeError('Bad command: %s\n' % cmd)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run(sys.argv[:])
|