Skip to content

Commit

Permalink
ninja: harden cmd wrap mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
refack committed Feb 7, 2017
1 parent edcdb07 commit 305c7bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ gyp.main = function main(args, extra) {
gyp_binary: args[0],
home_dot_gyp: homeDotGyp,
root_targets: options.root_targets,
target_arch: cmdlineDefaultVariables['target_arch'] || ''
target_arch: cmdlineDefaultVariables['target_arch'] || 'ia32'
};

// Start with the default variables from the command line.
Expand Down
10 changes: 5 additions & 5 deletions lib/gyp/generator/ninja/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ Ninja.prototype.actionCmd = function actionCmd(base, toBase, cmds) {
return res;

// TODO(indutny): escape quotes in res
return `cmd.exe /s /c "${res}"`;
return `${gyp.platform.win.ninjaWrap} powershell -Command ${res.replace(/ & /g, ' ; ')}`;
};

Ninja.prototype.copies = function copies() {
Expand Down Expand Up @@ -558,6 +558,8 @@ function NinjaMain(targetList, targetDicts, data, params, config) {
}

NinjaMain.prototype.generate = function generate() {
if (process.platform === 'win32')
gyp.platform.win.setupNinjaWrapper(this.params['target_arch']);
this.vars();
this.rulesAndTargets();
this.defaults();
Expand Down Expand Up @@ -708,8 +710,7 @@ NinjaMain.prototype.rulesAndTargets = function rulesAndTargets() {
});

if (process.platform === 'win32') {
gyp.platform.win.ninjaRules(main, this.configDir,
this.options.generator_flags, this.params);
gyp.platform.win.ninjaRules(main, this.configDir, this.params);
} else {
gyp.platform.unix.ninjaRules(main, useCxx);
}
Expand Down Expand Up @@ -785,8 +786,7 @@ NinjaMain.prototype.build = function build() {
execSync('ninja -C ' + this.configDir, { stdio: 'inherit' });
};

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

Expand Down
22 changes: 11 additions & 11 deletions lib/gyp/platform/win.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ const process = gyp.bindings.process;

const win = exports;

win.ninjaRules = function ninjaRules(n, outDir, generatorFlags, params) {
let envFile = win.genEnvironment(
outDir,
generatorFlags['msvs_version'] || 'auto',
params['target_arch'] || 'ia32');
if (envFile)
envFile = ` -e ${envFile} `;
else
envFile = '';
win.getEnvFileName = function (target_arch) {
return `environment.${target_arch}`;
};

const ninjaWrap = `ninja -t msvc ${envFile}--`;
win.setupNinjaWrapper = function (target_arch) {
const envFile = win.getEnvFileName(target_arch);
this.ninjaWrap = `ninja -t msvc -e ${envFile} --`;
};

win.ninjaRules = function ninjaRules(n, outDir, params) {
win.genEnvironment(outDir, params['target_arch']);
const ninjaWrap = this.ninjaWrap;
n.rule('cc', {
deps: 'msvc',
// TODO(indutny): is /Fd$pdbname_c needed here?
Expand Down Expand Up @@ -498,8 +498,8 @@ win.genEnvironment = function genEnvironment(outDir, version, arch) {
}

const envBlock = formatEnvBlock(lines);
const envFile = 'environment.' + arch;

const envFile = win.getEnvFileName(target_arch);
fs.writeFileSync(path.join(outDir, envFile), envBlock);
return envFile;
};

0 comments on commit 305c7bf

Please sign in to comment.