From 36094e8d4721b050420dbf935fdad6149e2e754a Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Wed, 16 Sep 2015 09:38:49 -0400 Subject: [PATCH] Handle build failure --- lib/exe.js | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/exe.js b/lib/exe.js index d96677d..142af42 100644 --- a/lib/exe.js +++ b/lib/exe.js @@ -196,18 +196,37 @@ exports.compile = function (options, complete) { } }, - /** - * monkeypatch child_process.js so nexejs knows when it is a forked process - */ - function monkeyPatchChildProc(next) { - _monkeyPatchChildProcess(nodeCompiler, next); - }, + /** + * monkeypatch child_process.js so nexejs knows when it is a forked process + */ + function monkeyPatchChildProc(next) { + _monkeyPatchChildProcess(nodeCompiler, next); + }, + + /** + * If an old compiled executable exists in the Release directory, delete it. + * This lets us see if the build failed by checking the existence of this file later. + */ + + function cleanUpOldExecutable (next) { + fs.unlink(nodeCompiler.releasePath, function (err) { + if (err) { + if (err.code === "ENOENT") { + next(); + } else { + throw err; + } + } else { + next(); + } + }); + }, /** * compile the node application */ - function makeExe (next) { + function makeExecutable (next) { if(isWin) { _log("vcbuild [make stage]"); } else { @@ -224,6 +243,25 @@ exports.compile = function (options, complete) { mkdirp(path.dirname(options.output), function(){ next(); }); }, + /** + * Verify that the executable was compiled successfully + */ + + function checkThatExecutableExists (next) { + fs.access(nodeCompiler.releasePath, function (err) { + if (err) { + _log("error", + "The release executable has not been generated. " + + "This indicates a failure in the build process. " + + "There is likely additional information above." + ); + throw new Error("The release executable was not built ('" + nodeCompiler.releasePath + "')"); + } else { + next(); + } + }); + }, + /** * Copy the compilied binary to the output specified. */