@@ -48,7 +48,7 @@ function systemPath(parts) {
4848}
4949
5050// Will be used near the end to configure `node-gyp`.
51- var pythonPath = '/usr/bin/python' ;
51+ var pythonPath = "" ;
5252
5353var local = path . join . bind ( path , __dirname ) ;
5454
@@ -58,12 +58,7 @@ var paths = envOverride({
5858 libgit2 : local ( "vendor/libgit2/" ) ,
5959 libssh2 : local ( "vendor/libssh2/" ) ,
6060 http_parser : local ( "vendor/http_parser/" ) ,
61- sys : {
62- include : local ( "include/sys/" ) ,
63- src : local ( "src/sys/" ) ,
64- build : local ( "build/Release/obj.target/src/sys/" )
65- } ,
66- release : local ( "build/Release/" )
61+ release : local ( "build/Release/" ) ,
6762} ) ;
6863
6964// Load the package.json.
@@ -76,8 +71,7 @@ if (NODE_VERSION === 0.1) {
7671fse . ensureDir ( path . resolve ( __dirname , paths . release ) )
7772. then ( detectNodeWebkit . call ( null , __dirname ) )
7873. then ( fetch )
79- . then ( finish , compile )
80- . done ( )
74+ . then ( finish , compile ) ;
8175
8276function fetch ( ) {
8377 console . info ( "[nodegit] Fetching binary from S3." ) ;
@@ -104,83 +98,103 @@ function compile(err) {
10498
10599 console . info ( "[nodegit] Determining dependencies." ) ;
106100
107- return python ( )
108- . then ( getVendorLib ( "libgit2" , "https://github.com/libgit2/libgit2/tarball/" + pkg . libgit2 . sha ) )
109- . then ( getVendorLib ( "libssh2" , pkg . libssh2 . url ) )
110- . then ( getVendorLib ( "http_parser" , pkg . http_parser . url ) )
111- . then ( buildNative )
112- . then ( finish , fail ) ;
113-
101+ return Promise . all ( [
102+ python ( ) ,
103+ getVendorLib ( "libgit2" , "https://github.com/libgit2/libgit2/tarball/" + pkg . libgit2 . sha ) ,
104+ getVendorLib ( "libssh2" , pkg . libssh2 . url ) ,
105+ getVendorLib ( "http_parser" , pkg . http_parser . url ) ,
106+ guardGenerated ( )
107+ ] )
108+ . then ( buildNative )
109+ . then ( finish , fail ) ;
114110}
115111
116112function python ( ) {
117- return exec ( "which python2" )
113+ var pathFinderCommand = process . platform === "win32" ? "where" : "which" ;
114+
115+ return exec ( pathFinderCommand + " python2" )
118116 . then ( function ( which ) {
119117 return which ;
120118 } , function ( err ) {
121119 return null ;
122120 } )
123121 . then ( function ( path ) {
124- return path || exec ( "which python") ;
122+ return path || exec ( pathFinderCommand + " python") ;
125123 } )
126- . then ( function ( which ) {
127- return which ;
124+ . then ( function ( path ) {
125+ return path ;
128126 } , function ( err ) {
129127 return null ;
130128 } )
131129 . then ( function ( path ) {
132- pythonPath = path . trim ( ) ;
133- if ( ! pythonPath ) {
130+ if ( ! path ) {
134131 throw new Error ( "Python is required to build libgit2." ) ;
135132 }
133+ return path . trim ( ) ;
134+ } , function ( err ) {
135+ throw new Error ( "Error finding python." ) ;
136136 } )
137- . then ( function ( ) {
138- return exec ( pythonPath + " -V 2>&1" ) ;
137+ . then ( function ( path ) {
138+ pythonPath = path ;
139+ return exec ( path + " -V 2>&1" ) ;
139140 } )
140141 . then ( function ( version ) {
141- if ( version [ 1 ] . indexOf ( "Python 3" ) === 0 ) {
142+ if ( version . trim ( ) . indexOf ( "Python 3" ) === 0 ) {
142143 throw new Error ( "Incorrect version of Python, gyp requires < 3." ) ;
143144 }
144145 } ) ;
145146}
146147
147148function getVendorLib ( name , url ) {
148- return function ( ) {
149- var version = pkg [ name ] . sha || pkg [ name ] . version ;
150- console . info ( "[nodegit] Detecting vendor/" + name + "." ) ;
151- if ( fse . existsSync ( paths [ name ] + version ) ) {
152- console . info ( "[nodegit] vendor/" + name + " already exists." ) ;
153- return new Promise ( function ( resolve , reject ) { resolve ( ) } ) ;
154- }
155- else {
156- console . info ( "[nodegit] Removing outdated vendor/" + name + "." ) ;
157- return fse . remove ( paths [ name ] )
158- . then ( function ( ) {
159- return new Promise ( function ( resolve , reject ) {
160-
161- console . info ( "[nodegit] Fetching vendor/" + name + "." ) ;
149+ var version = pkg [ name ] . sha || pkg [ name ] . version ;
150+ console . info ( "[nodegit] Detecting vendor/" + name + "." ) ;
151+ if ( fse . existsSync ( paths [ name ] + version ) ) {
152+ console . info ( "[nodegit] vendor/" + name + " already exists." ) ;
153+ return Promise . resolve ( ) ;
154+ }
155+ else {
156+ console . info ( "[nodegit] Removing outdated vendor/" + name + "." ) ;
157+ return fse . remove ( paths [ name ] )
158+ . then ( function ( ) {
159+ return new Promise ( function ( resolve , reject ) {
162160
163- var extract = tar . Extract ( {
164- path : paths [ name ] ,
165- strip : true
166- } ) ;
161+ console . info ( "[nodegit] Fetching vendor/" + name + "." ) ;
167162
168- request . get ( url ) . pipe ( zlib . createUnzip ( ) ) . pipe ( extract )
169- . on ( "error" , reject )
170- . on ( "end" , resolve ) ;
163+ var extract = tar . Extract ( {
164+ path : paths [ name ] ,
165+ strip : true
171166 } ) ;
172- } ) . then ( function ( ) {
173- return fse . writeFile ( paths [ name ] + version , "" ) ;
174- } ) . then ( function ( ) {
175- if ( ( name == "libssh2" ) && ( process . platform !== "win32" ) ) {
176167
177- return exec ( paths [ name ] + "configure" , { cwd : paths [ name ] } ) ;
178- }
168+ request . get ( url ) . pipe ( zlib . createUnzip ( ) ) . pipe ( extract )
169+ . on ( "error" , reject )
170+ . on ( "end" , resolve ) ;
179171 } ) ;
180- }
172+ } ) . then ( function ( ) {
173+ return fse . writeFile ( paths [ name ] + version , "" ) ;
174+ } ) . then ( function ( ) {
175+ if ( ( name == "libssh2" ) && ( process . platform !== "win32" ) ) {
176+ return exec ( paths [ name ] + "configure" , { cwd : paths [ name ] } ) ;
177+ }
178+ } ) ;
181179 }
182180}
183181
182+ function guardGenerated ( ) {
183+ return Promise . all ( [
184+ fse . stat ( path . resolve ( __dirname , "src/" ) ) ,
185+ fse . stat ( path . resolve ( __dirname , "include/" ) )
186+ ] ) . then ( function ( ) {
187+ return Promise . resolve ( ) ;
188+ } , function ( ) {
189+ console . info ( "[nodegit] C++ files not found, generating now." ) ;
190+ console . info ( "[nodegit] Installing all devDependencies" ) ;
191+ return exec ( "npm install --ignore-scripts --dont-prepublish" )
192+ . then ( function ( ) {
193+ return exec ( "node generate" ) ;
194+ } ) ;
195+ } ) ;
196+ }
197+
184198function buildNative ( ) {
185199 return exec ( "cd " + __dirname ) . then ( function ( ) {
186200 if ( nodeWebkit ) {
@@ -221,7 +235,21 @@ function detectNodeWebkit(directory) {
221235
222236function finish ( ) {
223237 console . info ( "[nodegit] Completed installation successfully." ) ;
224- return Promise . resolve ( ) . done ( ) ;
238+ if ( ! buildOnly ) {
239+ console . info ( "[nodegit] Cleaning up" ) ;
240+ return Promise . all ( [
241+ fse . remove ( path . resolve ( __dirname , "src" ) ) ,
242+ fse . remove ( path . resolve ( __dirname , "include" ) ) ,
243+ fse . remove ( path . resolve ( __dirname , "generate/output" ) ) ,
244+ fse . remove ( path . resolve ( __dirname , paths . libgit2 ) ) ,
245+ fse . remove ( path . resolve ( __dirname , paths . libssh2 ) ) ,
246+ fse . remove ( path . resolve ( __dirname , paths . http_parser ) )
247+ // exec("npm prune --production")
248+ ] ) . done ( ) ;
249+ }
250+ else {
251+ return Promise . resolve ( ) . done ( ) ;
252+ }
225253}
226254
227255function fail ( message ) {
0 commit comments