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
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
1 change: 1 addition & 0 deletions bin/node-gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var path = require('path')
var prog = gyp()
var completed = false
prog.parseArgv(process.argv)
prog.buildDir = prog.opts['build-dir'] || 'build'
prog.devDir = prog.opts.devdir

var homeDir = osenv.home()
Expand Down
6 changes: 3 additions & 3 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function build (gyp, argv, callback) {
var release = processRelease(argv, gyp, process.version, process.release)
, makeCommand = gyp.opts.make || process.env.MAKE || platformMake
, command = win ? 'msbuild' : makeCommand
, buildDir = path.resolve('build')
, buildDir = path.resolve(gyp.buildDir)
, configPath = path.resolve(buildDir, 'config.gypi')
, jobs = gyp.opts.jobs || process.env.JOBS
, buildType
Expand Down Expand Up @@ -86,7 +86,7 @@ function build (gyp, argv, callback) {
*/

function findSolutionFile () {
glob('build/*.sln', function (err, files) {
glob(buildDir + '/*.sln', function (err, files) {
if (err) return callback(err)
if (files.length === 0) {
return callback(new Error('Could not find *.sln file. Did you run "configure"?'))
Expand Down Expand Up @@ -240,7 +240,7 @@ function build (gyp, argv, callback) {
argv.push('BUILDTYPE=' + buildType)
// Invoke the Makefile in the 'build' dir.
argv.push('-C')
argv.push('build')
argv.push(buildDir)
if (jobs) {
var j = parseInt(jobs, 10)
if (!isNaN(j) && j > 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var log = require('npmlog')
function clean (gyp, argv, callback) {

// Remove the 'build' dir
var buildDir = 'build'
var buildDir = gyp.buildDir

log.verbose('clean', 'removing "%s" directory', buildDir)
rm(buildDir, callback)
Expand Down
9 changes: 5 additions & 4 deletions lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports.usage = 'Generates ' + (win ? 'MSVC project files' : 'a Makefile') + ' f
function configure (gyp, argv, callback) {

var python = gyp.opts.python || process.env.PYTHON || 'python2'
, buildDir = path.resolve('build')
, buildDir = path.resolve(gyp.buildDir)
, configNames = [ 'config.gypi', 'common.gypi' ]
, configs = []
, nodeDir
Expand Down Expand Up @@ -154,12 +154,13 @@ function configure (gyp, argv, callback) {
return v
}

log.silly('build/' + configFilename, config)
log.silly(gyp.buildDir + '/' + configFilename, config)

// 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)
configs.push(configPath)
fs.writeFile(configPath, [prefix, json, ''].join('\n'), findConfigs)
}
Expand Down Expand Up @@ -254,7 +255,7 @@ function configure (gyp, argv, callback) {
if (err)
common_gypi = path.resolve(nodeDir, 'common.gypi')

var output_dir = 'build'
var output_dir = gyp.buildDir
if (win) {
// Windows expects an absolute path
output_dir = buildDir
Expand Down
2 changes: 2 additions & 0 deletions lib/node-gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function Gyp () {

this.devDir = ''
this.commands = {}
this.buildDir = ''

commands.forEach(function (command) {
self.commands[command] = function (argv, callback) {
Expand Down Expand Up @@ -89,6 +90,7 @@ proto.configDefs = {
, 'tarball': String // 'install'
, jobs: String // 'build'
, thin: String // 'configure'
, 'build-dir': String // everywhere
}

/**
Expand Down
50 changes: 49 additions & 1 deletion test/test-addon.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
'use strict'

var test = require('tape')
var execFile = require('child_process').execFile
var childProcess = require('child_process')
var execFile = childProcess.execFile
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)
Expand All @@ -26,3 +42,35 @@ test('build simple addon', function (t) {
proc.stdout.setEncoding('utf-8')
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']
var proc = execFile(process.execPath, cmd, 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(path.join(addonPath, 'foo/Release/hello.node'))
t.strictEqual(binding.hello(), 'world')

// Cleanup
execFile(process.execPath, [nodeGyp, '--build-dir=foo', 'clean'], t.end)
} catch (error) {
t.error(error, 'load module')
}
})

proc.stdout.setEncoding('utf-8')
proc.stderr.setEncoding('utf-8')
})

test('build with different build dir - teardown',
cleanup(path.join(addonPath, 'foo')))