Skip to content

Commit

Permalink
windows: better msbuild version/path parsing and query correct regist…
Browse files Browse the repository at this point in the history
…ry on 64-bit
  • Loading branch information
mscdex committed Mar 27, 2013
1 parent 3923b73 commit 23bd601
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,33 @@ function build (gyp, argv, callback) {
function findMsbuild () {
log.verbose('could not find "msbuild.exe" in PATH - finding location in registry')
var notfoundErr = new Error('Can\'t find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008+ installed?')
exec('reg query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s', function (err, stdout, stderr) {
var reVers = /Software\\Microsoft\\MSBuild\\ToolsVersions\\([^\r]+)\r\n\s+MSBuildToolsPath\s+REG_SZ\s+([^\r]+)/gi
var cmd = 'reg query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s'
if (process.arch !== 'ia32')
cmd += ' /reg:32'
exec(cmd, function (err, stdout, stderr) {
var reVers = /ToolsVersions\\([^\\]+)$/i
, rePath = /\r\n[ \t]+MSBuildToolsPath[ \t]+REG_SZ[ \t]+([^\r]+)/i
, msbuilds = []
, r
, msbuildPath
if (err) {
return callback(notfoundErr)
}
while (r = reVers.exec(stdout)) {
if (parseFloat(r[1], 10) >= 3.5) {
msbuilds.push({
version: parseFloat(r[1], 10),
path: r[2]
})
stdout.split('\r\n\r\n').forEach(function(l) {
if (!l) return
l = l.trim()
if (r = reVers.exec(l.substring(0, l.indexOf('\r\n')))) {
var ver = parseFloat(r[1], 10)
if (ver >= 3.5) {
if (r = rePath.exec(l)) {
msbuilds.push({
version: ver,
path: r[1]
})
}
}
}
}
})
msbuilds.sort(function (x, y) {
return (x.version < y.version ? -1 : 1)
})
Expand Down

1 comment on commit 23bd601

@domenic
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yessssss

Please sign in to comment.