-
Notifications
You must be signed in to change notification settings - Fork 295
Build native dependencies with spaces in apm's path #673
Conversation
775af07
to
14004d9
Compare
@smashwilson what's the story here for Windows? |
@BinaryMuse Windows should be unaffected, as Windows users will go in through I should verify that |
I have been installing packages with native dependencies fine on Windows, and I know @damieng has as well. Both of us have spaces in the directory path. |
@50Wliu Perfect. I just confirmed that this works:
|
@@ -85,7 +84,8 @@ class Install extends Command | |||
opts = {env, cwd: @atomDirectory} | |||
opts.streaming = true if @verbose | |||
|
|||
@fork @atomNodeGypPath, installNodeArgs, opts, (code, stderr='', stdout='') -> | |||
atomNodeGypPath = process.env.ATOM_NODE_GYP_PATH or require.resolve('node-gyp/bin/node-gyp') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit weird to me. I poked around a bit trying to use @npm.config.get('node-gyp')
but that's pointed to the node_modules/.bin/
symlink, not the node-gyp.js
script, so @fork
wasn't happy with it, and I didn't want to swap it out for a @spawn
because it looked important to preserve the node executable.
@BinaryMuse I'd appreciate a look-over when you get the chance 😁 |
Requirements
Description of the Change
Currently, Atom Beta is unable to install packages that directly or transitively include a native dependency, because the Makefile that
node-gyp
generate includes whitespace in a dependency list, causing the following failure:This PR works around the issue by providing a custom Makefile generator that escapes these paths.
Passing the custom generator to gyp is a bit... involved.
node-gyp
hardcodes an-fmake
argument to the gyp invocation and doesn't provide a mechanism to pass a custom--format
. To work around this, I've introduced apython-interceptor.sh
script that's passed to npm asPYTHON
, which node-gyp will exec to invoke gyp.python-interceptor.sh
directly execs the real Python binary preserving all arguments as-is, except when it's running the gyp entrypoint, in which case it detects and removes any-f
or--format
arguments and replaces them with a--format
argument that invokes the custom generator.Because
gyp
assumes that paths don't contain a-
character, the custom generator is provided togyp
by adding its containing directory toPYTHONPATH
and specifying the generator as<modulename>.py
. That triggersgyp
's module file importing logic to import the correct module name, but by manipulating thePYTHONPATH
ourselves we sidestep the-
split earlier.Alternate Designs
The best option here is to fix the problem at the source. It's a one-line fix upstream in node-gyp. I do intend to file a PR there, but I'd rather have this a temporary fix we can 🚢 independently until that works its way through the pipeline of getting feedback and getting merged 👉 being released in node-gyp 👉 being released in npm.
Benefits
The immediate benefit is that
apm-beta install
orupgrade
commands will succeed for packages that include native dependencies, from the commandline or within the Atom UI.It requires no action on the part of either npm package authors or
apm
users for builds to succeed.Possible Drawbacks
The
python-interceptor.sh
script relies on the presence of a/bin/bash
binary that understands arrays. There may be Linux distros where that is not true.Applicable Issues