node/test/common/shared-lib-util.js
Rod Vagg 999e7d7b44
gyp,build: consistent shared library location
Ref: https://github.com/nodejs/node-gyp/issues/2233
Ref: https://github.com/nodejs/gyp-next/pull/69

PR-URL: https://github.com/nodejs/node/pull/35635
Refs: https://github.com/nodejs/gyp-next/releases/tag/v0.6.0
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
2020-10-14 12:09:57 +05:30

51 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
const path = require('path');
const kNodeShared = Boolean(process.config.variables.node_shared);
const kShlibSuffix = process.config.variables.shlib_suffix;
const kExecPath = path.dirname(process.execPath);
// If node executable is linked to shared lib, need to take care about the
// shared lib path.
function addLibraryPath(env) {
if (!kNodeShared) {
return;
}
env = env || process.env;
env.LD_LIBRARY_PATH =
(env.LD_LIBRARY_PATH ? env.LD_LIBRARY_PATH + path.delimiter : '') +
kExecPath;
// For AIX.
env.LIBPATH =
(env.LIBPATH ? env.LIBPATH + path.delimiter : '') +
kExecPath;
// For Mac OSX.
env.DYLD_LIBRARY_PATH =
(env.DYLD_LIBRARY_PATH ? env.DYLD_LIBRARY_PATH + path.delimiter : '') +
kExecPath;
// For Windows.
env.PATH = (env.PATH ? env.PATH + path.delimiter : '') + kExecPath;
}
// Get the full path of shared lib.
function getSharedLibPath() {
if (common.isWindows) {
return path.join(kExecPath, 'node.dll');
}
return path.join(kExecPath, `libnode.${kShlibSuffix}`);
}
// Get the binary path of stack frames.
function getBinaryPath() {
return kNodeShared ? getSharedLibPath() : process.execPath;
}
module.exports = {
addLibraryPath,
getBinaryPath,
getSharedLibPath
};