Multiarch search path, arch triplet, DFHS path for modules
authorBastien ROUCARIÈS <roucaries.bastien@gmail.com>
Sun, 2 Feb 2025 00:03:59 +0000 (01:03 +0100)
committerJérémy Lal <kapouer@melix.org>
Sun, 2 Feb 2025 00:03:59 +0000 (01:03 +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: Topic dfsg
Gbp-Pq: Name multilib_modules.patch

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

index 115c3d38e179e216ad9ca2f62b4c506a57107ab0..5c4095b977e198f6c7457e5e0ce79f43b22f594b 100755 (executable)
@@ -96,6 +96,12 @@ parser.add_argument('--coverage',
     default=None,
     help='Build node with code coverage enabled')
 
+parser.add_argument('--arch-triplet',
+    action='store',
+    dest='arch_triplet',
+    default=None,
+    help='arch triplet used by distro')
+
 parser.add_argument('--debug',
     action='store_true',
     dest='debug',
@@ -149,6 +155,13 @@ parser.add_argument('--gdb',
     default=None,
     help='add gdb support')
 
+parser.add_argument('--node-relative-path',
+    action='store',
+    dest='node_relative_path',
+    default=None,
+    help='Node path(s) used by require, resolved relative to prefix dir.')
+
+
 parser.add_argument('--no-ifaddrs',
     action='store_true',
     dest='no_ifaddrs',
@@ -1552,6 +1565,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))
@@ -2135,6 +2159,7 @@ flavor = GetFlavor(flavor_params)
 configure_node(output)
 configure_node_lib_files(output)
 configure_napi(output)
+configure_debian(output)
 configure_library('zlib', output)
 configure_library('http_parser', output)
 configure_library('libuv', output)
index c284b39b1ac13eaea8776b7b4f457c084dce5fb8..4a15ed34ab62dcb4c83bc0a540768167f936e5c9 100644 (file)
@@ -1643,6 +1643,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.
@@ -1650,7 +1651,18 @@ Module._initPaths = function() {
     path.resolve(process.execPath, '..') :
     path.resolve(process.execPath, '..', '..');
 
-  const paths = [path.resolve(prefixDir, 'lib', 'node')];
+  const postDirs = [];
+  if (relativePaths) {
+    relativePaths.split(path.delimiter).map(path => {
+      if (path) postDirs.push(path);
+    });
+  } else {
+    postDirs.push(path.join('lib', 'node'));
+  }
+
+  const paths = postDirs.map(postDir => {
+    return path.resolve(prefixDir, postDir);
+  });
 
   if (homeDir) {
     ArrayPrototypeUnshift(paths, path.resolve(homeDir, '.node_libraries'));
index a7b846019957d6fee2b5f101180c58d991449dfa..0ee40644f4af3f91a7922bbcfab2622d18100dec 100644 (file)
@@ -71,12 +71,12 @@ if (process.argv[2] === 'child') {
   env.HOME = env.USERPROFILE = bothHomeDir;
   runTest('$HOME/.node_modules', env);
 
-  // Test module in $PREFIX/lib/node.
-  // Write module into $PREFIX/lib/node.
-  const expectedString = '$PREFIX/lib/node';
-  const prefixLibPath = path.join(prefixPath, 'lib');
+  // Test module in $PREFIX/share/node.
+  // Write module into $PREFIX/share/node.
+  const expectedString = '$PREFIX/share/nodejs';
+  const prefixLibPath = path.join(prefixPath, 'share');
   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}';`);