• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const path = require('path');
4
5const kNodeShared = Boolean(process.config.variables.node_shared);
6const kShlibSuffix = process.config.variables.shlib_suffix;
7const kExecPath = path.dirname(process.execPath);
8
9// If node executable is linked to shared lib, need to take care about the
10// shared lib path.
11function addLibraryPath(env) {
12  if (!kNodeShared) {
13    return;
14  }
15
16  env = env || process.env;
17
18  env.LD_LIBRARY_PATH =
19    (env.LD_LIBRARY_PATH ? env.LD_LIBRARY_PATH + path.delimiter : '') +
20    path.join(kExecPath, 'lib.target');
21  // For AIX.
22  env.LIBPATH =
23    (env.LIBPATH ? env.LIBPATH + path.delimiter : '') +
24    path.join(kExecPath, 'lib.target');
25  // For Mac OSX.
26  env.DYLD_LIBRARY_PATH =
27    (env.DYLD_LIBRARY_PATH ? env.DYLD_LIBRARY_PATH + path.delimiter : '') +
28    kExecPath;
29  // For Windows.
30  env.PATH = (env.PATH ? env.PATH + path.delimiter : '') + kExecPath;
31}
32
33// Get the full path of shared lib.
34function getSharedLibPath() {
35  if (common.isWindows) {
36    return path.join(kExecPath, 'node.dll');
37  } else if (common.isOSX) {
38    return path.join(kExecPath, `libnode.${kShlibSuffix}`);
39  }
40  return path.join(kExecPath, 'lib.target', `libnode.${kShlibSuffix}`);
41}
42
43// Get the binary path of stack frames.
44function getBinaryPath() {
45  return kNodeShared ? getSharedLibPath() : process.execPath;
46}
47
48module.exports = {
49  addLibraryPath,
50  getBinaryPath,
51  getSharedLibPath
52};
53