2014-05-30 20:36:29 +04:00
|
|
|
var path = require('path');
|
|
|
|
var fs = require('fs');
|
2014-06-04 06:20:33 +04:00
|
|
|
var cp = require('child_process');
|
|
|
|
var execFile = cp.execFile;
|
2014-06-04 22:09:50 +04:00
|
|
|
var pythonExecutable = process.env.PYTHON;
|
2014-05-30 20:36:29 +04:00
|
|
|
|
2014-06-04 06:20:33 +04:00
|
|
|
module.exports = function(cb) {
|
2014-05-30 20:21:26 +04:00
|
|
|
verifyNode();
|
2014-06-04 06:20:33 +04:00
|
|
|
verifyPython27(cb);
|
2014-05-30 20:21:26 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
function verifyNode() {
|
|
|
|
var nodeVersion = process.versions.node.split('.');
|
|
|
|
var nodeMajorVersion = +nodeVersion[0];
|
|
|
|
var nodeMinorVersion = +nodeVersion[1];
|
|
|
|
if (nodeMajorVersion === 0 && nodeMinorVersion < 10) {
|
|
|
|
console.warn("node v0.10 is required to build Atom.");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 06:20:33 +04:00
|
|
|
function verifyPython27(cb) {
|
2014-06-04 22:44:52 +04:00
|
|
|
if (false && process.platform !== 'win32') {
|
2014-06-04 06:20:33 +04:00
|
|
|
cb();
|
2014-06-04 21:55:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-06-04 22:09:50 +04:00
|
|
|
if (!pythonExecutable) {
|
2014-05-30 20:21:26 +04:00
|
|
|
var systemDrive = process.env.SystemDrive || 'C:\\';
|
2014-06-04 22:44:52 +04:00
|
|
|
pythonExecutable = path.join(systemDrive, 'Python27', 'python.exe');
|
2014-06-04 06:20:33 +04:00
|
|
|
|
2014-06-04 22:44:52 +04:00
|
|
|
if (!fs.existsSync(pythonExecutable)) {
|
2014-06-04 06:20:33 +04:00
|
|
|
pythonExecutable = 'python';
|
|
|
|
}
|
2014-06-04 21:55:10 +04:00
|
|
|
}
|
2014-05-30 20:21:26 +04:00
|
|
|
|
2014-06-04 06:20:33 +04:00
|
|
|
checkPythonVersion(pythonExecutable, cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkPythonVersion (python, cb) {
|
2014-06-04 22:10:14 +04:00
|
|
|
var pythonHelpMessage = "Set the PYTHON env var to '/path/to/Python27/python.exe' if your python is installed in a non-default location.";
|
2014-06-04 06:20:33 +04:00
|
|
|
|
|
|
|
execFile(python, ['-c', 'import platform; print(platform.python_version());'], { env: process.env }, function (err, stdout) {
|
|
|
|
if (err) {
|
2014-06-04 22:10:14 +04:00
|
|
|
console.log("Python 2.7 is required to build Atom. An error occured when checking for python '" + err + "'");
|
|
|
|
console.log(pythonHelpMessage);
|
2014-05-30 20:21:26 +04:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2014-06-04 06:20:33 +04:00
|
|
|
|
2014-06-04 22:10:14 +04:00
|
|
|
var version = stdout.trim();
|
2014-06-04 06:20:33 +04:00
|
|
|
if (~version.indexOf('+')) {
|
2014-06-04 22:10:14 +04:00
|
|
|
version = version.replace(/\+/g, '');
|
2014-06-04 06:20:33 +04:00
|
|
|
}
|
|
|
|
if (~version.indexOf('rc')) {
|
2014-06-04 22:10:14 +04:00
|
|
|
version = version.replace(/rc(.*)$/ig, '');
|
2014-06-04 06:20:33 +04:00
|
|
|
}
|
|
|
|
|
2014-06-04 22:10:14 +04:00
|
|
|
// Atom requires python 2.7 or higher (but not python 3) for node-gyp
|
2014-06-04 06:20:33 +04:00
|
|
|
var versionArray = version.split('.').map(function(num) { return +num; });
|
2014-06-04 22:10:14 +04:00
|
|
|
var goodPythonVersion = (versionArray[0] === 2 && versionArray[1] >= 7);
|
2014-06-04 06:20:33 +04:00
|
|
|
if (!goodPythonVersion) {
|
2014-06-04 22:10:14 +04:00
|
|
|
console.log("Python 2.7 is required to build Atom. '" + python + "' returns version " + version);
|
|
|
|
console.log(pythonHelpMessage);
|
2014-06-04 06:20:33 +04:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, if we've gotten this far, callback to resume the install process.
|
|
|
|
cb();
|
|
|
|
});
|
2014-05-30 20:21:26 +04:00
|
|
|
}
|