Multiarch search path, arch triplet, DFHS path for modules
authorBastien ROUCARIÈS <roucaries.bastien@gmail.com>
Sat, 8 Aug 2020 12:09:43 +0000 (13:09 +0100)
committerJérémy Lal <kapouer@melix.org>
Sat, 8 Aug 2020 12:09:43 +0000 (13:09 +0100)
Last-Update: 2018-09-30
Last-Update: 2020-03-04
Forwarded: https://github.com/nodejs/node/issues/22745
Reviewed-By: Xavier Guimard <yadd@debian.org>
Gbp-Pq: Name dfhs_module_path_arch_triplet.patch

configure.py
lib/internal/modules/cjs/loader.js
test/parallel/test-module-loading-globalpaths.js

index b67ad1f06f4e43bc87798cc41c7d78ad51b4d467..f3cdd87122d0e8263a469b6f8914ef9da635a21c 100755 (executable)
@@ -83,6 +83,11 @@ parser.add_option('--coverage',
     dest='coverage',
     help='Build node with code coverage enabled')
 
+parser.add_option('--arch-triplet',
+    action='store',
+    dest='arch_triplet',
+    help='arch triplet used by distro')
+
 parser.add_option('--debug',
     action='store_true',
     dest='debug',
@@ -121,6 +126,11 @@ parser.add_option('--gdb',
     dest='gdb',
     help='add gdb support')
 
+parser.add_option('--node-relative-path',
+    action='store',
+    dest='node_relative_path',
+    help='Node path(s) used by require, resolved relative to prefix dir.')
+
 parser.add_option('--no-ifaddrs',
     action='store_true',
     dest='no_ifaddrs',
@@ -1209,6 +1219,17 @@ def configure_napi(output):
   version = getnapibuildversion.get_napi_version()
   output['variables']['napi_build_version'] = version
 
+def configure_debian(output):
+  if options.arch_triplet:
+    output['variables']['arch_triplet'] = options.arch_triplet
+  else:
+    output['variables']['arch_triplet'] = 'unknown-unknown-unknown'
+
+  if options.node_relative_path:
+    output['variables']['node_relative_path'] = options.node_relative_path
+  else:
+    output['variables']['node_relative_path']= ''
+
 def configure_library(lib, output, pkgname=None):
   shared_lib = 'shared_' + lib
   output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
@@ -1699,6 +1720,7 @@ flavor = GetFlavor(flavor_params)
 
 configure_node(output)
 configure_napi(output)
+configure_debian(output)
 configure_library('zlib', output)
 configure_library('http_parser', output)
 configure_library('libuv', output)
index 98668573db651a42876c3369e6fa7c2ef97d6e73..5e441b39d2bc588584175b0d94749069abcabab4 100644 (file)
@@ -1232,6 +1232,7 @@ Module.createRequire = createRequire;
 Module._initPaths = function() {
   const homeDir = isWindows ? process.env.USERPROFILE : safeGetenv('HOME');
   const nodePath = isWindows ? process.env.NODE_PATH : safeGetenv('NODE_PATH');
+  const relativePaths = process.config.variables.node_relative_path;
 
   // process.execPath is $PREFIX/bin/node except on Windows where it is
   // $PREFIX\node.exe where $PREFIX is the root of the Node.js installation.
@@ -1239,7 +1240,17 @@ Module._initPaths = function() {
     path.resolve(process.execPath, '..') :
     path.resolve(process.execPath, '..', '..');
 
-  let paths = [path.resolve(prefixDir, 'lib', 'node')];
+  var postDirs = [];
+  if (relativePaths) {
+    relativePaths.split(path.delimiter).map(path => {
+      if (path) postDirs.push(path);
+    });
+  } else {
+    postDirs.push(path.join('lib', 'node'));
+  }
+  let paths = postDirs.map(postDir => {
+    return path.resolve(prefixDir, postDir);
+  });
 
   if (homeDir) {
     paths.unshift(path.resolve(homeDir, '.node_libraries'));
index 5d6a104f29c9d719a17028f09f06717eb1aaaa56..7123059e2a016b37c726753896f00f1ce7188dab 100644 (file)
@@ -73,10 +73,10 @@ if (process.argv[2] === 'child') {
 
   // Test module in $PREFIX/lib/node.
   // Write module into $PREFIX/lib/node.
-  const expectedString = '$PREFIX/lib/node';
+  const expectedString = '$PREFIX/lib/nodejs';
   const prefixLibPath = path.join(prefixPath, 'lib');
   fs.mkdirSync(prefixLibPath);
-  const prefixLibNodePath = path.join(prefixLibPath, 'node');
+  const prefixLibNodePath = path.join(prefixLibPath, 'nodejs');
   fs.mkdirSync(prefixLibNodePath);
   const pkgPath = path.join(prefixLibNodePath, `${pkgName}.js`);
   fs.writeFileSync(pkgPath, `exports.string = '${expectedString}';`);