Skip to content

Commit 0376bd6

Browse files
bzozrefack
authored andcommitted
win: find and setup for VS2017
1 parent 3291fed commit 0376bd6

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

lib/build.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ var fs = require('graceful-fs')
1414
, mkdirp = require('mkdirp')
1515
, exec = require('child_process').exec
1616
, processRelease = require('./process-release')
17-
, win = process.platform == 'win32'
17+
, win = process.platform === 'win32';
18+
if (win)
19+
var findVS = require('get-vs2017-path')
1820

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

@@ -107,7 +109,7 @@ function build (gyp, argv, callback) {
107109
if (err) {
108110
if (win && /not found/.test(err.message)) {
109111
// On windows and no 'msbuild' found. Let's guess where it is
110-
findMsbuild()
112+
findMsbuild15()
111113
} else {
112114
// Some other error or 'make' not found on Unix, report that to the user
113115
callback(err)
@@ -122,6 +124,17 @@ function build (gyp, argv, callback) {
122124
/**
123125
* Search for the location of "msbuild.exe" file on Windows.
124126
*/
127+
function findMsbuild15() {
128+
log.verbose('looking for VS2017 msbuild')
129+
var msbuild_path = findVS.locateMsbuild()
130+
if (msbuild_path) {
131+
command = msbuild_path
132+
log.verbose('found VS2017 msbuild at ' + msbuild_path)
133+
copyNodeLib()
134+
} else {
135+
findMsbuild()
136+
}
137+
}
125138

126139
function findMsbuild () {
127140
log.verbose('could not find "msbuild.exe" in PATH - finding location in registry')

lib/configure.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ var fs = require('graceful-fs')
2222
, win = process.platform == 'win32'
2323
, findNodeDirectory = require('./find-node-directory')
2424
, msgFormat = require('util').format
25+
if (win)
26+
var findVS = require('./find-vs2017')
2527

2628
exports.usage = 'Generates ' + (win ? 'MSVC project files' : 'a Makefile') + ' for the current module'
2729

@@ -39,10 +41,23 @@ function configure (gyp, argv, callback) {
3941
callback(err)
4042
} else {
4143
python = found
42-
getNodeDir()
44+
findVisualStudio2017()
4345
}
4446
})
4547

48+
function findVisualStudio2017() {
49+
if (win) {
50+
const vsSetup = findVS.getVS2017Setup();
51+
if (!vsSetup) return callback()
52+
gyp.opts.msvs_version = '2017';
53+
process.env['vs2017_install'] = vsSetup.InstallationPath;
54+
if (vsSetup.SDK) process.env['vs2017_sdk'] = vsSetup.SDK.replace(/\d+$/, '0')
55+
callback();
56+
} else {
57+
getNodeDir()
58+
}
59+
}
60+
4661
function getNodeDir () {
4762

4863
// 'python' should be set by now
@@ -317,9 +332,9 @@ function configure (gyp, argv, callback) {
317332
}
318333

319334
/**
320-
* Returns the first file or directory from an array of candidates that is
335+
* Returns the first file or directory from an array of candidates that is
321336
* readable by the current user, or undefined if none of the candidates are
322-
* readable.
337+
* readable.
323338
*/
324339
function findAccessibleSync (logprefix, dir, candidates) {
325340
for (var next = 0; next < candidates.length; next++) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"main": "./lib/node-gyp.js",
2424
"dependencies": {
2525
"fstream": "^1.0.0",
26+
"get-vs2017-path": "^1.2.0",
2627
"glob": "^7.0.3",
2728
"graceful-fs": "^4.1.2",
2829
"minimatch": "^3.0.2",

0 commit comments

Comments
 (0)