Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win: use windows-autoconf to setup MSVS 2010 to 2017 #1178

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
gyp/test
node_modules
test/.node-gyp
!test/node_modules
build/
268 changes: 0 additions & 268 deletions lib/Find-VS2017.cs

This file was deleted.

76 changes: 14 additions & 62 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ var fs = require('graceful-fs')
, mkdirp = require('mkdirp')
, exec = require('child_process').exec
, processRelease = require('./process-release')
, win = process.platform === 'win32'
, win = process.platform === 'win32';
if (win)
var autoconf = require('windows-autoconf')

exports.usage = 'Invokes `' + (win ? 'msbuild' : 'make') + '` and builds the module'

Expand Down Expand Up @@ -106,7 +108,7 @@ function build (gyp, argv, callback) {
which(command, function (err, execPath) {
if (err) {
if (win && /not found/.test(err.message)) {
// On windows and no 'msbuild' found. Let's guess where it is
log.verbose('could not find "msbuild.exe" in PATH - finding location in registry')
findMsbuild()
} else {
// Some other error or 'make' not found on Unix, report that to the user
Expand All @@ -122,68 +124,18 @@ function build (gyp, argv, callback) {
/**
* Search for the location of "msbuild.exe" file on Windows.
*/

function findMsbuild () {
if (config.variables.msbuild_path) {
command = config.variables.msbuild_path
log.verbose('using MSBuild:', command)
copyNodeLib()
return
}

log.verbose('could not find "msbuild.exe" in PATH - finding location in registry')
var notfoundErr = 'Can\'t find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008+ installed?'
var cmd = 'reg query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s'
if (process.arch !== 'ia32')
cmd += ' /reg:32'
exec(cmd, function (err, stdout, stderr) {
if (err) {
return callback(new Error(err.message + '\n' + notfoundErr))
var notfoundErr = 'Can\'t find "msbuild.exe". Do you have Microsoft Visual Studio installed?'
try {
var msbuild_path = autoconf.locateMsbuild()
if (!msbuild_path) {
return callback(new Error(notfoundErr))
}
var reVers = /ToolsVersions\\([^\\]+)$/i
, rePath = /\r\n[ \t]+MSBuildToolsPath[ \t]+REG_SZ[ \t]+([^\r]+)/i
, msbuilds = []
, r
, msbuildPath
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)
})
;(function verifyMsbuild () {
if (!msbuilds.length) return callback(new Error(notfoundErr))
msbuildPath = path.resolve(msbuilds.pop().path, 'msbuild.exe')
fs.stat(msbuildPath, function (err, stat) {
if (err) {
if (err.code == 'ENOENT') {
if (msbuilds.length) {
return verifyMsbuild()
} else {
callback(new Error(notfoundErr))
}
} else {
callback(err)
}
return
}
command = msbuildPath
copyNodeLib()
})
})()
})
} catch (e) {
return callback(new Error(err.message + '\n' + notfoundErr))
}
command = msbuild_path
copyNodeLib()
}

/**
Expand Down
Loading