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

Prefix build targets with /t: on Windows #1164

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
gyp/test
node_modules
node_modules/*
!test/node_modules/hello_world
build
test/.node-gyp
4 changes: 4 additions & 0 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function build (gyp, argv, callback) {
platformMake = 'gmake'
} else if (process.platform.indexOf('bsd') !== -1) {
platformMake = 'gmake'
} else if (win && argv.length > 0) {
argv = argv.map(function(target) {
return '/t:' + target
})
}

var release = processRelease(argv, gyp, process.version, process.release)
Expand Down
6 changes: 6 additions & 0 deletions test/node_modules/hello_world/binding.gyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/node_modules/hello_world/world.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/node_modules/hello_world/world.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 23 additions & 7 deletions test/test-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,38 @@ var addonPath = path.resolve(__dirname, 'node_modules', 'hello_world')
var nodeGyp = path.resolve(__dirname, '..', 'bin', 'node-gyp.js')

test('build simple addon', function (t) {
t.plan(3)
t.plan(4)

// Set the loglevel otherwise the output disappears when run via 'npm test'
var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) {
exec(t, ['clean', 'rebuild'], [], function (err, stdout, stderr) {
var logLines = stderr.toString().trim().split(/\r?\n/)
var lastLine = logLines[logLines.length-1]
t.strictEqual(err, null)
t.strictEqual(lastLine, 'gyp info ok', 'should end in ok')
try {
var binding = require('hello_world')
t.strictEqual(binding.hello(), 'world')
var hello = require('hello_world/hello')
t.strictEqual(hello.hello(), 'world')
} catch (error) {
t.error(error, 'load module')
}

try {
var world = require('hello_world/world')
t.strictEqual(world.world(), 'hello')
} catch (error) {
t.error(error, 'load module')
}
})
})

function exec(t, cmd, args, cb) {
// Set the loglevel otherwise the output disappears when run via 'npm test'
var toExec = [nodeGyp]
.concat(cmd)
.concat(['-C', addonPath, '--loglevel=verbose'])
.concat(args)

t.comment(toExec.join(' '))
var proc = execFile(process.execPath, toExec, cb)
proc.stdout.setEncoding('utf-8')
proc.stderr.setEncoding('utf-8')
})
}
48 changes: 48 additions & 0 deletions test/test-specific-addon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

var test = require('tape')
var execFile = require('child_process').execFile
var path = require('path')
var addonPath = path.resolve(__dirname, 'node_modules', 'hello_world')
var nodeGyp = path.resolve(__dirname, '..', 'bin', 'node-gyp.js')

test('build specific addon', function (t) {
t.plan(5)

exec(t, ['clean', 'configure'], [], function (err) {
t.error(err, 'clean build')

exec(t, ['build'], ['hello'], function (err, stdout, stderr) {
var logLines = stderr.toString().trim().split(/\r?\n/)
var lastLine = logLines[logLines.length-1]
t.strictEqual(err, null)
t.strictEqual(lastLine, 'gyp info ok', 'should end in ok')
try {
var hello = require('hello_world/hello')
t.strictEqual(hello.hello(), 'world')
} catch (error) {
t.error(error, 'load module')
}

try {
var world = require('hello_world/world')
t.fail('should not have loaded unbuilt module')
} catch (e) {
t.ok(/Could not locate the bindings file/.test(e), 'should not build world')
}
})
})
})

function exec(t, cmd, args, cb) {
// Set the loglevel otherwise the output disappears when run via 'npm test'
var toExec = [nodeGyp]
.concat(cmd)
.concat(['-C', addonPath, '--loglevel=verbose'])
.concat(args)

t.comment(toExec.join(' '))
var proc = execFile(process.execPath, toExec, cb)
proc.stdout.setEncoding('utf-8')
proc.stderr.setEncoding('utf-8')
}