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