@@ -19,9 +19,11 @@ var fs = require('graceful-fs')
19
19
, cp = require ( 'child_process' )
20
20
, extend = require ( 'util' ) . _extend
21
21
, processRelease = require ( './process-release' )
22
- , win = process . platform == 'win32'
22
+ , win = process . platform === 'win32'
23
23
, findNodeDirectory = require ( './find-node-directory' )
24
24
, msgFormat = require ( 'util' ) . format
25
+ if ( win )
26
+ var findVS = require ( 'windows-autoconf' )
25
27
26
28
exports . usage = 'Generates ' + ( win ? 'MSVC project files' : 'a Makefile' ) + ' for the current module'
27
29
@@ -39,15 +41,13 @@ function configure (gyp, argv, callback) {
39
41
callback ( err )
40
42
} else {
41
43
python = found
42
- getNodeDir ( )
44
+ // 'python' should be set by now
45
+ process . env . PYTHON = python
46
+ getNodeDir ( )
43
47
}
44
48
} )
45
49
46
50
function getNodeDir ( ) {
47
-
48
- // 'python' should be set by now
49
- process . env . PYTHON = python
50
-
51
51
if ( gyp . opts . nodedir ) {
52
52
// --nodedir was specified. use that for the dev files
53
53
nodeDir = gyp . opts . nodedir . replace ( / ^ ~ / , osenv . home ( ) )
@@ -90,6 +90,24 @@ function configure (gyp, argv, callback) {
90
90
} )
91
91
}
92
92
93
+ function findVisualStudio2017 ( defaults ) {
94
+ if ( gyp . opts . msvs_version && gyp . opts . msvs_version !== '2017' )
95
+ return
96
+
97
+ try {
98
+ var vsSetup = findVS . getVS2017Setup ( )
99
+ if ( ! vsSetup || ! vsSetup . InstallationPath ) return
100
+ } catch ( _ ) {
101
+ return
102
+ }
103
+
104
+ gyp . opts . msvs_version = '2015'
105
+ process . env [ 'GYP_MSVS_VERSION' ] = 2015
106
+ process . env [ 'GYP_MSVS_OVERRIDE_PATH' ] = vsSetup . InstallationPath
107
+ defaults [ 'msbuild_toolset' ] = 'v141'
108
+ defaults [ 'msvs_windows_target_platform_version' ] = vsSetup . SDK
109
+ }
110
+
93
111
function createConfigFile ( err ) {
94
112
if ( err ) return callback ( err )
95
113
@@ -137,6 +155,9 @@ function configure (gyp, argv, callback) {
137
155
// disable -T "thin" static archives by default
138
156
variables . standalone_static_library = gyp . opts . thin ? 0 : 1
139
157
158
+ if ( win )
159
+ findVisualStudio2017 ( defaults )
160
+
140
161
// loop through the rest of the opts and add the unknown ones as variables.
141
162
// this allows for module-specific configure flags like:
142
163
//
@@ -201,7 +222,7 @@ function configure (gyp, argv, callback) {
201
222
}
202
223
203
224
function hasMsvsVersion ( ) {
204
- return argv . some ( function ( arg ) {
225
+ return argv . find ( function ( arg ) {
205
226
return arg . indexOf ( 'msvs_version' ) === 0
206
227
} )
207
228
}
@@ -317,9 +338,9 @@ function configure (gyp, argv, callback) {
317
338
}
318
339
319
340
/**
320
- * Returns the first file or directory from an array of candidates that is
341
+ * Returns the first file or directory from an array of candidates that is
321
342
* readable by the current user, or undefined if none of the candidates are
322
- * readable.
343
+ * readable.
323
344
*/
324
345
function findAccessibleSync ( logprefix , dir , candidates ) {
325
346
for ( var next = 0 ; next < candidates . length ; next ++ ) {
0 commit comments