forked from prebuild/prebuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgyp.js
71 lines (60 loc) · 1.77 KB
/
gyp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var assert = require('assert')
var path = require('path')
var os = require('os')
var backends = {
'node-gyp': require('node-gyp')(),
'node-ninja': require('node-ninja')(),
'nw-gyp': require('nw-gyp')()
}
// Use system installed node-gyp for other JS engines
var jsEngine = process.jsEngine || 'v8'
if (jsEngine !== 'v8') {
backends['node-gyp'] = require(path.join(
path.dirname(process.execPath), 'node_modules/npm/node_modules/node-gyp'))()
}
function runGyp (opts, cb) {
var backend = opts.backend || 'node-gyp'
var gyp = opts.gyp || backends[backend]
assert(gyp, 'missing backend')
var log = opts.log
var args = opts.args
assert(Array.isArray(args), 'args must be an array')
log.verbose('execute ' + backend + ' with `' + args.join(' ') + '`')
gyp.parseArgv(args)
gyp.devDir = devDir(opts.runtime || 'node')
function runStep () {
var command = gyp.todo.shift()
if (!command) {
return cb()
}
if (opts.filter) {
if (opts.filter(command)) {
process.nextTick(runStep)
return
}
}
gyp.commands[command.name](command.args, function (err) {
if (err) {
log.error(command.name + ' error')
log.error('stack', err.stack)
log.error('not ok')
return cb(err)
}
log.verbose('ok')
process.nextTick(runStep)
})
}
if (gyp.todo.length > 0) {
runStep()
} else {
log.verbose('no gyp tasks needed')
cb()
}
}
function devDir (runtime) {
// Since electron and node are reusing the versions now (fx 6.0.0) and
// node-gyp only uses the version to store the dev files, they have started
// clashing. To work around this we explicitly set devdir to tmpdir/runtime(/target)
return path.join(os.tmpdir(), 'prebuild', runtime)
}
module.exports = runGyp