Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/2.5.1' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
cjntaylor committed Feb 9, 2018
2 parents af5c43c + dff02a2 commit f875727
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
88 changes: 44 additions & 44 deletions lib/ncmake.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const spawn = require('child_process').spawn;
const yargs = require('yargs');
const which = require('which');
const debug = require('debug')('ncmake');
var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;
var yargs = require('yargs');
var which = require('which');
var debug = require('debug')('ncmake');

// Main usage strings
let argparse = yargs
var argparse = yargs
.usage('$0 [options] <command>');

// Primary options
Expand Down Expand Up @@ -39,7 +39,7 @@ argparse = argparse
.command('install', 'Install the native addon');

// Deprecated commands from node-gyp
const compat = 'Deprecated node-gyp command (no-op)';
var compat = 'Deprecated node-gyp command (no-op)';
argparse = argparse
.command('list', compat)
.command('remove', compat);
Expand All @@ -59,19 +59,19 @@ argparse = argparse

// Use Ninja on platforms where it is installed as a default
// (since its significantly faster than make)
let ninja, generator = 'default';
var ninja, generator = 'default';
if(process.platform === 'darwin' || process.platform == 'linux') {
try {
ninja = which.sync('ninja');
generator = 'Ninja';
}
catch(err) {}
}
debug(`Selecting default generator "${generator}"`);
debug('Selecting default generator "' + generator + '"');

