Modify readme, implement cross-plat --python <loc> closes #94
This commit is contained in:
+73
-12
@@ -19,8 +19,10 @@ var _log = require("./log"),
|
||||
_monkeypatch = require("./monkeypatch");
|
||||
|
||||
var isWin = /^win/.test(process.platform);
|
||||
var isPy;
|
||||
|
||||
/**
|
||||
* Compiliation process.
|
||||
*/
|
||||
|
||||
exports.compile = function (options, complete) {
|
||||
@@ -28,11 +30,31 @@ exports.compile = function (options, complete) {
|
||||
var nodeCompiler, nexeEntryPath;
|
||||
|
||||
async.waterfall([
|
||||
/** check relevant options
|
||||
*
|
||||
*/
|
||||
function checkOpts (next) {
|
||||
/*
|
||||
* Have we been given a custom flag for python executable?
|
||||
*/
|
||||
if(options.python!=='python' && options.python!=="") {
|
||||
if(isWin) {
|
||||
isPy=options.python.replace(/\//gm, "\\"); // use windows file paths, batch is sensitive.
|
||||
} else {
|
||||
isPy=options.python;
|
||||
}
|
||||
|
||||
_log("set python as "+isPy);
|
||||
} else {
|
||||
isPy="python";
|
||||
}
|
||||
|
||||
next();
|
||||
},
|
||||
|
||||
/**
|
||||
* first download node
|
||||
*/
|
||||
|
||||
function downloadNode (next) {
|
||||
_downloadNode(options.nodeVersion, options.nodeTempDir, next);
|
||||
},
|
||||
@@ -104,11 +126,16 @@ exports.compile = function (options, complete) {
|
||||
*/
|
||||
|
||||
function makeExe (next) {
|
||||
_log("make");
|
||||
if(isWin) {
|
||||
_log("vcbuild [make stage]");
|
||||
} else {
|
||||
_log("make");
|
||||
}
|
||||
nodeCompiler.make(next);
|
||||
},
|
||||
|
||||
/**
|
||||
* we create the output directory if needed
|
||||
*/
|
||||
|
||||
function makeOutputDirectory (next) {
|
||||
@@ -116,11 +143,20 @@ exports.compile = function (options, complete) {
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy the compilied binary to the output specified.
|
||||
*/
|
||||
|
||||
function copyBinaryToOutput (next) {
|
||||
_log("cp %s %s", nodeCompiler.releasePath, options.output);
|
||||
ncp(nodeCompiler.releasePath, options.output, next);
|
||||
ncp(nodeCompiler.releasePath, options.output, function (err) {
|
||||
if (err) {
|
||||
console.log("* NOTICE * Failed to copy binary. Did the build fail?");
|
||||
throw err; // dump raw error object
|
||||
}
|
||||
_log('copied');
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
], complete);
|
||||
}
|
||||
@@ -228,7 +264,27 @@ function _getNodeCompiler (nodeFileDir, complete) {
|
||||
version: path.basename(nodeFileDir),
|
||||
releasePath: path.join(dir, "Release", "node.exe"),
|
||||
make: function(next) {
|
||||
var vcbuild = spawn("vcbuild.bat", ["nosign", "release"], { cwd: dir });
|
||||
// create a new env with minimal impact on old one
|
||||
var newEnv = process.env
|
||||
|
||||
if(isPy!=="python") {
|
||||
_log("vcbuild: python => "+isPy);
|
||||
|
||||
// replace vcbuild contents
|
||||
var data = fs.readFileSync(dir+"\\vcbuild.bat", 'utf8');
|
||||
var result = data.replace(/[\s]python/gm, isPy); // I can't regex
|
||||
var err = fs.writeFileSync(dir+"\\vcbuild.bat", result, 'utf8');
|
||||
if(err) throw err;
|
||||
|
||||
// temporary fix, should edit whatever is gening the project files at somepoint.
|
||||
newEnv.path = process.env.PATH+";"+path.dirname(isPy)
|
||||
}
|
||||
|
||||
// spawn a vcbuild process with our custom enviroment.
|
||||
var vcbuild = spawn("vcbuild.bat", ["nosign", "release"], {
|
||||
cwd: dir,
|
||||
env: newEnv
|
||||
});
|
||||
vcbuild.stdout.pipe(process.stdout);
|
||||
vcbuild.stderr.pipe(process.stderr);
|
||||
vcbuild.on("close", function() {
|
||||
@@ -242,7 +298,13 @@ function _getNodeCompiler (nodeFileDir, complete) {
|
||||
version: path.basename(nodeFileDir),
|
||||
releasePath: path.join(dir, "out", "Release", "node"),
|
||||
make: function (next) {
|
||||
var configure = spawn("./configure", [], { cwd: dir });
|
||||
var cfg = "./configure", configure;
|
||||
if(isPy !== "python") {
|
||||
configure = spawn(isPy, [cfg], { cwd: dir });
|
||||
} else {
|
||||
configure = spawn(cfg, [], { cwd: dir });
|
||||
}
|
||||
|
||||
configure.stdout.pipe(process.stdout);
|
||||
configure.stderr.pipe(process.stderr);
|
||||
configure.on("close", function () {
|
||||
@@ -281,7 +343,7 @@ function _monkeyPatchNodeConfig (compiler, complete) {
|
||||
},
|
||||
|
||||
/**
|
||||
* monkeypatch main entry point
|
||||
* monkeypatch main entry point
|
||||
*/
|
||||
|
||||
function (next) {
|
||||
@@ -299,7 +361,7 @@ function _monkeyPatchGyp (compiler, complete) {
|
||||
var gypPath = path.join(compiler.dir, "node.gyp");
|
||||
|
||||
_monkeypatch(
|
||||
gypPath,
|
||||
gypPath,
|
||||
function (content) {
|
||||
return ~content.indexOf("nexe.js");
|
||||
},
|
||||
@@ -317,7 +379,7 @@ function _monkeyPatchMainJs (compiler, complete) {
|
||||
var mainPath = path.join(compiler.dir, "src", "node.js");
|
||||
|
||||
_monkeypatch(
|
||||
mainPath,
|
||||
mainPath,
|
||||
function (content) {
|
||||
return ~content.indexOf("nexe");
|
||||
},
|
||||
@@ -395,9 +457,9 @@ function _logProgress (req) {
|
||||
req.on("response", function (resp) {
|
||||
|
||||
var len = parseInt(resp.headers["content-length"], 10),
|
||||
bar = new ProgressBar("[:bar]", {
|
||||
complete: "=",
|
||||
incomplete: " ",
|
||||
bar = new ProgressBar("[:bar]", {
|
||||
complete: "=",
|
||||
incomplete: " ",
|
||||
total: len,
|
||||
width: process.stdout.columns - 2
|
||||
});
|
||||
@@ -409,4 +471,3 @@ function _logProgress (req) {
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
module.exports = require("./exe");
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user