node-gyp
Advanced tools
Comparing version 0.3.9 to 0.3.10
@@ -12,2 +12,3 @@ | ||
, which = require('which') | ||
, mkdirp = require('./util/mkdirp') | ||
, asyncEmit = require('./util/asyncEmit') | ||
@@ -25,3 +26,6 @@ , createHook = require('./util/hook') | ||
, configPath = path.resolve(buildDir, 'config.gypi') | ||
, buildType | ||
, config | ||
, arch | ||
, version | ||
, emitter | ||
@@ -50,2 +54,19 @@ | ||
config = JSON.parse(data.replace(/\#.+\n/, '')) | ||
// get the 'arch', 'buildType', and 'version' vars from the config | ||
buildType = config.target_defaults.default_configuration | ||
arch = config.variables.target_arch | ||
version = config.variables.target_version | ||
if ('debug' in gyp.opts) { | ||
buildType = gyp.opts.debug ? 'Debug' : 'Release' | ||
} | ||
if (!buildType) { | ||
buildType = 'Release' | ||
} | ||
gyp.verbose('build type:', buildType) | ||
gyp.verbose('architecture:', arch) | ||
gyp.verbose('node version:', version) | ||
if (win) { | ||
@@ -60,3 +81,3 @@ findSolutionFile() | ||
/** | ||
* On Windows, find first build/*.sln file. | ||
* On Windows, find the first build/*.sln file. | ||
*/ | ||
@@ -76,2 +97,6 @@ | ||
/** | ||
* Uses node-which to locate the msbuild / make executable. | ||
*/ | ||
function doWhich () { | ||
@@ -91,3 +116,3 @@ // First make sure we have the build command in the PATH | ||
gyp.verbose('`which` succeeded for `' + command + '`', execPath) | ||
build() | ||
copyNodeLib() | ||
}) | ||
@@ -118,3 +143,3 @@ } | ||
command = msbuild | ||
build() | ||
copyNodeLib() | ||
}) | ||
@@ -124,13 +149,32 @@ } | ||
/** | ||
* Copies the node.lib file for the current target architecture into the | ||
* current proper dev dir location. | ||
*/ | ||
function copyNodeLib () { | ||
if (!win) return doBuild() | ||
var devDir = path.resolve(gyp.devDir, version) | ||
, buildDir = path.resolve(devDir, buildType) | ||
, archNodeLibPath = path.resolve(devDir, arch, 'node.lib') | ||
, buildNodeLibPath = path.resolve(buildDir, 'node.lib') | ||
mkdirp(buildDir, function (err, isNew) { | ||
if (err) return callback(err) | ||
gyp.verbose('"' + buildType + '" dir needed to be created?', isNew) | ||
var rs = fs.createReadStream(archNodeLibPath) | ||
, ws = fs.createWriteStream(buildNodeLibPath) | ||
rs.pipe(ws) | ||
rs.on('error', callback) | ||
ws.on('error', callback) | ||
rs.on('end', doBuild) | ||
}) | ||
} | ||
/** | ||
* Actually spawn the process and compile the module. | ||
*/ | ||
function build () { | ||
var buildType = config.target_defaults.default_configuration | ||
, platform = config.variables.target_arch == 'x64' ? '64' : '32' | ||
function doBuild () { | ||
if (gyp.opts.debug) { | ||
buildType = 'Debug' | ||
} | ||
// Enable Verbose build | ||
@@ -151,3 +195,4 @@ if (!win && gyp.opts.verbose) { | ||
if (win) { | ||
argv.push('/p:Configuration=' + buildType + ';Platform=Win' + platform) | ||
var p = arch === 'x64' ? 'x64' : 'Win32' | ||
argv.push('/p:Configuration=' + buildType + ';Platform=' + p) | ||
} else { | ||
@@ -154,0 +199,0 @@ argv.push('BUILDTYPE=' + buildType) |
@@ -22,3 +22,3 @@ | ||
var python = gyp.opts.python || 'python' | ||
var python = process.env.PYTHON || gyp.opts.python || 'python' | ||
, buildDir = path.resolve('build') | ||
@@ -50,3 +50,3 @@ , configPath | ||
gyp.verbose('`which` succeeded for `' + python + '`', execPath) | ||
getVersion() | ||
getTargetVersion() | ||
}) | ||
@@ -59,3 +59,3 @@ } | ||
gyp.verbose('could not find "' + python + '". guessing location') | ||
var rootDir = process.env.HOMEDIR || process.env.SystemDrive || 'C:\\' | ||
var rootDir = process.env.HOMEDRIVE || process.env.SystemDrive || 'C:\\' | ||
if (rootDir[rootDir.length - 1] !== '\\') { | ||
@@ -76,3 +76,3 @@ rootDir += '\\' | ||
python = pythonPath | ||
getVersion() | ||
getTargetVersion() | ||
}) | ||
@@ -82,6 +82,10 @@ } | ||
function failNoPython () { | ||
callback(new Error('Python does not seem to be installed')) | ||
callback(new Error('Can\'t find Python, you can set the PYTHON env variable.')) | ||
} | ||
function getVersion () { | ||
function getTargetVersion () { | ||
// 'python' should be set by now | ||
process.env.PYTHON = python | ||
if (gyp.opts.target) { | ||
@@ -122,19 +126,61 @@ // if --target was given, then ensure that version is installed | ||
var config = {} | ||
configPath = path.resolve(buildDir, 'config.gypi') | ||
config.target_defaults = { | ||
cflags: [] | ||
, default_configuration: gyp.opts.debug ? 'Debug' : 'Release' | ||
, defines: [] | ||
, include_dirs: [] | ||
, libraries: [] | ||
var config = process.config || {} | ||
, defaults = config.target_defaults | ||
, variables = config.variables | ||
if (!defaults) { | ||
defaults = config.target_defaults = {} | ||
} | ||
if (!variables) { | ||
variables = config.variables = {} | ||
} | ||
if (!defaults.cflags) { | ||
defaults.cflags = [] | ||
} | ||
if (!defaults.defines) { | ||
defaults.defines = [] | ||
} | ||
if (!defaults.include_dirs) { | ||
defaults.include_dirs = [] | ||
} | ||
if (!defaults.libraries) { | ||
defaults.libraries = [] | ||
} | ||
config.variables = { | ||
target_arch: gyp.opts.arch || process.arch || 'ia32' | ||
// set the default_configuration prop | ||
if ('debug' in gyp.opts) { | ||
defaults.default_configuration = gyp.opts.debug ? 'Debug' : 'Release' | ||
} | ||
if (!defaults.default_configuration) { | ||
defaults.default_configuration = 'Release' | ||
} | ||
// set the target_arch variable | ||
variables.target_arch = gyp.opts.arch || process.arch || 'ia32' | ||
// also set the target_version variable | ||
variables.target_version = version | ||
// loop through the rest of the opts and add the unknown ones as variables. | ||
// this allows for module-specific configure flags like: | ||
// | ||
// $ node-gyp configure --shared-libxml2 | ||
Object.keys(gyp.opts).forEach(function (opt) { | ||
if (opt === 'argv') return | ||
if (opt in gyp.configDefs) return | ||
variables[opt.replace(/-/g, '_')] = gyp.opts[opt] | ||
}) | ||
// ensures that any boolean values from `process.config` get stringified | ||
function boolsToString (k, v) { | ||
if (typeof v === 'boolean') | ||
return String(v) | ||
return v | ||
} | ||
// 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, null, 2) | ||
, json = JSON.stringify(config, boolsToString, 2) | ||
gyp.verbose('writing out config file', configPath) | ||
@@ -147,4 +193,4 @@ fs.writeFile(configPath, [prefix, json, ''].join('\n'), runGypAddon) | ||
var devDir = path.resolve(process.env.HOME, '.node-gyp', version) | ||
, gyp_addon = path.resolve(devDir, 'tools', 'gyp_addon') | ||
// location of the `gyp_addon` python script for the target node version | ||
var gyp_addon = path.resolve(gyp.devDir, version, 'tools', 'gyp_addon') | ||
@@ -151,0 +197,0 @@ if (!~argv.indexOf('-f') && !~argv.indexOf('--format')) { |
@@ -56,3 +56,3 @@ | ||
if (semver.lt(versionStr, '0.6.0')) { | ||
return callback(new Error('Minimum target version is `0.6` or greater. Got: ' + versionStr)) | ||
return callback(new Error('Minimum target version is `0.6.0` or greater. Got: ' + versionStr)) | ||
} | ||
@@ -71,7 +71,6 @@ | ||
// the directory where the dev files will be installed | ||
var devDir = path.resolve(gyp.devDir, version) | ||
// TODO: Make ~/.node-gyp configurable | ||
var devDir = path.resolve(process.env.HOME, '.node-gyp', version) | ||
// If '--ensure' was passed, then don't *always* install the version, | ||
// If '--ensure' was passed, then don't *always* install the version; | ||
// check if it is already installed, and only install when needed | ||
@@ -247,36 +246,46 @@ if (gyp.opts.ensure) { | ||
gyp.verbose('on Windows; need to download `node.lib`...') | ||
// TODO: windows 64-bit support | ||
var releaseDir = path.resolve(devDir, 'Release') | ||
, debugDir = path.resolve(devDir, 'Debug') | ||
, nodeLibUrl = distUrl + '/v' + version + '/node.lib' | ||
var dir32 = path.resolve(devDir, 'ia32') | ||
, dir64 = path.resolve(devDir, 'x64') | ||
, nodeLibPath32 = path.resolve(dir32, 'node.lib') | ||
, nodeLibPath64 = path.resolve(dir64, 'node.lib') | ||
, nodeLibUrl32 = distUrl + '/v' + version + '/node.lib' | ||
, nodeLibUrl64 = distUrl + '/v' + version + '/x64/node.lib' | ||
gyp.verbose('Release dir', releaseDir) | ||
gyp.verbose('Debug dir', debugDir) | ||
gyp.verbose('`node.lib` url', nodeLibUrl) | ||
// TODO: parallelize mkdirs | ||
mkdir(releaseDir, function (err) { | ||
gyp.verbose('32-bit node.lib dir', dir32) | ||
gyp.verbose('64-bit node.lib dir', dir64) | ||
gyp.verbose('`node.lib` 32-bit url', nodeLibUrl32) | ||
gyp.verbose('`node.lib` 64-bit url', nodeLibUrl64) | ||
var async = 2 | ||
mkdir(dir32, function (err) { | ||
if (err) return done(err) | ||
mkdir(debugDir, function (err) { | ||
if (err) return done(err) | ||
// TODO: clean this mess up, written in a hastemode-9000 | ||
var badDownload = false | ||
var res = download(nodeLibUrl, function (err, res) { | ||
if (err || res.statusCode != 200) { | ||
badDownload = true | ||
done(err || new Error(res.statusCode + ' status code downloading node.lib')) | ||
} | ||
var res = download(nodeLibUrl32, function (err, _res) { | ||
if (err || _res.statusCode !== 200) { | ||
return done(err || new Error(res.statusCode + ' status code downloading 32-bit node.lib')) | ||
} | ||
gyp.verbose('streaming 32-bit node.lib to:', nodeLibPath32) | ||
var ws = fs.createWriteStream(nodeLibPath32) | ||
ws.on('error', cb) | ||
res.pipe(ws) | ||
res.on('end', function () { | ||
--async || done() | ||
}) | ||
var releaseDirNodeLib = path.resolve(releaseDir, 'node.lib') | ||
, debugDirNodeLib = path.resolve(debugDir, 'node.lib') | ||
, rws = fs.createWriteStream(releaseDirNodeLib) | ||
, dws = fs.createWriteStream(debugDirNodeLib) | ||
gyp.verbose('streaming to', releaseDirNodeLib) | ||
gyp.verbose('streaming to', debugDirNodeLib) | ||
res.pipe(rws) | ||
res.pipe(dws) | ||
}) | ||
res.on('error', done) | ||
}) | ||
mkdir(dir64, function (err) { | ||
if (err) return done(err) | ||
var res = download(nodeLibUrl64, function (err, _res) { | ||
if (err || _res.statusCode !== 200) { | ||
return done(err || new Error(res.statusCode + ' status code downloading 64-bit node.lib')) | ||
} | ||
gyp.verbose('streaming 64-bit node.lib to:', nodeLibPath64) | ||
var ws = fs.createWriteStream(nodeLibPath64) | ||
ws.on('error', cb) | ||
res.pipe(ws) | ||
res.on('end', function () { | ||
if (badDownload) return | ||
done() | ||
--async || done() | ||
}) | ||
}) | ||
res.on('error', done) | ||
}) | ||
@@ -283,0 +292,0 @@ } |
@@ -15,9 +15,6 @@ | ||
// TODO: Make ~/.node-gyp configurable | ||
var nodeGypDir = path.resolve(process.env.HOME, '.node-gyp') | ||
gyp.verbose('using node-gyp dir', gyp.devDir) | ||
gyp.verbose('using node-gyp dir', nodeGypDir) | ||
// readdir the node-gyp dir | ||
fs.readdir(nodeGypDir, onreaddir) | ||
fs.readdir(gyp.devDir, onreaddir) | ||
@@ -24,0 +21,0 @@ function onreaddir (err, versions) { |
@@ -41,2 +41,8 @@ | ||
// set the dir where node-gyp dev files get installed | ||
// TODO: make this configurable? | ||
// see: https://github.com/TooTallNate/node-gyp/issues/21 | ||
var homeDir = process.env.HOME || process.env.USERPROFILE | ||
this.devDir = path.resolve(homeDir, '.node-gyp') | ||
this.commands = {} | ||
@@ -60,2 +66,6 @@ commands.forEach(function (command) { | ||
/** | ||
* nopt configuration definitions | ||
*/ | ||
proto.configDefs = { | ||
@@ -72,4 +82,15 @@ help: Boolean // everywhere | ||
proto.shorthands = {} | ||
/** | ||
* nopt shorthands | ||
*/ | ||
proto.shorthands = { | ||
release: '--no-debug' | ||
} | ||
/** | ||
* Parses the given argv array and sets the 'opts', | ||
* 'argv' and 'command' properties. | ||
*/ | ||
proto.parseArgv = function parseOpts (argv) { | ||
@@ -76,0 +97,0 @@ this.opts = nopt(this.configDefs, this.shorthands, argv) |
@@ -17,7 +17,4 @@ | ||
// TODO: Make ~/.node-gyp configurable | ||
var nodeGypDir = path.resolve(process.env.HOME, '.node-gyp') | ||
gyp.verbose('using node-gyp dir', gyp.devDir) | ||
gyp.verbose('using node-gyp dir', nodeGypDir) | ||
// get the user-specified version to remove | ||
@@ -40,3 +37,3 @@ var v = argv[0] || gyp.opts.target | ||
var versionPath = path.resolve(nodeGypDir, version) | ||
var versionPath = path.resolve(gyp.devDir, version) | ||
gyp.verbose('removing development files for version', version) | ||
@@ -43,0 +40,0 @@ |
{ "name": "node-gyp" | ||
, "description": "Node.js native addon build tool" | ||
, "keywords": [ "native", "addon", "module", "c", "c++", "bindings", "gyp" ] | ||
, "version": "0.3.9" | ||
, "installVersion": 5 | ||
, "version": "0.3.10" | ||
, "installVersion": 6 | ||
, "author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)" | ||
@@ -7,0 +7,0 @@ , "repository": { "type": "git", "url": "git://github.com/TooTallNate/node-gyp.git" } |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
915209
1153