11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst path = require('path');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst kNodeShared = Boolean(process.config.variables.node_shared);
61cb0ef41Sopenharmony_ciconst kShlibSuffix = process.config.variables.shlib_suffix;
71cb0ef41Sopenharmony_ciconst kExecPath = path.dirname(process.execPath);
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci// If node executable is linked to shared lib, need to take care about the
101cb0ef41Sopenharmony_ci// shared lib path.
111cb0ef41Sopenharmony_cifunction addLibraryPath(env) {
121cb0ef41Sopenharmony_ci  if (!kNodeShared) {
131cb0ef41Sopenharmony_ci    return;
141cb0ef41Sopenharmony_ci  }
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci  env = env || process.env;
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  env.LD_LIBRARY_PATH =
191cb0ef41Sopenharmony_ci    (env.LD_LIBRARY_PATH ? env.LD_LIBRARY_PATH + path.delimiter : '') +
201cb0ef41Sopenharmony_ci    kExecPath;
211cb0ef41Sopenharmony_ci  // For AIX.
221cb0ef41Sopenharmony_ci  env.LIBPATH =
231cb0ef41Sopenharmony_ci    (env.LIBPATH ? env.LIBPATH + path.delimiter : '') +
241cb0ef41Sopenharmony_ci    kExecPath;
251cb0ef41Sopenharmony_ci  // For Mac OSX.
261cb0ef41Sopenharmony_ci  env.DYLD_LIBRARY_PATH =
271cb0ef41Sopenharmony_ci    (env.DYLD_LIBRARY_PATH ? env.DYLD_LIBRARY_PATH + path.delimiter : '') +
281cb0ef41Sopenharmony_ci    kExecPath;
291cb0ef41Sopenharmony_ci  // For Windows.
301cb0ef41Sopenharmony_ci  env.PATH = (env.PATH ? env.PATH + path.delimiter : '') + kExecPath;
311cb0ef41Sopenharmony_ci}
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci// Get the full path of shared lib.
341cb0ef41Sopenharmony_cifunction getSharedLibPath() {
351cb0ef41Sopenharmony_ci  if (common.isWindows) {
361cb0ef41Sopenharmony_ci    return path.join(kExecPath, 'node.dll');
371cb0ef41Sopenharmony_ci  }
381cb0ef41Sopenharmony_ci  return path.join(kExecPath, `libnode.${kShlibSuffix}`);
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci// Get the binary path of stack frames.
421cb0ef41Sopenharmony_cifunction getBinaryPath() {
431cb0ef41Sopenharmony_ci  return kNodeShared ? getSharedLibPath() : process.execPath;
441cb0ef41Sopenharmony_ci}
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_cimodule.exports = {
471cb0ef41Sopenharmony_ci  addLibraryPath,
481cb0ef41Sopenharmony_ci  getBinaryPath,
491cb0ef41Sopenharmony_ci  getSharedLibPath,
501cb0ef41Sopenharmony_ci};
51