Skip to content

Commit 498f1ee

Browse files
authored
Merge pull request #96 from lgeiger/dont-recompile-libzmq
Don't recompile libzmq if already built
2 parents 4bb5066 + 4087c89 commit 498f1ee

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"scripts": {
2727
"build:libzmq": "node scripts/preinstall.js",
2828
"install": "prebuild --install --preinstall \"npm run build:libzmq\"",
29-
"rebuild": "prebuild --compile",
3029
"prebuild": "prebuild --all --strip",
3130
"build:docs": "jsdoc -R README.md -d docs lib/*.js",
3231
"test": "mocha --expose-gc --slow 300",

scripts/build_libzmq.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ make install
2626

2727
cd $ZMQ_PREFIX
2828
rm -rf $ZMQ_SRC_DIR
29+
rm -f zeromq-$ZMQ.tar.gz

scripts/preinstall.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (process.platform == 'linux') {
1313
ZMQ_REPO = 'libzmq';
1414
}
1515

16-
function buildZMQ(scriptPath) {
16+
function buildZMQ(scriptPath, zmqDir) {
1717
console.log('Building libzmq for ' + process.platform);
1818

1919
var child = spawn(scriptPath, [ZMQ]);
@@ -23,6 +23,18 @@ function buildZMQ(scriptPath) {
2323
child.on('error', function(err) {
2424
console.error('Failed to start child process.');
2525
});
26+
child.on('close', function(code) {
27+
if (code !== 0) {
28+
return console.error('child process exited with code ' + code);
29+
}
30+
var message = 'Succesfully build libzmq on ' + Date();
31+
fs.writeFile(path.join(zmqDir, 'BUILD_SUCCESS'), message, function(err) {
32+
if (err) {
33+
return console.error(err.message);
34+
}
35+
console.log(message);
36+
});
37+
});
2638
}
2739

2840
if (process.platform === 'win32') {
@@ -44,18 +56,23 @@ if (process.platform === 'win32') {
4456
} else {
4557
var SCRIPT_PATH = path.join(__dirname, 'build_libzmq.sh');
4658
var TAR_URL = 'https://github.com/zeromq/' + ZMQ_REPO + '/releases/download/v' + ZMQ + '/zeromq-' + ZMQ + '.tar.gz';
47-
var DIR = path.join(__dirname, '..', 'zmq');
48-
var FILE_NAME = path.join(DIR, 'zeromq-' + ZMQ + '.tar.gz');
59+
var DIR_NAME = path.join(__dirname, '..', 'zmq');
60+
var FILE_NAME = path.join(DIR_NAME, 'zeromq-' + ZMQ + '.tar.gz');
61+
62+
if (!fs.existsSync(DIR_NAME)) {
63+
fs.mkdirSync(DIR_NAME);
64+
}
4965

50-
if (!fs.existsSync(DIR)) {
51-
fs.mkdirSync(DIR);
66+
if (fs.existsSync(path.join(DIR_NAME, 'BUILD_SUCCESS'))) {
67+
return console.log('Libzmq found, skipping rebuild.');
5268
}
5369

5470
if (fs.existsSync(FILE_NAME)) {
55-
buildZMQ(SCRIPT_PATH);
56-
} else {
57-
download(TAR_URL, FILE_NAME, function() {
58-
buildZMQ(SCRIPT_PATH);
59-
});
71+
return buildZMQ(SCRIPT_PATH, DIR_NAME);
6072
}
73+
74+
download(TAR_URL, FILE_NAME, function() {
75+
buildZMQ(SCRIPT_PATH, DIR_NAME);
76+
});
77+
6178
}

0 commit comments

Comments
 (0)