11var cp = require ( "child_process" ) ;
2+ var fse = require ( 'fs-extra' ) ;
23var path = require ( "path" ) ;
3- var rooted = function ( dir ) {
4- var fullPath = path . join ( __dirname , ".." , dir ) ;
5- var escapedPathForShell = fullPath . replace ( / / g, "\\ " ) ;
6- return escapedPathForShell ;
7- } ;
4+
5+ const libssh2VendorDirectory = path . resolve ( __dirname , ".." , "vendor" , "libssh2" ) ;
6+ const libssh2ConfigureScript = path . join ( libssh2VendorDirectory , "configure" ) ;
7+ const libssh2StaticConfigDirectory = path . resolve ( __dirname , ".." , "vendor" , "static_config" , "libssh2" ) ;
88
99module . exports = function retrieveExternalDependencies ( ) {
10- // Do not configure on Windows
11- if ( process . platform === "win32" ) {
12- return Promise . resolve ( "" ) ;
10+ console . info ( "[nodegit] Configuring libssh2." ) ;
11+
12+ // Copy Windows / Mac preconfigured files
13+ if ( process . platform === "win32" || process . platform === "darwin" ) {
14+ return fse . copy (
15+ path . join ( libssh2StaticConfigDirectory , process . platform ) ,
16+ path . join ( libssh2VendorDirectory , process . platform )
17+ ) ;
1318 }
1419
20+ // Run the `configure` script on Linux
1521 return new Promise ( function ( resolve , reject ) {
16- console . info ( "[nodegit] Configuring libssh2." ) ;
22+
1723 var opensslDir = process . argv [ 2 ] ;
1824 var isElectron = process . argv [ 3 ] === "1" ;
1925 var opensslIncludes = isElectron ? path . join ( opensslDir , "includes" ) : opensslDir ;
2026
2127 var newEnv = { } ;
22-
23- // For some magic reason, MacOS fails to build if we copy over the current environment variables, but Linux
24- // builds fail if we DON'T copy over the current environment variables
25- if ( process . platform !== "darwin" ) {
26- Object . keys ( process . env ) . forEach ( function ( key ) {
27- newEnv [ key ] = process . env [ key ] ;
28- } ) ;
29- }
28+ Object . keys ( process . env ) . forEach ( function ( key ) {
29+ newEnv [ key ] = process . env [ key ] ;
30+ } ) ;
3031
3132 newEnv . CPPFLAGS = newEnv . CPPFLAGS || "" ;
3233 newEnv . CPPFLAGS += ` -I${ opensslIncludes } ` ;
@@ -38,8 +39,11 @@ module.exports = function retrieveExternalDependencies() {
3839 }
3940
4041 cp . exec (
41- rooted ( "vendor/libssh2/configure" ) + maybeLibsslPrefix ,
42- { cwd : rooted ( "vendor/libssh2/" ) , env : newEnv } ,
42+ libssh2ConfigureScript + maybeLibsslPrefix ,
43+ {
44+ cwd : libssh2VendorDirectory ,
45+ env : newEnv
46+ } ,
4347 function ( err , stdout , stderr ) {
4448 if ( err ) {
4549 console . error ( err ) ;
0 commit comments