node/tools/install.py
Gabriel Schulhof 596bd5f1bb src: factor out Node.js-agnostic N-APIs
Split the Node.js ECMAScript API (N-EAPI?) into its own header and
implementation files. The motivation is that the ECMAScript API stand
on its own so it might be embedded separately, implementation and all.

Portions of the implementation used by both files are stored in
`node_api_impl.h`.

The checked boxes below indicate that the given API remains in
`node_api.h`, whereas the lack of a checkbox indicates that the API was
moved to `node_ecma_api.h`.

* [x] NAPI_MODULE
* [x] NAPI_MODULE_INIT
* [x] napi_acquire_threadsafe_function
* [x] napi_add_env_cleanup_hook
* [x] napi_async_destroy
* [x] napi_async_init
* [x] napi_call_threadsafe_function
* [x] napi_cancel_async_work
* [x] napi_close_callback_scope
* [x] napi_create_async_work
* [x] napi_create_buffer
* [x] napi_create_buffer_copy
* [x] napi_create_external_buffer
* [x] napi_create_threadsafe_function
* [x] napi_delete_async_work
* [x] napi_fatal_error
* [x] napi_fatal_exception
* [x] napi_get_buffer_info
* [x] napi_get_node_version
* [x] napi_get_threadsafe_function_context
* [x] napi_get_uv_event_loop
* [x] napi_is_buffer
* [x] napi_make_callback
* [x] napi_module_register
* [x] napi_open_callback_scope
* [x] napi_queue_async_work
* [x] napi_ref_threadsafe_function
* [x] napi_release_threadsafe_function
* [x] napi_remove_env_cleanup_hook
* [x] napi_unref_threadsafe_function
* [ ] napi_add_finalizer
* [ ] napi_adjust_external_memory
* [ ] napi_call_function
* [ ] napi_close_escapable_handle_scope
* [ ] napi_close_handle_scope
* [ ] napi_coerce_to_bool
* [ ] napi_coerce_to_number
* [ ] napi_coerce_to_object
* [ ] napi_coerce_to_string
* [ ] napi_create_array
* [ ] napi_create_arraybuffer
* [ ] napi_create_array_with_length
* [ ] napi_create_bigint_int64
* [ ] napi_create_bigint_uint64
* [ ] napi_create_bigint_words
* [ ] napi_create_dataview
* [ ] napi_create_double
* [ ] napi_create_error
* [ ] napi_create_external
* [ ] napi_create_external_arraybuffer
* [ ] napi_create_function
* [ ] napi_create_int32
* [ ] napi_create_int64
* [ ] napi_create_object
* [ ] napi_create_promise
* [ ] napi_create_range_error
* [ ] napi_create_reference
* [ ] napi_create_string_latin1
* [ ] napi_create_string_utf16
* [ ] napi_create_string_utf8
* [ ] napi_create_symbol
* [ ] napi_create_typedarray
* [ ] napi_create_type_error
* [ ] napi_create_uint32
* [ ] napi_define_class
* [ ] napi_define_properties
* [ ] napi_delete_element
* [ ] napi_delete_property
* [ ] napi_delete_reference
* [ ] napi_escape_handle
* [ ] napi_get_and_clear_last_exception
* [ ] napi_get_arraybuffer_info
* [ ] napi_get_array_length
* [ ] napi_get_boolean
* [ ] napi_get_cb_info
* [ ] napi_get_dataview_info
* [ ] napi_get_element
* [ ] napi_get_global
* [ ] napi_get_last_error_info
* [ ] napi_get_named_property
* [ ] napi_get_new_target
* [ ] napi_get_null
* [ ] napi_get_property
* [ ] napi_get_property_names
* [ ] napi_get_prototype
* [ ] napi_get_reference_value
* [ ] napi_get_typedarray_info
* [ ] napi_get_undefined
* [ ] napi_get_value_bigint_int64
* [ ] napi_get_value_bigint_uint64
* [ ] napi_get_value_bigint_words
* [ ] napi_get_value_bool
* [ ] napi_get_value_double
* [ ] napi_get_value_external
* [ ] napi_get_value_int32
* [ ] napi_get_value_int64
* [ ] napi_get_value_string_latin1
* [ ] napi_get_value_string_utf16
* [ ] napi_get_value_string_utf8
* [ ] napi_get_value_uint32
* [ ] napi_get_version
* [ ] napi_has_element
* [ ] napi_has_named_property
* [ ] napi_has_own_property
* [ ] napi_has_property
* [ ] napi_instanceof
* [ ] napi_is_array
* [ ] napi_is_arraybuffer
* [ ] napi_is_dataview
* [ ] napi_is_error
* [ ] napi_is_exception_pending
* [ ] napi_is_promise
* [ ] napi_is_typedarray
* [ ] napi_new_instance
* [ ] napi_open_escapable_handle_scope
* [ ] napi_open_handle_scope
* [ ] napi_reference_ref
* [ ] napi_reference_unref
* [ ] napi_reject_deferred
* [ ] napi_remove_wrap
* [ ] napi_resolve_deferred
* [ ] napi_run_script
* [ ] napi_set_element
* [ ] napi_set_named_property
* [ ] napi_set_property
* [ ] napi_strict_equals
* [ ] napi_throw
* [ ] napi_throw_error
* [ ] napi_throw_range_error
* [ ] napi_throw_type_error
* [ ] napi_typeof
* [ ] napi_unwrap
* [ ] napi_wrap