// Architecture detection parameters
const msvcRegex = /visual\s+studio/i;
const msvcArch = {
var msvcRegex = /visual\s+studio/i;
var msvcArch = {
x64: 'x64',
ia32: 'x86',
x32: 'x86'
Expand All @@ -98,15 +98,15 @@ function Warning(msg) { this.message = msg; }
// Catch-all function for node-gyp deprecated commands
function deprecated() {
return new Promise(function (resolve, reject) {
const warn = new Warning('node-gyp deprecated command invoked. ' +
var warn = new Warning('node-gyp deprecated command invoked. ' +
'This is not supported in node-cmake, consider updating your build');
warn.code = 0; // Exit cleanly (for tools that still use this command)
reject(warn);
});
}

// The list of accepted commands (mirror node-gyp's API)
const commands = {
var commands = {
help: function () {
return new Promise(function (resolve) {
argparse.showHelp();
Expand All @@ -115,14 +115,14 @@ const commands = {
},
distclean: function (argv, cmake) {
return new Promise(function (resolve, reject) {
const args = ['-E', 'remove_directory', argv.output];
var args = ['-E', 'remove_directory', argv.output];
debug('Execute', cmake, args);
const distclean = spawn(cmake, args, {
var distclean = spawn(cmake, args, {
stdio: 'inherit'
});
function handleError(code) {
if(code !== 0) { // An Error object will also not equal 0
const err = new Error('Unable to remove build directory');
var err = new Error('Unable to remove build directory');
err.code = 8;
return reject(err);
}
Expand All @@ -134,14 +134,14 @@ const commands = {
},
clean: function (argv, cmake) {
// Run CMake clean if the project has been "configured"
const args = ['--build', argv.output, '--target', 'clean'];
var args = ['--build', argv.output, '--target', 'clean'];
args.push('--config', (argv.debug) ? 'Debug' : 'Release');
return new Promise(function (resolve, reject) {
fs.exists(path.join(argv.output, 'CMakeCache.txt'), function (exists) {
if(exists) {
// Silently clean the project, do nothing on faiure (no-op)
debug('Execute', cmake, args);
const clean = spawn(cmake, args, {
var clean = spawn(cmake, args, {
stdio: 'ignore'
});
function handleError(code) { return resolve(); }
Expand All @@ -153,7 +153,7 @@ const commands = {
});
},
configure: function (argv, cmake) {
const args = ['-DCMAKE_BUILD_TYPE=' + ((argv.debug) ? 'Debug' : 'Release')];
var args = ['-DCMAKE_BUILD_TYPE=' + ((argv.debug) ? 'Debug' : 'Release')];

// Under MSVC specifically, attempt to pass the architecture flag of the current version
// of node to cmake. This should attempt to use an MSVC that will compile node modules
Expand All @@ -174,14 +174,14 @@ const commands = {

return new Promise(function (resolve, reject) {
// Use CMake as a cross-platform mkdir to create the build directory
const margs = ['-E', 'make_directory', argv.output];
var margs = ['-E', 'make_directory', argv.output];
debug('Execute', cmake, margs);
const mkdir = spawn(cmake, margs, {
var mkdir = spawn(cmake, margs, {
stdio: 'inherit'
});
function handleError(code) {
if(code !== 0) {
const err = new Error('Unable to create build directory');
var err = new Error('Unable to create build directory');
err.code = 3;
return reject(err);
}
Expand All @@ -193,13 +193,13 @@ const commands = {
return new Promise(function (resolve, reject) {
// Run CMake to configure the project
debug('Execute', cmake, args);
const configure = spawn(cmake, args, {
var configure = spawn(cmake, args, {
cwd: path.resolve(argv.output),
stdio: 'inherit'
});
function handleError(code) {
if(code !== 0) {
const err = new Error('Unable to configure project');
var err = new Error('Unable to configure project');
err.code = 4;
return reject(err);
}
Expand All @@ -212,17 +212,17 @@ const commands = {
},
build: function (argv, cmake) {
// Run CMake build to build the project (generator agnostic)
const args = ['--build', argv.output, '--config', (argv.debug) ? 'Debug' : 'Release'];
var args = ['--build', argv.output, '--config', (argv.debug) ? 'Debug' : 'Release'];
return new Promise(function (resolve, reject) {
fs.exists(path.join(argv.output, 'CMakeCache.txt'), function (exists) {
if(exists) {
debug('Execute', cmake, args);
const build = spawn(cmake, args, {
var build = spawn(cmake, args, {
stdio: 'inherit'
});
function handleError(code) {
if(code !== 0) {
const err = new Error('Build failed');
var err = new Error('Build failed');
err.code = 7;
return reject(err);
}
Expand All @@ -232,7 +232,7 @@ const commands = {
build.on('error', handleError);
}
else {
const err = new Error('Project is not configured, ' +
var err = new Error('Project is not configured, ' +
'Run \'configure\' command first');
err.code = 6;
return reject(err);
Expand All @@ -253,23 +253,23 @@ const commands = {
update: function (argv, cmake) {
return new Promise(function (resolve, reject) {
// The CMake script is relative to this utility when installed
const source = path.resolve(path.join(__dirname, '..', 'NodeJS.cmake'));
const output = path.resolve('NodeJS.cmake');
const rd = fs.createReadStream(source);
var source = path.resolve(path.join(__dirname, '..', 'NodeJS.cmake'));
var output = path.resolve('NodeJS.cmake');
var rd = fs.createReadStream(source);
rd.on('error', function (rerr) {
const err = new Error('Unable to read NodeJS.cmake');
var err = new Error('Unable to read NodeJS.cmake');
err.code = 9;
reject(err);
});
const wr = fs.createWriteStream(output);
var wr = fs.createWriteStream(output);
wr.on('error', function (rerr) {
const err = new Error('Unable to write NodeJS.cmake');
var err = new Error('Unable to write NodeJS.cmake');
err.code = 9;
reject(err);
});
wr.on('close', function (rerr) {
if(rerr) {
const err = new Error('Unknown I/O error');
var err = new Error('Unknown I/O error');
err.code = 9;
reject(err);
}
Expand All @@ -280,20 +280,20 @@ const commands = {
},
install: function (argv, cmake) {
// Run CMake build to install the project (generator agnostic)
const args = [
var args = [
'--build', argv.output, '--config', (argv.debug) ? 'Debug' : 'Release',
'--target', 'install'
];
return new Promise(function (resolve, reject) {
fs.exists(path.join(argv.output, 'CMakeCache.txt'), function (exists) {
if (exists) {
debug('Execute', cmake, args);
const build = spawn(cmake, args, {
var build = spawn(cmake, args, {
stdio: 'inherit'
});
function handleError(code) {
if (code !== 0) {
const err = new Error('Build failed');
var err = new Error('Build failed');
err.code = 7;
return reject(err);
}
Expand All @@ -303,7 +303,7 @@ const commands = {
build.on('error', handleError);
}
else {
const err = new Error('Project is not configured, ' +
var err = new Error('Project is not configured, ' +
'Run \'configure\' command first');
err.code = 6;
return reject(err);
Expand All @@ -316,7 +316,7 @@ const commands = {
};

// Find the cmake binary on the user's path
let cmake;
var cmake;
try {
cmake = which.sync('cmake');
}
Expand All @@ -326,13 +326,13 @@ catch(e) {
}

// Finalize command line arguments
const argv = argparse.argv;
var argv = argparse.argv;
debug('Arguments', argv);

// Parse the first plain-argument as the command to execute
const cmd = argparse.argv._[0].toLowerCase();
var cmd = argparse.argv._[0].toLowerCase();
debug('Command', cmd);
const func = commands[cmd];
var func = commands[cmd];
((func) ? func(argv, cmake) : Promise.reject(
new Error('Invalid command \'' + cmd + '\'')
))
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "node-cmake",
"author": "Colin Taylor <cjntaylor@gmail.com>",
"version": "2.5.0",
"version": "2.5.1",
"description": "A CMake-based build system for node.js native modules",
"keywords": [
"cmake",
Expand Down

0 comments on commit f875727

Please sign in to comment.