Skip to content

Commit

Permalink
Problem: gyp dependencies don't work properly
Browse files Browse the repository at this point in the history
This is due to a bug in gyp that I've documented and reported at
https://bugs.chromium.org/p/gyp/issues/detail?id=508.

My test case is a bindings.gyp that has a dependency on another
gyp file in a different directory. The problem I was seeing was
makefiles being generated in what looked like random places up
and down the file tree.

It turns out that gyp is trying to use relative directories while
at the same time letting the user switch directories using the
--generator-output option.

It took a while but I got a minimal reproducible test case that I
could report to the gyp project. However, this could take forever
to be merged and we have to deal with widespread existing gyps in
the world.

So...

Solution: provide a workaround in node-gyp.

The simplest workaround is to not use --generator-output. This has
the disadvantage of creating gyp's makefiles in the main project
directory. That's manageable with .gitignores. It is how most gyp
projects work. It has the big advantage of not scattering its
makefiles around the file system.

I've called this option `-mklocal` and documented it. I've no idea
how to add it to the regression test.

Thanks for taking this patch into consideration.
  • Loading branch information
hintjens committed Feb 14, 2016
1 parent b762fd2 commit 86ddbca
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ Command options
| `--silent`, `--loglevel=silent` | Don't log anything
| `--debug` | Make Debug build (default=Release)
| `--release`, `--no-debug` | Make Release build
| `--mklocal` | Generate Makefiles in current directory

Notes:

* The `--mklocal` option generates makefiles in the current directory, rather than in `build/`. This works around [issue #508 in gyp](https://bugs.chromium.org/p/gyp/issues/detail?id=508). If your binding.gyp has dependencies on other gyp files, use `--mklocal` to avoid gyp scattering its makefiles around your file system. Specify this option for both `configure` and `build` commands.

License
-------
Expand Down
8 changes: 5 additions & 3 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,11 @@ function build (gyp, argv, callback) {
}
} else {
argv.push('BUILDTYPE=' + buildType)
// Invoke the Makefile in the 'build' dir.
argv.push('-C')
argv.push('build')
if (!gyp.opts.mklocal) {
// Invoke the Makefile in the 'build' dir.
argv.push('-C')
argv.push('build')
}
if (jobs) {
var j = parseInt(jobs, 10)
if (!isNaN(j) && j > 0) {
Expand Down
11 changes: 6 additions & 5 deletions lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,12 @@ function configure (gyp, argv, callback) {
argv.push('--depth=.')
argv.push('--no-parallel')

// tell gyp to write the Makefile/Solution files into output_dir
argv.push('--generator-output', output_dir)

// tell make to write its output into the same dir
argv.push('-Goutput_dir=.')
if (!gyp.opts.mklocal) {
// tell gyp to write the Makefile/Solution files into output_dir
argv.push('--generator-output=' + output_dir)
// tell make to write its output into the same dir
argv.push('-Goutput_dir=.')
}

// enforce use of the "binding.gyp" file
argv.unshift('binding.gyp')
Expand Down
1 change: 1 addition & 0 deletions lib/node-gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ proto.configDefs = {
, 'tarball': String // 'install'
, jobs: String // 'build'
, thin: String // 'configure'
, mklocal: Boolean // 'configure', 'build'
}

/**
Expand Down

0 comments on commit 86ddbca

Please sign in to comment.