UNPKG

mist

Version:
92 lines (82 loc) 2.28 kB
/* * Renders a resolver to a Ninja build file * * resolver: * A resolver, generated from a Mistfile */ var fs, os, path, spawn, tmp; path = require('path'); os = require('os'); tmp = require('tmp'); fs = require('fs'); spawn = (require('child_process')).spawn; module.exports.render = function(resolver) { var i, k, len, name, out, ref, ref1, ref2, target, targets, v, vars; targets = resolver.compile(); out = ["ninja_required_version = 1.2", "builddir = " + (path.join(resolver.rootDir, '.mist'))]; out.push2 = function(s) { return this.push(" " + s); }; ref = targets.commands; for (name in ref) { vars = ref[name]; out.push("rule " + name); for (k in vars) { v = vars[k]; out.push2(k + " = " + v); } } ref1 = targets.targets; for (i = 0, len = ref1.length; i < len; i++) { target = ref1[i]; out.push(['build', target.outputs, target.auxOutputs, ':', target.command.name, target.inputs, target.dependencies.length ? '|' : '', target.dependencies, target.orderDependencies.length ? '||' : '', target.orderDependencies].flatten().linearize()); ref2 = target.command.vars; for (k in ref2) { v = ref2[k]; out.push2(k + " = " + v); } } out.push(''); return out.join('\n'); }; module.exports.run = function(resolver, exArgs, proc, opts, exitcb) { var args, cb, rendered, tmpFile; if (exArgs == null) { exArgs = []; } if (proc == null) { proc = 'ninja'; } if (opts == null) { opts = { stdio: [null, process.stdout, process.stderr] }; } if (exitcb == null) { exitcb = process.exit; } rendered = module.exports.render(resolver); args = ['-v', '-w', 'dupbuild=err', '-C', resolver.rootDir]; switch (os.platform()) { case 'darwin' || 'linux': args.push('-f', '/dev/stdin'); cb = function(proc) { proc.stdin.write(rendered); return proc.stdin.end(); }; break; default: tmpFile = tmp.fileSync(); args.push('-f', tmpFile.name); fs.writeSync(tmpFile.fd, rendered); fs.closeSync(tmpFile.fd); } proc = spawn(proc, args.concat(exArgs), opts); if (exitcb) { proc.on('exit', exitcb); } if (cb) { return cb(proc); } }; //# sourceMappingURL=ninja.js.map