configure: add support for "config.gypi" and "commong.gypi" files

When present alongside the "binding.gyp" file. This gives addons a chance to
overwrite default variables specified in the gyp files of the native addon's
gyp dependencies.
This commit is contained in:
Nathan Rajlich 2012-11-13 18:41:25 -08:00
parent bae7580ff8
commit 2e5e6a66a8

View file

@ -29,7 +29,8 @@ function configure (gyp, argv, callback) {
, hasVC2012Express = false , hasVC2012Express = false
, hasWin71SDK = false , hasWin71SDK = false
, hasWin8SDK = false , hasWin8SDK = false
, configPath , configNames = [ 'config.gypi', 'common.gypi' ]
, configs = []
, nodeDir , nodeDir
@ -241,9 +242,9 @@ function configure (gyp, argv, callback) {
if (err) return callback(err) if (err) return callback(err)
var configFilename = 'config.gypi' var configFilename = 'config.gypi'
configPath = path.resolve(buildDir, configFilename) var configPath = path.resolve(buildDir, configFilename)
log.verbose(configFilename, 'creating config file') log.verbose('build/' + configFilename, 'creating config file')
var config = process.config || {} var config = process.config || {}
, defaults = config.target_defaults , defaults = config.target_defaults
@ -311,13 +312,34 @@ function configure (gyp, argv, callback) {
return v return v
} }
log.silly(configFilename, config) log.silly('build/' + configFilename, config)
// now write out the config.gypi file to the build/ dir // 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' var prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step'
, json = JSON.stringify(config, boolsToString, 2) , json = JSON.stringify(config, boolsToString, 2)
log.verbose(configFilename, 'writing out config file: %s', configPath) log.verbose('build/' + configFilename, 'writing out config file: %s', configPath)
fs.writeFile(configPath, [prefix, json, ''].join('\n'), runGyp) configs.push(configPath)
fs.writeFile(configPath, [prefix, json, ''].join('\n'), findConfigs)
}
function findConfigs (err) {
if (err) return callback(err)
var name = configNames.shift();
if (!name) return runGyp();
var fullPath = path.resolve(name);
log.verbose(name, 'checking for gypi file: %s', fullPath);
fs.stat(fullPath, function (err, stat) {
if (err) {
if (err.code == 'ENOENT') {
findConfigs() // check next gypi filename
} else {
callback(err)
}
} else {
configs.push(fullPath);
findConfigs()
}
});
} }
function runGyp (err) { function runGyp (err) {
@ -349,8 +371,10 @@ function configure (gyp, argv, callback) {
} }
} }
// include the "config.gypi" file that was generated // include all the ".gypi" files that were found
argv.push('-I', configPath) configs.forEach(function (config) {
argv.push('-I', config)
})
// this logic ported from the old `gyp_addon` python file // this logic ported from the old `gyp_addon` python file
var gyp_script = path.resolve(nodeDir, 'tools', 'gyp', 'gyp') var gyp_script = path.resolve(nodeDir, 'tools', 'gyp', 'gyp')