Skip to content

Commit

Permalink
ninja: build with either ninja.js or ninja binary
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Jul 1, 2016
1 parent 5cd94fc commit 8616418
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 2 additions & 0 deletions bin/gyp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ const gyp = require('../');
// TEMPORARY MEASURE
process.stdout._handle.setBlocking(true);
const code = gyp.main(process.argv.slice(1));
if (code === null)
return;
process.exit(code);
7 changes: 5 additions & 2 deletions lib/gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,19 @@ gyp.main = function main(args, extra) {
* need to have dependencies defined before dependents reference them should
* generate targets in the order specified in flat_list.
*/
generator.generateOutput(flatList, targets, data, params);
const out = generator.generateOutput(flatList, targets, data, params);

if (options.configs.length !== 0) {
let validConfigs = targets[flatList[0]]['configurations'];
for (let i = 0; i < options.configs.length; i++) {
const conf = options.configs[i];
if (!validConfigs[conf])
throw new Error(`Invalid config specified via --build: ${conf}`);

out[conf].build();
}
generator.performBuild(data, options.configs, params);

return null;
}

return 0;
Expand Down
21 changes: 18 additions & 3 deletions lib/gyp/generator/ninja/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const gyp = require('../../../gyp');
const Writer = require('./writer');

const execSync = gyp.bindings.execSync;
const path = gyp.bindings.path;
const process = gyp.bindings.process;

Expand Down Expand Up @@ -717,19 +718,33 @@ NinjaMain.prototype.defaults = function defaults() {
main.finalize();
};

NinjaMain.prototype.build = function build() {
try {
execSync('ninja -C ' + this.configDir, {
stdio: 'inherit'
});
return;
} catch (e) {
if (!/not found/i.test(e.message))
throw e;

require('ninja.js').cli.run([ 'node', 'ninja.js', '-C', this.configDir ]);
}
};

exports.generateOutput = function generateOutput(targetList, targetDicts, data,
params) {
if (targetList.length === 0)
throw new Error('No targets to build!');

const configs = Object.keys(targetDicts[targetList[0]].configurations);

const res = {};
configs.forEach((config) => {
const main = new NinjaMain(targetList, targetDicts, data, params, config);
main.generate();
res[config] = main;
});
};

exports.performBuild = function performBuild() {
throw new Error('Not implemented');
return res;
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"mocha": "^2.5.3",
"rimraf": "^2.5.2"
},
"optionalDependencies": {
"ninja.js": "^1.0.10"
},
"dependencies": {
"mkdirp": "^0.5.1",
"parser-base": "^1.0.0",
Expand Down

0 comments on commit 8616418

Please sign in to comment.