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

Allow build directory to be changed. #919

Closed
wants to merge 1 commit into from

Conversation

peterbraden
Copy link

Change with NODE_GYP_BUILD_DIR environment variable

Fixes #263

@bnoordhuis
Copy link
Member

It should be a switch, like --builddir. The way node-gyp works, it can then also be configured by setting npm_config_builddir in the environment. See #916 for an example.

@guymguym
Copy link
Contributor

guymguym commented Aug 8, 2016

Planning to merge? Would be great to allow it for tensorflow.

lib/configure.js Outdated

// now write out the config.gypi file to the build/ dir
var prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step'
, json = JSON.stringify(config, boolsToString, 2)
log.verbose('build/' + configFilename, 'writing out config file: %s', configPath)
log.verbose(gyp.buildDir + '/' + configFilename, 'writing out config file: %s', configPath)
Copy link
Member

Choose a reason for hiding this comment

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

Can you wrap this line at 80 columns? I'd break at the the comma, then line up the second argument with the first one.

@bnoordhuis
Copy link
Member

@peterbraden Can you add a regression test to test/test-addon.js?

@peterbraden
Copy link
Author

added a very basic test.

t.strictEqual(binding.hello(), 'world')

// Cleanup
exec('rm -rf foo', t.end)
Copy link
Member

Choose a reason for hiding this comment

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

This won't work on Windows. Can you run node-gyp --build_dir=foo clean?

Naming bikeshed: what about calling it --build-dir? That's more in line with --dist-url. (OTOH there's --msvs_version but that mimics the gyp variable.)

@bnoordhuis
Copy link
Member

@peterbraden Can you rebase and squash? Thanks.

peterbraden added a commit to peterbraden/node-gyp that referenced this pull request Oct 24, 2016
Change with `--build-dir` parameter.

ie:
```
node-gyp --build-dir=foo rebuild
```

PR nodejs#919
Fixes nodejs#263
@peterbraden
Copy link
Author

Done

@bnoordhuis bnoordhuis mentioned this pull request Oct 27, 2016
@rvagg
Copy link
Member

rvagg commented Nov 8, 2016

Your test doesn't work, for two reasons: require cache saving "hello_world" and hello.js using the bindings module to load from the existing build directory. So here's a patch to fix your test:

diff --git a/test/test-addon.js b/test/test-addon.js
index 4b8bc5e..2816cd1 100644
--- a/test/test-addon.js
+++ b/test/test-addon.js
@@ -7,6 +7,20 @@ var exec = childProcess.exec
 var path = require('path')
 var addonPath = path.resolve(__dirname, 'node_modules', 'hello_world')
 var nodeGyp = path.resolve(__dirname, '..', 'bin', 'node-gyp.js')
