@@ -21,9 +21,9 @@ var fs = require('graceful-fs')
2121 , execFile = cp . execFile
2222 , win = process . platform == 'win32'
2323 , findNodeDirectory = require ( './find-node-directory' )
24- , msgFormat = require ( 'util' ) . format
24+ , gypjs = require ( 'gyp.js' )
2525
26- exports . usage = 'Generates ' + ( win ? 'MSVC project files' : 'a Makefile' ) + ' for the current module'
26+ exports . usage = 'Generates ' + ( process . env . npm_config_gypjs ? 'ninja build files' : ( win ? 'MSVC project files' : 'a Makefile' ) ) + ' for the current module'
2727
2828function configure ( gyp , argv , callback ) {
2929
@@ -34,14 +34,18 @@ function configure (gyp, argv, callback) {
3434 , nodeDir
3535 , release = processRelease ( argv , gyp , process . version , process . release )
3636
37- findPython ( python , function ( err , found ) {
38- if ( err ) {
39- callback ( err )
40- } else {
41- python = found
42- getNodeDir ( )
43- }
44- } )
37+ if ( ! gyp . opts . gypjs ) {
38+ findPython ( python , function ( err , found ) {
39+ if ( err ) {
40+ callback ( err )
41+ } else {
42+ python = found
43+ getNodeDir ( )
44+ }
45+ } )
46+ } else {
47+ getNodeDir ( )
48+ }
4549
4650 function getNodeDir ( ) {
4751
@@ -185,35 +189,37 @@ function configure (gyp, argv, callback) {
185189 function runGyp ( err ) {
186190 if ( err ) return callback ( err )
187191
188- if ( ! ~ argv . indexOf ( '-f' ) && ! ~ argv . indexOf ( '--format' ) ) {
189- if ( win ) {
190- log . verbose ( 'gyp' , 'gyp format was not specified; forcing "msvs"' )
191- // force the 'make' target for non-Windows
192- argv . push ( '-f' , 'msvs' )
193- } else {
194- log . verbose ( 'gyp' , 'gyp format was not specified; forcing "make"' )
195- // force the 'make' target for non-Windows
196- argv . push ( '-f' , 'make' )
192+ if ( ! gyp . opts . gypjs ) {
193+ if ( ! ~ argv . indexOf ( '-f' ) && ! ~ argv . indexOf ( '--format' ) ) {
194+ if ( win ) {
195+ log . verbose ( 'gyp' , 'gyp format was not specified; forcing "msvs"' )
196+ // force the 'make' target for non-Windows
197+ argv . push ( '-f' , 'msvs' )
198+ } else {
199+ log . verbose ( 'gyp' , 'gyp format was not specified; forcing "make"' )
200+ // force the 'make' target for non-Windows
201+ argv . push ( '-f' , 'make' )
202+ }
197203 }
198- }
199204
200- function hasMsvsVersion ( ) {
201- return argv . some ( function ( arg ) {
202- return arg . indexOf ( 'msvs_version' ) === 0
203- } )
204- }
205+ function hasMsvsVersion ( ) {
206+ return argv . some ( function ( arg ) {
207+ return arg . indexOf ( 'msvs_version' ) === 0
208+ } )
209+ }
205210
206- if ( win && ! hasMsvsVersion ( ) ) {
207- if ( 'msvs_version' in gyp . opts ) {
208- argv . push ( '-G' , 'msvs_version=' + gyp . opts . msvs_version )
209- } else {
210- argv . push ( '-G' , 'msvs_version=auto' )
211+ if ( win && ! hasMsvsVersion ( ) ) {
212+ if ( 'msvs_version' in gyp . opts ) {
213+ argv . push ( '-G' , 'msvs_version=' + gyp . opts . msvs_version )
214+ } else {
215+ argv . push ( '-G' , 'msvs_version=auto' )
216+ }
211217 }
212218 }
213219
214220 // include all the ".gypi" files that were found
215221 configs . forEach ( function ( config ) {
216- argv . push ( '-I' , config )
222+ argv . push ( '-I' + config )
217223 } )
218224
219225 // for AIX we need to set up the path to the exp file
@@ -237,9 +243,8 @@ function configure (gyp, argv, callback) {
237243 if ( node_exp_file !== undefined ) {
238244 log . verbose ( logprefix , 'Found exports file: %s' , node_exp_file )
239245 } else {
240- var msg = msgFormat ( 'Could not find node.exp file in %s' , node_root_dir )
241246 log . error ( logprefix , 'Could not find exports file' )
242- return callback ( new Error ( msg ) )
247+ return callback ( new Error ( 'Could not find node.exp file in ' + node_root_dir ) )
243248 }
244249 }
245250
@@ -258,8 +263,8 @@ function configure (gyp, argv, callback) {
258263 }
259264 var nodeGypDir = path . resolve ( __dirname , '..' )
260265
261- argv . push ( '-I' , addon_gypi )
262- argv . push ( '-I' , common_gypi )
266+ argv . push ( '-I' + addon_gypi )
267+ argv . push ( '-I' + common_gypi )
263268 argv . push ( '-Dlibrary=shared_library' )
264269 argv . push ( '-Dvisibility=default' )
265270 argv . push ( '-Dnode_root_dir=' + nodeDir )
@@ -281,15 +286,19 @@ function configure (gyp, argv, callback) {
281286 // enforce use of the "binding.gyp" file
282287 argv . unshift ( 'binding.gyp' )
283288
284- // execute `gyp` from the current target nodedir
285- argv . unshift ( gyp_script )
289+ if ( ! gyp . opts . gypjs ) {
290+ // execute `gyp` from the current target nodedir
291+ argv . unshift ( gyp_script )
286292
287- // make sure python uses files that came with this particular node package
288- var pypath = new PathArray ( process . env , 'PYTHONPATH' )
289- pypath . unshift ( path . join ( __dirname , '..' , 'gyp' , 'pylib' ) )
293+ // make sure python uses files that came with this particular node package
294+ var pypath = new PathArray ( process . env , 'PYTHONPATH' )
295+ pypath . unshift ( path . join ( __dirname , '..' , 'gyp' , 'pylib' ) )
290296
291- var cp = gyp . spawn ( python , argv )
292- cp . on ( 'exit' , onCpExit )
297+ var cp = gyp . spawn ( python , argv )
298+ cp . on ( 'exit' , onCpExit )
299+ } else {
300+ onCpExit ( gypjs . main ( argv ) )
301+ }
293302 } )
294303 }
295304
0 commit comments