diff --git a/deps/npm/node_modules/node-gyp/lib/configure.js b/deps/npm/node_modules/node-gyp/lib/configure.js index 009935202af9..705b9f824727 100644 --- a/deps/npm/node_modules/node-gyp/lib/configure.js +++ b/deps/npm/node_modules/node-gyp/lib/configure.js @@ -133,7 +133,7 @@ function configure (gyp, argv, callback) { nodeDir = gyp.opts.nodedir.replace(/^~/, osenv.home()) log.verbose('get node dir', 'compiling against specified --nodedir dev files: %s', nodeDir) - createBuildDir() + copyCommonGypi() } else { // if no --nodedir specified, ensure node dependencies are installed @@ -156,11 +156,84 @@ function configure (gyp, argv, callback) { if (err) return callback(err) log.verbose('get node dir', 'target node version installed:', release.versionDir) nodeDir = path.resolve(gyp.devDir, release.versionDir) - createBuildDir() + copyCommonGypi() }) } } + function findNodeRootDirectory() { + // Have a look to see what is above us, to try and work out where we are + npm_parent_directory = path.join(__dirname, '..', '..','..','..') + log.verbose('node-gyp root', 'npm_parent_directory is ' + path.basename(npm_parent_directory)) + node_root_dir = "" + + log.verbose('node-gyp root','Finding node root directory') + if (path.basename(npm_parent_directory) == 'lib') { + // We are in a node install directory + node_root_dir = path.join(npm_parent_directory, '..', '..') + log.verbose('node-gyp root', 'in install directory, root = ' + node_root_dir) + } else if (path.basename(npm_parent_directory) == 'node_modules') { + // We are in a node build directory, where npm lives under lib/ + node_root_dir = path.join(npm_parent_directory, '..', '..', 'include', 'node') + log.verbose('node-gyp root', 'in build directory, root = ' + node_root_dir) + } else { + // We don't know where we are, try working it out from the location + // of the node binary + var node_dir = path.dirname(process.execPath) + var directory_up = path.basename(node_dir) + if (directory_up == 'bin') { + node_root_dir = path.join(node_dir, '..') + } else if (directory_up == 'Release' || directory_up == 'Debug') { + // If we are a recently built node, and the directory structure is that of a repository + // If we are on Windows then we only need to go one level up, everything else, two + if (process.platform == 'win32') { + node_root_dir = path.join(node_dir, '..') + } else { + node_root_dir = path.join(node_dir, '..', '..') + } + } + // Else return the default blank, "". + } + return node_root_dir + } + + function copyCommonGypi () { + // Only copy it if we haven't specified a --nodedir option + // (--nodedir implies you have everything in the correct place after a build) + if (!gyp.opts.nodedir) { + node_root_dir = findNodeRootDirectory() + var nodeCommonGypiPath = path.resolve(nodeDir, 'include','node','common.gypi') + + var possibleLocations = [path.resolve(node_root_dir, 'common.gypi'), + path.resolve(node_root_dir, 'include','node','common.gypi')] + + // Find which of these files exists + var buildNodeCommonGypiPath = null + for (var i = 0; i < possibleLocations.length; i++) { + log.verbose('node-gyp configure common.gypi','Checking: '+possibleLocations[i]) + if (fs.existsSync(possibleLocations[i])) { + buildNodeCommonGypiPath = possibleLocations[i] + break + } + } + + // Copy the one we found, if we found one + if (buildNodeCommonGypiPath != null) { + var rs = fs.createReadStream(buildNodeCommonGypiPath) + , ws = fs.createWriteStream(nodeCommonGypiPath) + log.info('node-gyp configure common.gypi','copying "common.gypi" from ' + buildNodeCommonGypiPath + ' to ' + nodeCommonGypiPath) + rs.pipe(ws) + rs.on('error', callback) + ws.on('error', callback) + rs.on('end', createBuildDir) + } else { + log.warn('node-gyp configure common.gypi', 'Unable to find a version of common.gypi to copy to the node headers location, your build may not work as expected') + } + } else { + createBuildDir() + } + } + function createBuildDir () { log.verbose('build dir', 'attempting to create "build" dir: %s', buildDir) mkdirp(buildDir, function (err, isNew) {