| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + #ifndef INIT_SSH2 | ||
| 2 | + #define INIT_SSH2 | ||
| 3 | + | ||
| 4 | + void init_ssh2(); | ||
| 5 | + | ||
| 6 | + #endif | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + // We are initializing libssh2 from a separate .cc file to avoid ssize_t | ||
| 2 | + // redefinition conflicts caused by incliding both node.h and libssh2.h from | ||
| 3 | + // the same file (e.g. nodegit.cc) | ||
| 4 | + // | ||
| 5 | + // The redefinition can also be avoided by #defines but that is risky in case | ||
| 6 | + // the libraries depend on the different definitions. | ||
| 7 | + | ||
| 8 | + #include <libssh2.h> | ||
| 9 | + | ||
| 10 | + void init_ssh2() { | ||
| 11 | + libssh2_init(0); | ||
| 12 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ | |||
| 16 | 16 | "sources": [ | |
| 17 | 17 | "src/lock_master.cc", | |
| 18 | 18 | "src/nodegit.cc", | |
| 19 | + "src/init_ssh2.cc", | ||
| 19 | 20 | "src/promise_completion.cc", | |
| 20 | 21 | "src/wrapper.cc", | |
| 21 | 22 | "src/functions/copy.cc", | |
@@ -32,6 +33,8 @@ | |||
| 32 | 33 | ||
| 33 | 34 | "include_dirs": [ | |
| 34 | 35 | "vendor/libv8-convert", | |
| 36 | + "vendor/libssh2/include", | ||
| 37 | + "vendor/openssl/openssl/include", | ||
| 35 | 38 | "<!(node -e \"require('nan')\")" | |
| 36 | 39 | ], | |
| 37 | 40 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,15 @@ | |||
| 1 | 1 | // This is a generated file, modify: generate/templates/nodegit.cc. | |
| 2 | 2 | #include <v8.h> | |
| 3 | + | ||
| 3 | 4 | #include <node.h> | |
| 4 | 5 | #include <git2.h> | |
| 5 | 6 | #include <map> | |
| 6 | 7 | #include <algorithm> | |
| 7 | 8 | #include <set> | |
| 8 | 9 | ||
| 10 | + #include <openssl/crypto.h> | ||
| 11 | + | ||
| 12 | + #include "../include/init_ssh2.h" | ||
| 9 | 13 | #include "../include/lock_master.h" | |
| 10 | 14 | #include "../include/wrapper.h" | |
| 11 | 15 | #include "../include/promise_completion.h" | |
@@ -39,7 +43,35 @@ void LockMasterGetDiagnostics(const FunctionCallbackInfo<Value>& info) { | |||
| 39 | 43 | info.GetReturnValue().Set(result); | |
| 40 | 44 | } | |
| 41 | 45 | ||
| 46 | + static uv_mutex_t *opensslMutexes; | ||
| 47 | + | ||
| 48 | + void OpenSSL_LockingCallback(int mode, int type, const char *, int) { | ||
| 49 | + if (mode & CRYPTO_LOCK) { | ||
| 50 | + uv_mutex_lock(&opensslMutexes[type]); | ||
| 51 | + } else { | ||
| 52 | + uv_mutex_unlock(&opensslMutexes[type]); | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + unsigned long OpenSSL_IDCallback() { | ||
| 57 | + return (unsigned long)uv_thread_self(); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + void OpenSSL_ThreadSetup() { | ||
| 61 | + opensslMutexes=(uv_mutex_t *)malloc(CRYPTO_num_locks() * sizeof(uv_mutex_t)); | ||
| 62 | + | ||
| 63 | + for (int i=0; i<CRYPTO_num_locks(); i++) { | ||
| 64 | + uv_mutex_init(&opensslMutexes[i]); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + CRYPTO_set_locking_callback(OpenSSL_LockingCallback); | ||
| 68 | + CRYPTO_set_id_callback(OpenSSL_IDCallback); | ||
| 69 | + } | ||
| 70 | + | ||
| 42 | 71 | extern "C" void init(Local<v8::Object> target) { | |
| 72 | + // Initialize thread safety in openssl and libssh2 | ||
| 73 | + OpenSSL_ThreadSetup(); | ||
| 74 | + init_ssh2(); | ||
| 43 | 75 | // Initialize libgit2. | |
| 44 | 76 | git_libgit2_init(); | |
| 45 | 77 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,9 +9,19 @@ module.exports = function retrieveExternalDependencies() { | |||
| 9 | 9 | ||
| 10 | 10 | return new Promise(function(resolve, reject) { | |
| 11 | 11 | console.info("[nodegit] Configuring libssh2."); | |
| 12 | - cp.execFile( | ||
| 13 | - rooted("vendor/libssh2/") + "configure", | ||
| 14 | - {cwd: rooted("vendor/libssh2/")}, | ||
| 12 | + var opensslDir = rooted("vendor/openssl/openssl"); | ||
| 13 | + var newEnv = {}; | ||
| 14 | + Object.keys(process.env).forEach(function(key) { | ||
| 15 | + newEnv[key] = process.env[key]; | ||
| 16 | + }); | ||
| 17 | + newEnv.CPPFLAGS = newEnv.CPPFLAGS || ""; | ||
| 18 | + newEnv.CPPFLAGS += " -I" + path.join(opensslDir, "include"); | ||
| 19 | + newEnv.CPPFLAGS = newEnv.CPPFLAGS.trim(); | ||
| 20 | + | ||
| 21 | + cp.exec( | ||
| 22 | + rooted("vendor/libssh2/configure") + | ||
| 23 | + " --with-libssl-prefix=" + opensslDir, | ||
| 24 | + {cwd: rooted("vendor/libssh2/"), env: newEnv}, | ||
| 15 | 25 | function(err, stdout, stderr) { | |
| 16 | 26 | if (err) { | |
| 17 | 27 | console.error(err); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,11 @@ | |||
| 1 | 1 | var promisify = require("promisify-node"); | |
| 2 | 2 | var path = require("path"); | |
| 3 | 3 | var fs = require("fs"); | |
| 4 | - | ||
| 4 | + var cp = require("child_process"); | ||
| 5 | 5 | var prepareForBuild = require("./prepareForBuild"); | |
| 6 | 6 | ||
| 7 | 7 | var exec = promisify(function(command, opts, callback) { | |
| 8 | - return require("child_process").exec(command, opts, callback); | ||
| 8 | + return cp.exec(command, opts, callback); | ||
| 9 | 9 | }); | |
| 10 | 10 | ||
| 11 | 11 | var fromRegistry; | |
@@ -52,7 +52,9 @@ function installPrebuilt() { | |||
| 52 | 52 | ||
| 53 | 53 | function pathForTool(name) { | |
| 54 | 54 | var toolPath = path.resolve(".", "node_modules", ".bin", name); | |
| 55 | - toolPath = "\"" + toolPath + "\""; | ||
| 55 | + if (process.platform == "win32") { | ||
| 56 | + toolPath += ".cmd"; | ||
| 57 | + } | ||
| 56 | 58 | return toolPath; | |
| 57 | 59 | } | |
| 58 | 60 | ||
@@ -72,7 +74,8 @@ function build() { | |||
| 72 | 74 | var opts = { | |
| 73 | 75 | cwd: ".", | |
| 74 | 76 | maxBuffer: Number.MAX_VALUE, | |
| 75 | - env: process.env | ||
| 77 | + env: process.env, | ||
| 78 | + stdio: "inherit" | ||
| 76 | 79 | }; | |
| 77 | 80 | ||
| 78 | 81 | var builder = "node-gyp"; | |
@@ -104,26 +107,27 @@ function build() { | |||
| 104 | 107 | ||
| 105 | 108 | opts.env.HOME = path.join(home, ".nodegit-gyp"); | |
| 106 | 109 | ||
| 107 | - var cmd = [ | ||
| 108 | - pathForTool(builder), | ||
| 110 | + var cmd = pathForTool(builder); | ||
| 111 | + var args = [ | ||
| 109 | 112 | "rebuild", | |
| 110 | 113 | debug, | |
| 111 | 114 | target, | |
| 112 | 115 | distUrl | |
| 113 | 116 | ] | |
| 114 | 117 | .join(" ") | |
| 115 | - .trim(); | ||
| 116 | - | ||
| 117 | - return exec(cmd, opts) | ||
| 118 | - .then(function() { | ||
| 119 | - console.info("[nodegit] Compilation complete."); | ||
| 120 | - console.info("[nodegit] Completed installation successfully."); | ||
| 121 | - process.exitCode = 0; | ||
| 122 | - }, | ||
| 123 | - function(err, stderr) { | ||
| 124 | - console.error(err); | ||
| 125 | - console.error(stderr); | ||
| 118 | + .trim() | ||
| 119 | + .split(" "); | ||
| 120 | + return new Promise(function(resolve, reject) { | ||
| 121 | + var child = cp.spawn(cmd, args, opts); | ||
| 122 | + child.on("close", function(code) { | ||
| 123 | + console.log(code); | ||
| 124 | + if (code) { | ||
| 125 | + reject(code); | ||
| 126 | 126 | process.exitCode = 13; | |
| 127 | 127 | } | |
| 128 | - ); | ||
| 128 | + else { | ||
| 129 | + resolve(); | ||
| 130 | + } | ||
| 131 | + }); | ||
| 132 | + }); | ||
| 129 | 133 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments