Skip to content

Commit

Permalink
win: find and setup for VS2017
Browse files Browse the repository at this point in the history
  • Loading branch information
bzoz authored and refack committed Feb 16, 2017
1 parent 3291fed commit 0376bd6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
17 changes: 15 additions & 2 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 findVS = require('get-vs2017-path')

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

Expand Down Expand Up @@ -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)
Expand All @@ -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')
Expand Down
21 changes: 18 additions & 3 deletions lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
Expand Down Expand Up @@ -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++) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0376bd6

Please sign in to comment.