Skip to content

Commit 7e75a78

Browse files
yhwangMylesBorins
authored andcommitted
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 <[email protected]> PR-URL: #18626 Refs: #18535 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 5b75572 commit 7e75a78

4 files changed

+47
-0
lines changed

node.gyp

+12
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@
251251
}],
252252
],
253253
}],
254+
[ 'node_shared=="true"', {
255+
'xcode_settings': {
256+
'OTHER_LDFLAGS': [ '-Wl,-rpath,@loader_path', ],
257+
},
258+
}],
254259
[ 'node_intermediate_lib_type=="shared_library" and OS=="win"', {
255260
# On Windows, having the same name for both executable and shared
256261
# lib causes filename collision. Need a different PRODUCT_NAME for
@@ -402,6 +407,10 @@
402407
'conditions': [
403408
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
404409
'product_extension': '<(shlib_suffix)',
410+
'xcode_settings': {
411+
'LD_DYLIB_INSTALL_NAME':
412+
'@rpath/lib<(node_core_target_name).<(shlib_suffix)'
413+
},
405414
}],
406415
['node_shared=="true" and OS=="aix"', {
407416
'product_name': 'node_base',
@@ -1113,6 +1122,9 @@
11131122
'<@(library_files)',
11141123
'common.gypi',
11151124
],
1125+
'direct_dependent_settings': {
1126+
'ldflags': [ '-Wl,-brtl' ],
1127+
},
11161128
},
11171129
]
11181130
}], # end aix section

test/common/shared-lib-util.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* eslint-disable required-modules */
2+
'use strict';
3+
const path = require('path');
4+
5+
// If node executable is linked to shared lib, need to take care about the
6+
// shared lib path.
7+
exports.addLibraryPath = function(env) {
8+
if (!process.config.variables.node_shared) {
9+
return;
10+
}
11+
12+
env = env || process.env;
13+
14+
env.LD_LIBRARY_PATH =
15+
(env.LD_LIBRARY_PATH ? env.LD_LIBRARY_PATH + path.delimiter : '') +
16+
path.join(path.dirname(process.execPath), 'lib.target');
17+
// For AIX.
18+
env.LIBPATH =
19+
(env.LIBPATH ? env.LIBPATH + path.delimiter : '') +
20+
path.join(path.dirname(process.execPath), 'lib.target');
21+
// For Mac OSX.
22+
env.DYLD_LIBRARY_PATH =
23+
(env.DYLD_LIBRARY_PATH ? env.DYLD_LIBRARY_PATH + path.delimiter : '') +
24+
path.dirname(process.execPath);
25+
// For Windows.
26+
env.PATH =
27+
(env.PATH ? env.PATH + path.delimiter : '') +
28+
path.dirname(process.execPath);
29+
};

test/parallel/test-child-process-fork-exec-path.js

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const tmpdir = require('../common/tmpdir');
2828
const msg = { test: 'this' };
2929
const nodePath = process.execPath;
3030
const copyPath = path.join(tmpdir.path, 'node-copy.exe');
31+
const { addLibraryPath } = require('../common/shared-lib-util');
32+
33+
addLibraryPath(process.env);
3134

3235
if (process.env.FORK) {
3336
assert(process.send);

test/parallel/test-module-loading-globalpaths.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const path = require('path');
66
const fs = require('fs');
77
const child_process = require('child_process');
88
const pkgName = 'foo';
9+
const { addLibraryPath } = require('../common/shared-lib-util');
10+
11+
addLibraryPath(process.env);
912

1013
if (process.argv[2] === 'child') {
1114
console.log(require(pkgName).string);

0 commit comments

Comments
 (0)