@@ -15,6 +15,7 @@ var fs = require('graceful-fs')
1515 , cp = require ( 'child_process' )
1616 , PathArray = require ( 'path-array' )
1717 , extend = require ( 'util' ) . _extend
18+ , processRelease = require ( './process-release' )
1819 , spawn = cp . spawn
1920 , execFile = cp . execFile
2021 , win = process . platform == 'win32'
@@ -28,6 +29,7 @@ function configure (gyp, argv, callback) {
2829 , configNames = [ 'config.gypi' , 'common.gypi' ]
2930 , configs = [ ]
3031 , nodeDir
32+ , release = processRelease ( argv , gyp , process . version , process . release )
3133
3234 checkPython ( )
3335
@@ -135,35 +137,25 @@ function configure (gyp, argv, callback) {
135137
136138 } else {
137139 // if no --nodedir specified, ensure node dependencies are installed
138- var version
139- var versionStr
140-
141- if ( gyp . opts . target ) {
140+ if ( 'v' + release . version !== process . version ) {
142141 // if --target was given, then determine a target version to compile for
143- versionStr = gyp . opts . target
144- log . verbose ( 'get node dir' , 'compiling against --target node version: %s' , versionStr )
142+ log . verbose ( 'get node dir' , 'compiling against --target node version: %s' , release . version )
145143 } else {
146144 // if no --target was specified then use the current host node version
147- versionStr = process . version
148- log . verbose ( 'get node dir' , 'no --target version specified, falling back to host node version: %s' , versionStr )
145+ log . verbose ( 'get node dir' , 'no --target version specified, falling back to host node version: %s' , release . version )
149146 }
150147
151148 // make sure we have a valid version
152- try {
153- version = semver . parse ( versionStr )
154- } catch ( e ) {
155- return callback ( e )
156- }
157- if ( ! version ) {
158- return callback ( new Error ( 'Invalid version number: ' + versionStr ) )
149+ if ( ! release . semver ) {
150+ return callback ( new Error ( 'Invalid version number: ' + release . version ) )
159151 }
160152
161153 // ensure that the target node version's dev files are installed
162154 gyp . opts . ensure = true
163- gyp . commands . install ( [ versionStr ] , function ( err , version ) {
155+ gyp . commands . install ( [ release . version ] , function ( err , version ) {
164156 if ( err ) return callback ( err )
165- log . verbose ( 'get node dir' , 'target node version installed:' , version )
166- nodeDir = path . resolve ( gyp . devDir , version )
157+ log . verbose ( 'get node dir' , 'target node version installed:' , release . versionDir )
158+ nodeDir = path . resolve ( gyp . devDir , release . versionDir )
167159 createBuildDir ( )
168160 } )
169161 }
@@ -310,42 +302,49 @@ function configure (gyp, argv, callback) {
310302 // this logic ported from the old `gyp_addon` python file
311303 var gyp_script = path . resolve ( __dirname , '..' , 'gyp' , 'gyp_main.py' )
312304 var addon_gypi = path . resolve ( __dirname , '..' , 'addon.gypi' )
313- var common_gypi = path . resolve ( nodeDir , 'common.gypi' )
314- var output_dir = 'build'
315- if ( win ) {
316- // Windows expects an absolute path
317- output_dir = buildDir
318- }
319- var nodeGypDir = path . resolve ( __dirname , '..' )
305+ var common_gypi = path . resolve ( nodeDir , 'include/node/common.gypi' )
306+ fs . stat ( common_gypi , function ( err , stat ) {
307+ if ( err || ! stat . isFile ( ) ) {
308+ common_gypi = path . resolve ( nodeDir , 'common.gypi' )
309+ }
320310
321- argv . push ( '-I' , addon_gypi )
322- argv . push ( '-I' , common_gypi )
323- argv . push ( '-Dlibrary=shared_library' )
324- argv . push ( '-Dvisibility=default' )
325- argv . push ( '-Dnode_root_dir=' + nodeDir )
326- argv . push ( '-Dnode_gyp_dir=' + nodeGypDir )
327- argv . push ( '-Dmodule_root_dir=' + process . cwd ( ) )
328- argv . push ( '--depth=.' )
329- argv . push ( '--no-parallel' )
311+ var output_dir = 'build'
312+ if ( win ) {
313+ // Windows expects an absolute path
314+ output_dir = buildDir
315+ }
316+ var nodeGypDir = path . resolve ( __dirname , '..' )
330317
331- // tell gyp to write the Makefile/Solution files into output_dir
332- argv . push ( '--generator-output' , output_dir )
318+ argv . push ( '-I' , addon_gypi )
319+ argv . push ( '-I' , common_gypi )
320+ argv . push ( '-Dlibrary=shared_library' )
321+ argv . push ( '-Dvisibility=default' )
322+ argv . push ( '-Dnode_root_dir=' + nodeDir )
323+ argv . push ( '-Dnode_gyp_dir=' + nodeGypDir )
324+ argv . push ( '-Dnode_lib_file=' + release . name + '.lib' )
325+ argv . push ( '-Dmodule_root_dir=' + process . cwd ( ) )
326+ argv . push ( '--depth=.' )
327+ argv . push ( '--no-parallel' )
333328
334- // tell make to write its output into the same dir
335- argv . push ( '-Goutput_dir=.' )
329+ // tell gyp to write the Makefile/Solution files into output_dir
330+ argv . push ( '--generator-output' , output_dir )
336331
337- // enforce use of the "binding.gyp" file
338- argv . unshift ( 'binding.gyp ')
332+ // tell make to write its output into the same dir
333+ argv . push ( '-Goutput_dir=. ')
339334
340- // execute `gyp` from the current target nodedir
341- argv . unshift ( gyp_script )
335+ // enforce use of the "binding.gyp" file
336+ argv . unshift ( 'binding.gyp' )
342337
343- // make sure python uses files that came with this particular node package
344- var pypath = new PathArray ( process . env , 'PYTHONPATH' )
345- pypath . unshift ( path . join ( __dirname , '..' , 'gyp' , 'pylib' ) )
338+ // execute `gyp` from the current target nodedir
339+ argv . unshift ( gyp_script )
346340
347- var cp = gyp . spawn ( python , argv )
348- cp . on ( 'exit' , onCpExit )
341+ // make sure python uses files that came with this particular node package
342+ var pypath = new PathArray ( process . env , 'PYTHONPATH' )
343+ pypath . unshift ( path . join ( __dirname , '..' , 'gyp' , 'pylib' ) )
344+
345+ var cp = gyp . spawn ( python , argv )
346+ cp . on ( 'exit' , onCpExit )
347+ } )
349348 }
350349
351350 /**
0 commit comments