@@ -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
2840if ( 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