+var rimraf = require('rimraf')
+
+function cleanup (dir) {
+  return function teardown (t) {
+    Object.keys(require.cache)
+      .forEach(function (d) {
+        if (d.indexOf(addonPath) == 0)
+          delete require.cache[d]
+      })
+    rimraf(dir, t.end)
+  }
+}
+
+test('build simple addon - setup', cleanup(path.join(addonPath, 'build')))

 test('build simple addon', function (t) {
   t.plan(3)
@@ -29,6 +43,10 @@ test('build simple addon', function (t) {
   proc.stderr.setEncoding('utf-8')
 })

+test('build simple addon - teardown', cleanup(path.join(addonPath, 'build')))
+
+test('build with different build dir - setup', cleanup(path.join(addonPath, 'foo')))
+
 test('build with different build dir', function(t) {
   var cmd = [nodeGyp, 'rebuild', '-C',
               addonPath, '--loglevel=verbose', '--build-dir=foo']
@@ -39,7 +57,7 @@ test('build with different build dir', function(t) {
     t.strictEqual(lastLine, 'gyp info ok', 'should end in ok')

     try {
-      var binding = require('hello_world')
+      var binding = require(path.join(addonPath, 'foo/Release/hello.node'))
       t.strictEqual(binding.hello(), 'world')

       // Cleanup
@@ -52,3 +70,5 @@ test('build with different build dir', function(t) {
   proc.stdout.setEncoding('utf-8')
   proc.stderr.setEncoding('utf-8')
 })
+
+test('build with different build dir - teardown', cleanup(path.join(addonPath, 'foo')))

@Fishrock123
Copy link
Contributor

ping @peterbraden

peterbraden added a commit to peterbraden/node-gyp that referenced this pull request Nov 23, 2016
Change with `--build-dir` parameter.

ie:
```
node-gyp --build-dir=foo rebuild
```

PR nodejs#919
Fixes nodejs#263
peterbraden added a commit to peterbraden/node-gyp that referenced this pull request Nov 23, 2016
Change with `--build-dir` parameter.

ie:
```
node-gyp --build-dir=foo rebuild
```

PR nodejs#919
Fixes nodejs#263
@peterbraden
Copy link
Author

Sorry, been busy with a new job. Done now, and squashed and rebased.

Thanks!

t.strictEqual(binding.hello(), 'world')

// Cleanup
exec('node-gyp --build-dir=foo clean', t.end)
Copy link
Member

Choose a reason for hiding this comment

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

Can you use execFile(process.execPath, [nodeGyp, ...]) here? Calling out to node-gyp risks picking up the version that is on the path, not what's under test.

Aside: I know they're Rod's work but can you wrap lines at 80 columns? Thanks. :-)

Change with `--build-dir` parameter.

ie:
```
node-gyp --build-dir=foo rebuild
```

PR nodejs#919
Fixes nodejs#263
@peterbraden
Copy link
Author

Updated, squashed

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

@Fishrock123
Copy link
Contributor

CI failed on windows, @bnoordhuis could you take a look?

@richardlau
Copy link
Member

Test failures on Windows are because the newly introduced cleanup() function in the tests is trying to remove a currently loaded .node file. Even if the module is deleted from require.cache the .node is not unloaded (Is it even possible to unload a required .node in Node.js?).

@bnoordhuis
Copy link
Member

(Is it even possible to unload a required .node in Node.js?)

No.

@richardlau
Copy link
Member

I don't think clearing entries from require.cache is needed, because the second require() call that was introduced to the test is requiring hello.node from a different location (path.join(addonPath, 'foo/Release/hello.node')) than hello.node that is required from require('hello_world') (via the bindings module) so would end up as a separate entry in the cache.

If the fear is contamination of the second test from the first, then perhaps the new test could be in a separate file? Or does tape run all tests in the same process?

@bnoordhuis
Copy link
Member

@peterbraden Are you still interested in pursuing this? From #919 (comment) it sounds like it's almost there, it just needs one or two small fix-ups.

If the fear is contamination of the second test from the first, then perhaps the new test could be in a separate file? Or does tape run all tests in the same process?

I think tape uses a process-per-file model so that sounds like a good idea.

@peterbraden
Copy link
Author

Sure, let me try when I have some free time, maybe this weekend.

@bnoordhuis
Copy link
Member

I found out the hard way today that tape runs all tests in the same process. I've filed #1123.

@599316527
Copy link

Has this feature been merged into master? I really need it.

@jlipps
Copy link

jlipps commented Jun 1, 2019

@peterbraden I'd still be interested in this patch if you want to resurrect it :-)

@rvagg
Copy link
Member

rvagg commented Jun 21, 2019

if @peterbraden or someone else wants to pick this up, please either rebase this or take the code and open a new PR against the current master
test failures because of the way tape works should be fixed once we migrate to tap which I hope we can achieve soon.

@peterbraden
Copy link
Author

I don't have time for this any more, hopefully someone else can take this on.

@bnoordhuis
Copy link
Member

It's with slightly sad eyes that I'm closing this out. I just closed out #263 after no one stepped forward. Thanks anyway, @peterbraden!

@bnoordhuis bnoordhuis closed this May 6, 2020
@ghost
Copy link

ghost commented Aug 6, 2021

I'm interested in helping to get this issue over the line, is the "tap/tape" thing mentioned above still an issue? What remains to be done here.

@cclauss
Copy link
Contributor

cclauss commented Aug 6, 2021

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.

Configurable build dir
9 participants