Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build args after -- in argv #235

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion bin/cmake-js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,20 @@ for (var key of _.keys(npmConfigData)) {

console.log(process.argv);

// forwards everything after '--' in argv as arguments to the build command
var buildArgs = [];
var hasSeenDoubleDash = false;
process.argv.forEach(function (arg) {
if (!hasSeenDoubleDash) {
hasSeenDoubleDash = arg === '--';
return;
}

buildArgs.push(arg);
});

var yargs = require("yargs")
.usage("CMake.js " + version + "\n\nUsage: $0 [<command>] [options]")
.usage("CMake.js " + version + "\n\nUsage: $0 [<command>] [options] [-- <build args>]")
.version(function () {
return version;
})
Expand Down Expand Up @@ -211,6 +223,7 @@ var options = {
runtimeVersion: argv.v,
arch: argv.a,
cMakeOptions: customOptions,
buildArgs: buildArgs,
silent: argv.i,
out: argv.O
};
Expand Down
6 changes: 6 additions & 0 deletions lib/cMake.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ CMake.prototype.getBuildCommand = function () {
if (this.options.target) {
command.push("--target", this.options.target);
}

if (this.options.buildArgs) {
command.push('--');
command = command.concat(this.options.buildArgs);
}

return Promise.resolve(command);
};

Expand Down
10 changes: 10 additions & 0 deletions tests/es6/testCases.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ let testCases = {

let command = yield buildSystem.getConfigureCommand();
assert.notEqual(command.indexOf("-Dfoo=bar"), -1, "custom options added");
}),
configureWithCustomBuildOptions: async(function*(options) {
options = _.extend({
directory: path.resolve(path.join(__dirname, "./prototype")),
buildArgs: ["-j7"]
}, options);
let buildSystem = new BuildSystem(options);

let command = yield buildSystem.getBuildCommand();
assert.notEqual(command.indexOf("-- -j7"), -1, "custom build options added");
})
};

Expand Down