From a653e89fbfa12b2e0842ff2095b139b64efff0aa Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Sun, 5 Feb 2012 10:34:01 -0800 Subject: [PATCH] Copy the legacy files on 'install' when version is "0.6". Fixes #1. --- lib/install.js | 104 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 21 deletions(-) diff --git a/lib/install.js b/lib/install.js index 2a9a3f4a53..2bb72035db 100644 --- a/lib/install.js +++ b/lib/install.js @@ -81,27 +81,7 @@ function install (gyp, argv, callback) { .pipe(zlib.createGunzip()) .pipe(parser) parser.on('entry', onEntry) - parser.on('end', function () { - if (!badDownload) { - gyp.verbose('done parsing tarball') - // now check the current version, if one isn't set, then "use" - // this newly installed version - gyp.verbose('now checking to see if a version needs to be set') - gyp.commands.current([], function (err, cur) { - if (err) return cb(err) - if (typeof cur == 'undefined') { - gyp.verbose('there\'s no version currently in "use", setting to', version) - gyp.commands.use([ version ], function (err) { - if (err) return cb(err) - cb() - }) - } else { - gyp.verbose('already set to another version, forget about it', cur) - cb() - } - }) - } - }) + parser.on('end', afterTarball) // something went wrong downloading the tarball? function downloadError (err, res) { @@ -153,11 +133,93 @@ function install (gyp, argv, callback) { }) } + + function afterTarball () { + if (badDownload) return + gyp.verbose('done parsing tarball') + var async = 0 + + async++ + checkVersion(deref) + + if (version === 0.6) { + async++ + copyLegacy(deref) + } + + //if (win) { + + //} + function deref (err) { + if (err) return cb(err) + --async || cb() + } + } + + function checkVersion (done) { + // now check the current version, if one isn't set, then "use" + // this newly installed version + gyp.verbose('now checking to see if a version needs to be set') + gyp.commands.current([], function (err, cur) { + if (err) return done(err) + if (typeof cur == 'undefined') { + gyp.verbose('there\'s no version currently in "use", setting to', version) + gyp.commands.use([ version ], function (err) { + if (err) return done(err) + done() + }) + } else { + gyp.verbose('already set to another version, forget about it', cur) + done() + } + }) + } + + function copyLegacy (done) { + // node 0.6.x doesn't come with the needed addon.gypi or gyp_addon + // files, so we must copy them over manually + gyp.verbose('copying "legacy" development files for version', version) + var legacyDir = path.join(__dirname, '..', 'legacy') + , toolsDir = path.join(devDir, 'tools') + gyp.verbose('using "legacy" dir', legacyDir) + gyp.verbose('installing to "tools" dir', toolsDir) + + // get a listing of the files to copy + fs.readdir(legacyDir, function (err, files) { + if (err) return done(err) + var count = files.length + + // copy each one over in parallel + files.forEach(function (file) { + var copyFrom = path.join(legacyDir, file) + , copyTo = path.join(toolsDir, path.basename(file)) + gyp.verbose('copying from, to', copyFrom, copyTo) + copy(copyFrom, copyTo, function (err) { + // TODO: guard against multi-callbacks + if (err) return done(err) + --count || done() + }) + }) + }) + } + + }) } } +function copy (from, to, cb) { + var ws = fs.createWriteStream(to) + , rs = fs.createReadStream(from) + rs.on('error', cb) + ws.on('error', cb) + rs.pipe(ws) + rs.on('end', function () { + cb() + }) +} + install.valid = function valid (file) { return minimatch(file, '*.gypi') || minimatch(file, 'tools/*.gypi')