From 0376bd6e85db3bf5cba9aadaaf72353599917478 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Mon, 30 Jan 2017 09:47:58 -0500 Subject: [PATCH] win: find and setup for VS2017 --- lib/build.js | 17 +++++++++++++++-- lib/configure.js | 21 ++++++++++++++++++--- package.json | 1 + 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/build.js b/lib/build.js index 0374fbc810..4486a3d1fc 100644 --- a/lib/build.js +++ b/lib/build.js @@ -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 findVS = require('get-vs2017-path') exports.usage = 'Invokes `' + (win ? 'msbuild' : 'make') + '` and builds the module' @@ -107,7 +109,7 @@ function build (gyp, argv, callback) { if (err) { if (win && /not found/.test(err.message)) { // On windows and no 'msbuild' found. Let's guess where it is - findMsbuild() + findMsbuild15() } else { // Some other error or 'make' not found on Unix, report that to the user callback(err) @@ -122,6 +124,17 @@ function build (gyp, argv, callback) { /** * Search for the location of "msbuild.exe" file on Windows. */ + function findMsbuild15() { + log.verbose('looking for VS2017 msbuild') + var msbuild_path = findVS.locateMsbuild() + if (msbuild_path) { + command = msbuild_path + log.verbose('found VS2017 msbuild at ' + msbuild_path) + copyNodeLib() + } else { + findMsbuild() + } + } function findMsbuild () { log.verbose('could not find "msbuild.exe" in PATH - finding location in registry') diff --git a/lib/configure.js b/lib/configure.js index d52b2902b0..e91a633120 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -22,6 +22,8 @@ var fs = require('graceful-fs') , win = process.platform == 'win32' , findNodeDirectory = require('./find-node-directory') , msgFormat = require('util').format +if (win) + var findVS = require('./find-vs2017') exports.usage = 'Generates ' + (win ? 'MSVC project files' : 'a Makefile') + ' for the current module' @@ -39,10 +41,23 @@ function configure (gyp, argv, callback) { callback(err) } else { python = found - getNodeDir() + findVisualStudio2017() } }) + function findVisualStudio2017() { + if (win) { + const vsSetup = findVS.getVS2017Setup(); + if (!vsSetup) return callback() + gyp.opts.msvs_version = '2017'; + process.env['vs2017_install'] = vsSetup.InstallationPath; + if (vsSetup.SDK) process.env['vs2017_sdk'] = vsSetup.SDK.replace(/\d+$/, '0') + callback(); + } else { + getNodeDir() + } + } + function getNodeDir () { // 'python' should be set by now @@ -317,9 +332,9 @@ function configure (gyp, argv, callback) { } /** - * Returns the first file or directory from an array of candidates that is + * Returns the first file or directory from an array of candidates that is * readable by the current user, or undefined if none of the candidates are - * readable. + * readable. */ function findAccessibleSync (logprefix, dir, candidates) { for (var next = 0; next < candidates.length; next++) { diff --git a/package.json b/package.json index 068271addf..b04486c1ca 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "main": "./lib/node-gyp.js", "dependencies": { "fstream": "^1.0.0", + "get-vs2017-path": "^1.2.0", "glob": "^7.0.3", "graceful-fs": "^4.1.2", "minimatch": "^3.0.2",