@@ -15,7 +15,7 @@ var rimraf = require('rimraf');
1515// ENV variables:
1616//
1717// PKG: Location of `package.json` sans `.json`.
18- // LIBGIT2: Location of libgit2 source.
18+ // LIBGIT2: Location of libgit2 source.
1919// BUILD: Location of nodegit build directory.
2020function envOverride ( obj ) {
2121 // Look through all keys.
@@ -45,6 +45,7 @@ var local = path.join.bind(path, __dirname);
4545var paths = envOverride ( {
4646 pkg : local ( 'package' ) ,
4747 libgit2 : local ( 'vendor/libgit2/' ) ,
48+ libssh2 : local ( 'vendor/libssh2/' ) ,
4849 sys : {
4950 include : local ( 'include/sys/' ) ,
5051 src : local ( 'src/sys/' ) ,
@@ -75,7 +76,7 @@ var dependencies = Q.allSettled([
7576 if ( ! python ) {
7677 throw new Error ( 'Python is required to build libgit2.' ) ;
7778 }
78-
79+
7980 // Now lets check the Python version to ensure it's < 3.
8081 return Q . nfcall ( exec , python + ' --version' ) . then ( function ( version ) {
8182 if ( version [ 1 ] . indexOf ( 'Python 3' ) === 0 ) {
@@ -94,7 +95,7 @@ var dependencies = Q.allSettled([
9495 } ) . fail ( function ( ) {
9596 console . info ( '[nodegit] Removing outdated vendor/libgit2.' ) ;
9697
97- // This directory is outdated, remove.
98+ // This directory is outdated, remove.
9899 throw Q . ninvoke ( rimraf , null , paths . libgit2 ) ;
99100 } ) ;
100101} )
@@ -105,7 +106,7 @@ var dependencies = Q.allSettled([
105106 console . info ( '[nodegit] Fetching vendor/libgit2.' ) ;
106107
107108 var url = 'https://github.com/libgit2/libgit2/tarball/' + pkg . libgit2 . sha ;
108-
109+
109110 var extract = tar . Extract ( {
110111 path : paths . libgit2 ,
111112 strip : true
@@ -120,6 +121,41 @@ var dependencies = Q.allSettled([
120121 } ) ;
121122} )
122123
124+ // Grab libssh2 if needed
125+ . then ( function ( ) {
126+ console . info ( '[nodegit] Detecting vendor/libssh2.' ) ;
127+
128+ return Q . ninvoke ( fs , 'stat' , paths . libssh2 ) . then ( function ( ) {
129+ return Q . ninvoke ( fs , 'stat' , paths . libssh2 + pkg . libssh2 . version ) ;
130+ } ) . fail ( function ( ) {
131+ console . info ( '[nodegit] Removing outdated vendor/libssh2.' ) ;
132+
133+ // This directory is outdated, remove.
134+ throw Q . ninvoke ( rimraf , null , paths . libssh2 ) ;
135+ } ) ;
136+ } )
137+
138+ // If the directory already exists, no need to refetch.
139+ . fail ( function ( ) {
140+ // Otherwise fetch the libssh2 source.
141+ console . info ( '[nodegit] Fetching vendor/libssh2.' ) ;
142+
143+ var url = pkg . libssh2 . url ;
144+
145+ var extract = tar . Extract ( {
146+ path : paths . libssh2 ,
147+ strip : true
148+ } ) ;
149+
150+ // First extract from Zlib and then extract from Tar.
151+ var expand = request . get ( url ) . pipe ( zlib . createUnzip ( ) ) . pipe ( extract ) ;
152+
153+ return Q . ninvoke ( expand , 'on' , 'end' ) . then ( function ( ) {
154+ // Write out a sha file for testing in the future.
155+ return Q . ninvoke ( fs , 'writeFile' , paths . libssh2 + pkg . libssh2 . version , '' ) ;
156+ } ) ;
157+ } )
158+
123159// Build the native module using node-gyp.
124160. then ( function ( ) {
125161 console . info ( '[nodegit] Building native node module.' ) ;
0 commit comments