test: add lib path env when node_shared=true
When building the node with `--shared` option, the major output is the shared library. However, we still build a node executable which links to the shared lib. It's for testing purpose. When testing with the executable, some test cases move/copy the executable, change the relative path to the shared library and fail. Using lib path env would solve the issue. However, in macOS, need to change the install name for the shared library and use rpath in the executable. In AIX, `-brtl` linker option rebinds the symbols in the executable and addon modules could use them. Signed-off-by: Yihong Wang <yh.wang@ibm.com> PR-URL: https://github.com/nodejs/node/pull/18626 Refs: https://github.com/nodejs/node/issues/18535 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
3e1e450f92
commit
ec9e7922bb
12
node.gyp
12
node.gyp
@ -260,6 +260,11 @@
|
|||||||
}],
|
}],
|
||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
|
[ 'node_shared=="true"', {
|
||||||
|
'xcode_settings': {
|
||||||
|
'OTHER_LDFLAGS': [ '-Wl,-rpath,@loader_path', ],
|
||||||
|
},
|
||||||
|
}],
|
||||||
[ 'node_intermediate_lib_type=="shared_library" and OS=="win"', {
|
[ 'node_intermediate_lib_type=="shared_library" and OS=="win"', {
|
||||||
# On Windows, having the same name for both executable and shared
|
# On Windows, having the same name for both executable and shared
|
||||||
# lib causes filename collision. Need a different PRODUCT_NAME for
|
# lib causes filename collision. Need a different PRODUCT_NAME for
|
||||||
@ -416,6 +421,10 @@
|
|||||||
'conditions': [
|
'conditions': [
|
||||||
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
|
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
|
||||||
'product_extension': '<(shlib_suffix)',
|
'product_extension': '<(shlib_suffix)',
|
||||||
|
'xcode_settings': {
|
||||||
|
'LD_DYLIB_INSTALL_NAME':
|
||||||
|
'@rpath/lib<(node_core_target_name).<(shlib_suffix)'
|
||||||
|
},
|
||||||
}],
|
}],
|
||||||
['node_shared=="true" and OS=="aix"', {
|
['node_shared=="true" and OS=="aix"', {
|
||||||
'product_name': 'node_base',
|
'product_name': 'node_base',
|
||||||
@ -1130,6 +1139,9 @@
|
|||||||
'<@(library_files)',
|
'<@(library_files)',
|
||||||
'common.gypi',
|
'common.gypi',
|
||||||
],
|
],
|
||||||
|
'direct_dependent_settings': {
|
||||||
|
'ldflags': [ '-Wl,-brtl' ],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}], # end aix section
|
}], # end aix section
|
||||||
|
29
test/common/shared-lib-util.js
Normal file
29
test/common/shared-lib-util.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* eslint-disable required-modules */
|
||||||
|
'use strict';
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// If node executable is linked to shared lib, need to take care about the
|
||||||
|
// shared lib path.
|
||||||
|
exports.addLibraryPath = function(env) {
|
||||||
|
if (!process.config.variables.node_shared) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
env = env || process.env;
|
||||||
|
|
||||||
|
env.LD_LIBRARY_PATH =
|
||||||
|
(env.LD_LIBRARY_PATH ? env.LD_LIBRARY_PATH + path.delimiter : '') +
|
||||||
|
path.join(path.dirname(process.execPath), 'lib.target');
|
||||||
|
// For AIX.
|
||||||
|
env.LIBPATH =
|
||||||
|
(env.LIBPATH ? env.LIBPATH + path.delimiter : '') +
|
||||||
|
path.join(path.dirname(process.execPath), 'lib.target');
|
||||||
|
// For Mac OSX.
|
||||||
|
env.DYLD_LIBRARY_PATH =
|
||||||
|
(env.DYLD_LIBRARY_PATH ? env.DYLD_LIBRARY_PATH + path.delimiter : '') +
|
||||||
|
path.dirname(process.execPath);
|
||||||
|
// For Windows.
|
||||||
|
env.PATH =
|
||||||
|
(env.PATH ? env.PATH + path.delimiter : '') +
|
||||||
|
path.dirname(process.execPath);
|
||||||
|
};
|
@ -28,6 +28,9 @@ const tmpdir = require('../common/tmpdir');
|
|||||||
const msg = { test: 'this' };
|
const msg = { test: 'this' };
|
||||||
const nodePath = process.execPath;
|
const nodePath = process.execPath;
|
||||||
const copyPath = path.join(tmpdir.path, 'node-copy.exe');
|
const copyPath = path.join(tmpdir.path, 'node-copy.exe');
|
||||||
|
const { addLibraryPath } = require('../common/shared-lib-util');
|
||||||
|
|
||||||
|
addLibraryPath(process.env);
|
||||||
|
|
||||||
if (process.env.FORK) {
|
if (process.env.FORK) {
|
||||||
assert(process.send);
|
assert(process.send);
|
||||||
|
@ -6,6 +6,9 @@ const path = require('path');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
const pkgName = 'foo';
|
const pkgName = 'foo';
|
||||||
|
const { addLibraryPath } = require('../common/shared-lib-util');
|
||||||
|
|
||||||
|
addLibraryPath(process.env);
|
||||||
|
|
||||||
if (process.argv[2] === 'child') {
|
if (process.argv[2] === 'child') {
|
||||||
console.log(require(pkgName).string);
|
console.log(require(pkgName).string);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user