Skip to content

Commit

Permalink
Copy the legacy files on 'install' when version is "0.6". Fixes #1.
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Feb 5, 2012
1 parent e31cdc5 commit a653e89
Showing 1 changed file with 83 additions and 21 deletions.
104 changes: 83 additions & 21 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit a653e89

Please sign in to comment.