forked from prebuild/prebuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prebuild.js
65 lines (57 loc) · 1.91 KB
/
prebuild.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
var fs = require('fs')
var async = require('async')
var getAbi = require('node-abi').getAbi
var getTarget = require('node-abi').getTarget
var getTarPath = require('./util').getTarPath
var build = require('./build')
var strip = require('./strip')
var pack = require('./pack')
function prebuild (opts, target, runtime, callback) {
var pkg = opts.pkg
var buildLog = opts.buildLog || function () {}
opts.target = target
opts.runtime = runtime
if (opts.runtime === 'node-webkit') {
opts.backend = 'nw-gyp'
}
var buildLogMessage = 'Preparing to prebuild ' + pkg.name + '@' + pkg.version + ' for ' + runtime + ' ' + target + ' on ' + opts.platform + '-' + opts.arch + ' using ' + opts.backend
if (opts.libc && opts.libc.length > 0) buildLogMessage += 'using libc ' + opts.libc
buildLog(buildLogMessage)
// --target can be target or abi
target = getTarget(target, runtime)
var abi = getAbi(target, runtime)
var tarPath = getTarPath(opts, abi)
fs.stat(tarPath, function (err, st) {
if (!err && !opts.force) {
buildLog(tarPath + ' exists, skipping build')
return callback(null, tarPath)
}
var tasks = [
function (cb) {
build(opts, target, function (err, filenames) {
if (err) return cb(err)
cb(null, filenames)
})
},
function (filenames, cb) {
buildLog('Packing ' + filenames.join(', ') + ' into ' + tarPath)
pack(filenames, tarPath, function (err) {
if (err) return cb(err)
buildLog('Prebuild written to ' + tarPath)
cb(null, tarPath)
})
}
]
if (opts.strip) {
tasks.splice(1, 0, function (filename, cb) {
buildLog('Stripping debug information from ' + filename)
strip(filename, function (err) {
if (err) return cb(err)
cb(null, filename)
})
})
}
async.waterfall(tasks, callback)
})
}
module.exports = prebuild