Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gyp: Export LD_LIBRARY_PATH quoted in case $(builddir) contains spaces #1277

Closed
wants to merge 8 commits into from

Conversation

melloc
Copy link

@melloc melloc commented Aug 25, 2017

Checklist
  • npm install && npm test passes
  • tests are included
  • commit message follows commit guidelines
Description of change

This change will make sure that the path to the build directory gets properly quoted and escaped when running actions.

isaacs and others added 8 commits June 6, 2017 06:56
Tar version 3 performs better and is more well tested than its
predecessor.  npm will be using this in the near future, so there is no
benefit in shipping a node-gyp that uses the slower and less reliable
fstream-based tar.

This drops support for node 0.x, and thus should be considered a
breaking semver-major change.

PR-URL: nodejs#1212
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
* dropping support for node < 4
* signal the CI not to test node < 4
If you're providing a path to a header tarball to install, you probably
want it to always be re-installed.

PR-URL: nodejs#1220
Fixes: nodejs#1216
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Refael Ackermann <refack@gmail.com>
* test: build simple addon in path with non-ascii characters
* test: add test-charmap.py

PR-URL: nodejs#1203
Reviewed-By: Refael Ackermann <refack@gmail.com>
Enable linking to the platform specific installation instructions

PR-URL: nodejs#1225
Reviewed-By: Refael Ackermann <refack@gmail.com>
Lifted verbatim from
https://github.com/nodejs/node/blob/master/CONTRIBUTING.md
then `s/Node.js/node-gyp/`.

PR-URL: nodejs#1229
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Give users reporting bugs a clearer idea of the info that will be
helpful when reporting issues.

PR-URL: nodejs#1228
Refs: https://github.com/nodejs/node/tree/master/.github
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
When actions are run, they're preceded by an update to the
LD_LIBRARY_PATH environment variable. If $(builddir) includes
any special shell characters, then the action will fail to run
and the build will fail.
@refack
Copy link
Contributor

refack commented Aug 27, 2017

Hello @melloc, thank you for the contribution.
This LGTM (apart from a few style nits), and I'm running node-gyp's CI on this: https://ci.nodejs.org/view/All/job/nodegyp-test-pull-request/34/
But what I would ask you to do, if you are so inclined, is it to submit this upstream to: https://gyp.gsrc.io/docs/Hacking.md
(If you rather not deal with the hassle, please let me know, and I'll submit it on your behalf.)

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 nits

@@ -916,11 +916,12 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
# libraries, but until everything is made cross-compile safe, also use
# target libraries.
# TODO(piman): when everything is cross-compile safe, remove lib.target
self.WriteLn('cmd_%s = LD_LIBRARY_PATH=$(builddir)/lib.host:'
'$(builddir)/lib.target:$$LD_LIBRARY_PATH; '
subst_builddir = '$(subst \',\'\\\'\',$(builddir))'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd rather you use the " string delimiter and the r prefix so you get:

     subst_builddir = r"$(subst ', '\'', $(builddir))"

Also IMHO the arg to self.WriteLn should be constructed before the call

     action_cmd = "..." \
       "..." % (...)
     self.WriteLn(action_cmd)

@refack
Copy link
Contributor

refack commented Aug 27, 2017

Seems like the new test fails on Windows:

module.js:487
    throw err;
    ^

Error: Cannot find module 'name's (weird)'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at [eval]:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at Object.runInThisContext (vm.js:116:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:569:30)
    at evalScript (bootstrap_node.js:432:27)
child_process.js:591
    throw err;
    ^

Error: Command failed: node -e require('name\'s (weird)')
module.js:487
    throw err;
    ^

Error: Cannot find module 'name's (weird)'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at [eval]:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at Object.runInThisContext (vm.js:116:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:569:30)
    at evalScript (bootstrap_node.js:432:27)


    at checkExecSyncError (child_process.js:568:13)
    at execFileSync (child_process.js:588:13)
    at runSpacedName (c:\workspace\nodegyp-test-commit\nodes\win2012r2\test\test-actions.js:15:10)
    at c:\workspace\nodegyp-test-commit\nodes\win2012r2\test\test-actions.js:29:19
    at ChildProcess.exithandler (child_process.js:244:7)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at maybeClose (internal/child_process.js:887:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5)

var nodeGyp = path.resolve(__dirname, '..', 'bin', 'node-gyp.js')

function runSpacedName() {
var testCode = "require('name\\'s (weird)')"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't put a \ in a Windows path. But you can put an unescaped '.
You could try using require("${addonPath}") but YMMV

var lastLine = logLines[logLines.length-1]
t.strictEqual(err, null)
t.strictEqual(lastLine, 'gyp info ok', 'should end in ok')
t.strictEqual(runSpacedName().trim(), 'world')
Copy link
Contributor

@refack refack Aug 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should lower the .trim() into runSpacedName

var cmd = [ nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose' ]

var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) {
var logLines = stderr.toString().trim().split(/\r?\n/)
Copy link
Contributor

@refack refack Aug 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  const lastLine = stderr.toString().trim().split(os.EOL).pop();

var lastLine = logLines[logLines.length-1]
t.strictEqual(err, null)
t.strictEqual(lastLine, 'gyp info ok', 'should end in ok')
t.strictEqual(runSpacedName().trim(), 'world')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should put a comment explaining where "world" comes from.

@melloc
Copy link
Author

melloc commented Aug 30, 2017

@refack Thanks for the feedback. I suspect the Windows tests are failing because the shell script is failing and not creating hello.js, although I'm not sure why this isn't causing node-gyp to exit non-zero. I'll modify it to run a batch script on Windows, and the shell script on everything else, and see if I can find a Windows environment to test it in.

Once I have that I'll look into what it would take to get it submitted upstream, too.

@rvagg
Copy link
Member

rvagg commented Jun 21, 2019

not sure if this is still needed, if so and it belongs here please open a fresh PR for it, otherwise maybe https://github.com/refack/GYP is the right place for it

@rvagg rvagg closed this Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.