@@ -23,7 +23,7 @@ var fs = require('graceful-fs')
2323 , findNodeDirectory = require ( './find-node-directory' )
2424 , msgFormat = require ( 'util' ) . format
2525if ( win )
26- var findVS2017 = require ( './find-vs2017 ' )
26+ var findVS = require ( 'windows-autoconf ' )
2727
2828exports . usage = 'Generates ' + ( win ? 'MSVC project files' : 'a Makefile' ) + ' for the current module'
2929
@@ -41,15 +41,13 @@ function configure (gyp, argv, callback) {
4141 callback ( err )
4242 } else {
4343 python = found
44- getNodeDir ( )
44+ // 'python' should be set by now
45+ process . env . PYTHON = python
46+ getNodeDir ( )
4547 }
4648 } )
4749
4850 function getNodeDir ( ) {
49-
50- // 'python' should be set by now
51- process . env . PYTHON = python
52-
5351 if ( gyp . opts . nodedir ) {
5452 // --nodedir was specified. use that for the dev files
5553 nodeDir = gyp . opts . nodedir . replace ( / ^ ~ / , osenv . home ( ) )
@@ -88,22 +86,29 @@ function configure (gyp, argv, callback) {
8886 mkdirp ( buildDir , function ( err , isNew ) {
8987 if ( err ) return callback ( err )
9088 log . verbose ( 'build dir' , '"build" dir needed to be created?' , isNew )
91- if ( win && ( ! gyp . opts . msvs_version || gyp . opts . msvs_version === '2017' ) ) {
92- findVS2017 ( function ( err , vsSetup ) {
93- if ( err ) {
94- log . verbose ( 'Not using VS2017:' , err . message )
95- createConfigFile ( )
96- } else {
97- createConfigFile ( null , vsSetup )
98- }
99- } )
100- } else {
101- createConfigFile ( )
102- }
89+ createConfigFile ( )
10390 } )
10491 }
10592
106- function createConfigFile ( err , vsSetup ) {
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+
111+ function createConfigFile ( err ) {
107112 if ( err ) return callback ( err )
108113
109114 var configFilename = 'config.gypi'
@@ -150,18 +155,8 @@ function configure (gyp, argv, callback) {
150155 // disable -T "thin" static archives by default
151156 variables . standalone_static_library = gyp . opts . thin ? 0 : 1
152157
153- if ( vsSetup ) {
154- // GYP doesn't (yet) have support for VS2017, so we force it to VS2015
155- // to avoid pulling a floating patch that has not landed upstream.
156- // Ref: https://chromium-review.googlesource.com/#/c/433540/
157- gyp . opts . msvs_version = '2015'
158- process . env [ 'GYP_MSVS_VERSION' ] = 2015
159- process . env [ 'GYP_MSVS_OVERRIDE_PATH' ] = vsSetup . path
160- defaults [ 'msbuild_toolset' ] = 'v141'
161- defaults [ 'msvs_windows_target_platform_version' ] = vsSetup . sdk
162- variables [ 'msbuild_path' ] = path . join ( vsSetup . path , 'MSBuild' , '15.0' ,
163- 'Bin' , 'MSBuild.exe' )
164- }
158+ if ( win )
159+ findVisualStudio2017 ( defaults )
165160
166161 // loop through the rest of the opts and add the unknown ones as variables.
167162 // this allows for module-specific configure flags like:
@@ -227,7 +222,7 @@ function configure (gyp, argv, callback) {
227222 }
228223
229224 function hasMsvsVersion ( ) {
230- return argv . some ( function ( arg ) {
225+ return argv . find ( function ( arg ) {
231226 return arg . indexOf ( 'msvs_version' ) === 0
232227 } )
233228 }
0 commit comments