@@ -21,27 +21,39 @@ var fs = require('graceful-fs')
21
21
, execFile = cp . execFile
22
22
, win = process . platform == 'win32'
23
23
, findNodeDirectory = require ( './find-node-directory' )
24
- , msgFormat = require ( 'util' ) . format
24
+ , gypjs = undefined
25
25
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' :
27
+ ( win ? 'MSVC project files' : 'a Makefile' ) ) + ' for the current module'
27
28
28
29
function configure ( gyp , argv , callback ) {
29
30
30
31
var python = gyp . opts . python || process . env . PYTHON || 'python2'
31
32
, buildDir = path . resolve ( 'build' )
32
33
, configNames = [ 'config.gypi' , 'common.gypi' ]
33
34
, configs = [ ]
35
+ , buildType
36
+ , arch
34
37
, nodeDir
35
38
, release = processRelease ( argv , gyp , process . version , process . release )
36
39
37
- findPython ( python , function ( err , found ) {
38
- if ( err ) {
39
- callback ( err )
40
- } else {
41
- python = found
42
- getNodeDir ( )
40
+ if ( ! gyp . opts . gypjs ) {
41
+ findPython ( python , function ( err , found ) {
42
+ if ( err ) {
43
+ callback ( err )
44
+ } else {
45
+ python = found
46
+ getNodeDir ( )
47
+ }
48
+ } )
49
+ } else {
50
+ try {
51
+ gypjs = require ( 'gyp.js' )
52
+ } catch ( err ) {
53
+ return callback ( new Error ( 'Can\'t find module gyp.js, you can install it with `npm install gyp.js`' ) )
43
54
}
44
- } )
55
+ getNodeDir ( )
56
+ }
45
57
46
58
function getNodeDir ( ) {
47
59
@@ -124,9 +136,10 @@ function configure (gyp, argv, callback) {
124
136
if ( ! defaults . default_configuration ) {
125
137
defaults . default_configuration = 'Release'
126
138
}
139
+ buildType = defaults . default_configuration
127
140
128
141
// set the target_arch variable
129
- variables . target_arch = gyp . opts . arch || process . arch || 'ia32'
142
+ variables . target_arch = arch = gyp . opts . arch || process . arch || 'ia32'
130
143
131
144
// set the node development directory
132
145
variables . nodedir = nodeDir
@@ -185,35 +198,37 @@ function configure (gyp, argv, callback) {
185
198
function runGyp ( err ) {
186
199
if ( err ) return callback ( err )
187
200
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' )
201
+ if ( ! gyp . opts . gypjs ) {
202
+ if ( ! ~ argv . indexOf ( '-f' ) && ! ~ argv . indexOf ( '--format' ) ) {
203
+ if ( win ) {
204
+ log . verbose ( 'gyp' , 'gyp format was not specified; forcing "msvs"' )
205
+ // force the 'msvs' target for non-Windows
206
+ argv . push ( '-f' , 'msvs' )
207
+ } else {
208
+ log . verbose ( 'gyp' , 'gyp format was not specified; forcing "make"' )
209
+ // force the 'make' target for non-Windows
210
+ argv . push ( '-f' , 'make' )
211
+ }
197
212
}
198
- }
199
213
200
- function hasMsvsVersion ( ) {
201
- return argv . some ( function ( arg ) {
202
- return arg . indexOf ( 'msvs_version' ) === 0
203
- } )
204
- }
214
+ function hasMsvsVersion ( ) {
215
+ return argv . some ( function ( arg ) {
216
+ return arg . indexOf ( 'msvs_version' ) === 0
217
+ } )
218
+ }
205
219
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' )
220
+ if ( win && ! hasMsvsVersion ( ) ) {
221
+ if ( 'msvs_version' in gyp . opts ) {
222
+ argv . push ( '-G' , 'msvs_version=' + gyp . opts . msvs_version )
223
+ } else {
224
+ argv . push ( '-G' , 'msvs_version=auto' )
225
+ }
211
226
}
212
227
}
213
228
214
229
// include all the ".gypi" files that were found
215
230
configs . forEach ( function ( config ) {
216
- argv . push ( '-I' , config )
231
+ argv . push ( '-I' + config )
217
232
} )
218
233
219
234
// for AIX we need to set up the path to the exp file
@@ -237,9 +252,8 @@ function configure (gyp, argv, callback) {
237
252
if ( node_exp_file !== undefined ) {
238
253
log . verbose ( logprefix , 'Found exports file: %s' , node_exp_file )
239
254
} else {
240
- var msg = msgFormat ( 'Could not find node.exp file in %s' , node_root_dir )
241
255
log . error ( logprefix , 'Could not find exports file' )
242
- return callback ( new Error ( msg ) )
256
+ return callback ( new Error ( 'Could not find node.exp file in ' + node_root_dir ) )
243
257
}
244
258
}
245
259
@@ -258,11 +272,12 @@ function configure (gyp, argv, callback) {
258
272
}
259
273
var nodeGypDir = path . resolve ( __dirname , '..' )
260
274
var nodeLibFile = path . join ( nodeDir ,
261
- ! gyp . opts . nodedir ? '<(target_arch)' : '$(Configuration)' ,
275
+ ! gyp . opts . nodedir ? '<(target_arch)' :
276
+ ( gyp . opts . gypjs ? buildType : '$(Configuration)' ) ,
262
277
release . name + '.lib' )
263
278
264
- argv . push ( '-I' , addon_gypi )
265
- argv . push ( '-I' , common_gypi )
279
+ argv . push ( '-I' + addon_gypi )
280
+ argv . push ( '-I' + common_gypi )
266
281
argv . push ( '-Dlibrary=shared_library' )
267
282
argv . push ( '-Dvisibility=default' )
268
283
argv . push ( '-Dnode_root_dir=' + nodeDir )
@@ -284,15 +299,20 @@ function configure (gyp, argv, callback) {
284
299
// enforce use of the "binding.gyp" file
285
300
argv . unshift ( 'binding.gyp' )
286
301
287
- // execute `gyp` from the current target nodedir
288
- argv . unshift ( gyp_script )
302
+ if ( ! gyp . opts . gypjs ) {
303
+ // execute `gyp` from the current target nodedir
304
+ argv . unshift ( gyp_script )
289
305
290
- // make sure python uses files that came with this particular node package
291
- var pypath = new PathArray ( process . env , 'PYTHONPATH' )
292
- pypath . unshift ( path . join ( __dirname , '..' , 'gyp' , 'pylib' ) )
306
+ // make sure python uses files that came with this particular node package
307
+ var pypath = new PathArray ( process . env , 'PYTHONPATH' )
308
+ pypath . unshift ( path . join ( __dirname , '..' , 'gyp' , 'pylib' ) )
293
309
294
- var cp = gyp . spawn ( python , argv )
295
- cp . on ( 'exit' , onCpExit )
310
+ var cp = gyp . spawn ( python , argv )
311
+ cp . on ( 'exit' , onCpExit )
312
+ } else {
313
+ argv . push ( '-Dtarget_arch=' + arch )
314
+ onCpExit ( gypjs . main ( argv ) )
315
+ }
296
316
} )
297
317
}
298
318
0 commit comments