PR-URL: https://github.com/nodejs/node/pull/23786
Reviewed-By: Yazhong Liu <yorkiefixer@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2018-11-17 14:38:51 -08:00

235 lines
7.0 KiB
Python
Executable File

#!/usr/bin/env python
import ast
import errno
import os
import re
import shutil
import sys
from getmoduleversion import get_version
# set at init time
node_prefix = '/usr/local' # PREFIX variable from Makefile
install_path = None # base target directory (DESTDIR + PREFIX from Makefile)
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()
return ast.literal_eval(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)
try_mkdir_r(os.path.dirname(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)
while path.startswith(install_path):
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('/'):
target_path = abspath(install_path, dst, os.path.basename(path))
else:
target_path = abspath(install_path, dst)
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))
try_unlink(target_path) # prevent ETXTBSY errors
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 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
if os.path.islink(abspath(install_path, target_path)): return
# 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
link_path = abspath(install_path, 'bin/npm')
if action == uninstall:
action([link_path], 'bin/npm')
elif action == install:
try_symlink('../lib/node_modules/npm/bin/npm-cli.js', link_path)
else:
assert(0) # unhandled action type
# 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:
assert(0) # unhandled action type
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 + '/')
def files(action):
is_windows = sys.platform == 'win32'
output_file = 'node'
output_prefix = 'out/Release/'
if 'false' == variables.get('node_shared'):
if is_windows:
output_file += '.exe'
else:
if is_windows:
output_file += '.dll'
else:
output_file = 'lib' + output_file + '.' + variables.get('shlib_suffix')
# GYP will output to lib.target except on OS X, this is hardcoded
# in its source - see the _InstallableTargetInstallPath function.
if sys.platform != 'darwin':
output_prefix += 'lib.target/'
if 'false' == variables.get('node_shared'):
action([output_prefix + output_file], 'bin/' + output_file)
else:
action([output_prefix + output_file], 'lib/' + output_file)
if 'true' == variables.get('node_use_dtrace'):
action(['out/Release/node.d'], 'lib/dtrace/node.d')
# behave similarly for systemtap
action(['src/node.stp'], 'share/systemtap/tapset/')
action(['deps/v8/tools/gdbinit'], 'share/doc/node/')
action(['deps/v8/tools/lldb_commands.py'], 'share/doc/node/')
if 'freebsd' in sys.platform or 'openbsd' in sys.platform:
action(['doc/node.1'], 'man/man1/')
else:
action(['doc/node.1'], 'share/man/man1/')
if 'true' == variables.get('node_install_npm'): npm_files(action)
headers(action)
def headers(action):
def ignore_inspector_headers(files, dest):
inspector_headers = [
'deps/v8/include/v8-inspector.h',
'deps/v8/include/v8-inspector-protocol.h'
]
files = filter(lambda name: name not in inspector_headers, files)
action(files, dest)
action([
'common.gypi',
'config.gypi',
'src/node.h',
'src/node_api.h',
'src/js_native_api.h',
'src/js_native_api_types.h',
'src/node_api_types.h',
'src/node_buffer.h',
'src/node_object_wrap.h',
'src/node_version.h',
], 'include/node/')
# Add the expfile that is created on AIX
if sys.platform.startswith('aix'):
action(['out/Release/node.exp'], 'include/node/')
subdir_files('deps/v8/include', 'include/node/', ignore_inspector_headers)
if 'false' == variables.get('node_shared_libuv'):
subdir_files('deps/uv/include', 'include/node/', action)
if 'true' == variables.get('node_use_openssl') and \
'false' == variables.get('node_shared_openssl'):
subdir_files('deps/openssl/openssl/include/openssl', 'include/node/openssl/', action)
subdir_files('deps/openssl/config/archs', 'include/node/openssl/archs', action)
subdir_files('deps/openssl/config', 'include/node/openssl', action)
if 'false' == variables.get('node_shared_zlib'):
action([
'deps/zlib/zconf.h',
'deps/zlib/zlib.h',
], 'include/node/')
def run(args):
global node_prefix, install_path, target_defaults, variables
# 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)
# argv[3] is a custom install prefix (think PREFIX)
# Difference is that dst_dir won't be included in shebang lines etc.
dst_dir = args[2] if len(args) > 2 else ''
if len(args) > 3:
node_prefix = args[3]
# install_path thus becomes the base target directory.
install_path = dst_dir + node_prefix + '/'
cmd = args[1] if len(args) > 1 else 'install'
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)
raise RuntimeError('Bad command: %s\n' % cmd)
if __name__ == '__main__':
run(sys.argv[:])