Skip to content

Commit b6f1ae3

Browse files
committed
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]>
1 parent 6abce37 commit b6f1ae3

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

node.gyp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@
260260
}],
261261
],
262262
}],
263+
[ 'node_shared=="true"', {
264+
'xcode_settings': {
265+
'OTHER_LDFLAGS': [ '-Wl,-rpath,@loader_path', ],
266+
},
267+
}],
263268
[ 'node_intermediate_lib_type=="shared_library" and OS=="win"', {
264269
# On Windows, having the same name for both executable and shared
265270
# lib causes filename collision. Need a different PRODUCT_NAME for
@@ -416,6 +421,10 @@
416421
'conditions': [
417422
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
418423
'product_extension': '<(shlib_suffix)',
424+
'xcode_settings': {
425+
'LD_DYLIB_INSTALL_NAME':
426+
'@rpath/lib<(node_core_target_name).<(shlib_suffix)'
427+
},
419428
}],
420429
['node_shared=="true" and OS=="aix"', {
421430
'product_name': 'node_base',
@@ -1130,6 +1139,9 @@
11301139
'<@(library_files)',
11311140
'common.gypi',
11321141
],
1142+
'direct_dependent_settings': {
1143+
'ldflags': [ '-Wl,-brtl' ],
1144+
},
11331145
},
11341146
]
11351147
}], # end aix section

test/common/shared-lib-util.js

Lines changed: 29 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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)