Skip to content

Commit

Permalink
Add build args after -- in argv
Browse files Browse the repository at this point in the history
Fix typo (?)

Parse build args properly (hopefully)

Fix calling cmake with custom build args
  • Loading branch information
rivertam committed Feb 26, 2021
1 parent 9687dba commit 7a19137
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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.getConfigureCommand();
assert.notEqual(command.indexOf("-- -j7"), -1, "custom build options added");
})
};

Expand Down

0 comments on commit 7a19137

Please sign in to comment.