Skip to content

Commit

Permalink
Fix build on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
John Haley committed Jun 22, 2016
1 parent 9543011 commit 805edba
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 55 deletions.
2 changes: 1 addition & 1 deletion lifecycleScripts/configureLibssh2.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ if (require.main === module) {
console.log("nothing to do");
}
else {
module.exports();
module.exports().done();
}
}
65 changes: 32 additions & 33 deletions lifecycleScripts/install.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
var nodePreGypConstructor = require("node-pre-gyp");
var nodePreGyp = new nodePreGypConstructor.Run();
var path = require("path");

var buildFlags = require("../utils/buildFlags");
var exec = require("../utils/execPromise");

module.exports = function install() {
console.log("[nodegit] Running install script");

// we need to add 2 blank entires to help the parser later.
var argv = ["", "", "install"];
var nodePreGypCmd = path.join(
__dirname,
"..",
"node_modules",
".bin",
"node-pre-gyp"
);

if (process.platform === "win32") {
nodePreGypCmd += ".cmd";
}

var cmd = [nodePreGypCmd, "install"];

if (buildFlags.mustBuild) {
argv.push("--build-from-source");
console.info(
"[nodegit] Pre-built download disabled, building from source."
);
cmd.push("--build-from-source");

if (buildFlags.debugBuild) {
argv.push("--debug");
console.info("[nodegit] Building debug version.");
cmd.push("--debug");
}
}
else {
argv.push("--fallback-to-build");
cmd.push("--fallback-to-build");
}

nodePreGyp.parseArgv(argv);

function run() {
var command = nodePreGyp.todo.shift();
if (!command) {
return;
}

nodePreGyp.commands[command.name](command.args, function (err) {
if (err) {
console.error(command.name + " error");
console.error("stack", err.stack);
console.error("not ok");
console.log(err.message);
return process.exit(1);
}
var args_array = [].slice.call(arguments, 1);
if (args_array.length) {
console.log.apply(console, args_array);
}
// now run the next command in the queue
process.nextTick(run);
return exec(cmd.join(" "))
.then(function() {
console.info("[nodegit] Completed installation successfully.");
});
}

run();
};

// Called on the command line
if (require.main === module) {
module.exports();
module.exports()
.catch(function(e) {
console.error("[nodegit] ERROR - Could not finish install");
console.error(e);
process.exit(1);
});
}
53 changes: 32 additions & 21 deletions lifecycleScripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env node

var fse = require("fs-extra");
var path = require("path");
var child_process = require("child_process");

var exec = require("../utils/execPromise");
var buildFlags = require("../utils/buildFlags");

var rootPath = path.join(__dirname, "..");
Expand All @@ -16,25 +15,37 @@ function printStandardLibError() {
console.log("");
console.log("$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test");
console.log("$ sudo apt-get update");
console.log("$ sudo apt-get install libstdc++-4.9-dev");
}

console.log("$ sudo apt-get install libstdc++-4.9-dev");
child_process.exec("node dist/nodegit.js", function(error, stdout, stderr) {
if (stderr) {
if (process.pladtform !== "linux" && ~stderr.indexOf("libstdc++")) {
printStandardLibError();
}
module.exports = function install() {
return exec("node dist/nodegit.js")
.then(function() {
// Is we're using NodeGit from a package manager then let's clean up after
// ourselves when we install successfully.
if (!buildFlags.mustBuild) {
fse.removeSync(path.join(rootPath, "vendor"));
fse.removeSync(path.join(rootPath, "src"));
fse.removeSync(path.join(rootPath, "include"));
fse.removeSync(path.join(rootPath, "build/Release/*.a"));
fse.removeSync(path.join(rootPath, "build/Release/obj.target"));
}
});
};

return;
}
// Called on the command line
if (require.main === module) {
module.exports()
.catch(function(e) {
console.error("[nodegit] ERROR - Could not finish postinstall");

// Is we're using NodeGit from a package manager then let's clean up after
// ourselves when we install successfully.
if (!buildFlags.mustBuild) {
fse.removeSync(path.join(rootPath, "vendor"));
fse.removeSync(path.join(rootPath, "src"));
fse.removeSync(path.join(rootPath, "include"));
fse.removeSync(path.join(rootPath, "build/Release/*.a"));
fse.removeSync(path.join(rootPath, "build/Release/obj.target"));
}
});
if (process.pladtform !== "linux" && ~e.indexOf("libstdc++")) {
printStandardLibError();
}
else {
console.error(e);
}

process.exit(1);
});
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"fs-extra": "~0.26.2",
"lodash": "^4.13.1",
"nan": "^2.2.0",
"node-gyp": "^3.3.1",
"node-pre-gyp": "~0.6.15",
"promisify-node": "~0.3.0"
},
Expand Down

0 comments on commit 805edba

Please sign in to comment.