diff --git a/Jakefile b/Jakefile index dc8070fd7514d..7b3e35350e211 100644 --- a/Jakefile +++ b/Jakefile @@ -235,14 +235,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu cmd = cmd + sources.join(" "); console.log(cmd + "\n"); - var ex = jake.createExec([cmd]); - // Add listeners for output and error - ex.addListener("stdout", function(output) { - process.stdout.write(output); - }); - ex.addListener("stderr", function(error) { - process.stderr.write(error); - }); + var ex = jake.createExec([cmd], {interactive: true}); ex.addListener("cmdEnd", function() { if (!useDebugMode && prefixes && fs.existsSync(outFile)) { for (var i in prefixes) { @@ -304,18 +297,9 @@ compileFile(processDiagnosticMessagesJs, file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson], function () { var cmd = "node " + processDiagnosticMessagesJs + " " + diagnosticMessagesJson; console.log(cmd); - var ex = jake.createExec([cmd]); - // Add listeners for output and error - ex.addListener("stdout", function(output) { - process.stdout.write(output); - }); - ex.addListener("stderr", function(error) { - process.stderr.write(error); - }); - ex.addListener("cmdEnd", function() { + exec(cmd, function() { complete(); }); - ex.run(); }, {async: true}) desc("Generates a diagnostic file in TypeScript based on an input JSON file"); @@ -476,14 +460,7 @@ desc("Builds the test infrastructure using the built compiler"); task("tests", ["local", run].concat(libraryTargets)); function exec(cmd, completeHandler) { - var ex = jake.createExec([cmd], {windowsVerbatimArguments: true}); - // Add listeners for output and error - ex.addListener("stdout", function(output) { - process.stdout.write(output); - }); - ex.addListener("stderr", function(error) { - process.stderr.write(error); - }); + var ex = jake.createExec([cmd], {windowsVerbatimArguments: true, interactive: true}); ex.addListener("cmdEnd", function() { if (completeHandler) { completeHandler(); @@ -677,13 +654,12 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() { var options = "--outdir " + temp + ' ' + loggedIOpath; var cmd = host + " " + LKGDirectory + compilerFilename + " " + options + " "; console.log(cmd + "\n"); - var ex = jake.createExec([cmd]); - ex.addListener("cmdEnd", function() { + + exec(cmd, function() { fs.renameSync(temp + '/harness/loggedIO.js', loggedIOJsPath); jake.rmRf(temp); complete(); }); - ex.run(); }, {async: true}); var instrumenterPath = harnessDirectory + 'instrumenter.ts'; @@ -694,9 +670,7 @@ desc("Builds an instrumented tsc.js"); task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function() { var cmd = host + ' ' + instrumenterJsPath + ' record iocapture ' + builtLocalDirectory + compilerFilename; console.log(cmd); - var ex = jake.createExec([cmd]); - ex.addListener("cmdEnd", function() { + exec(cmd, function() { complete(); }); - ex.run(); }, { async: true }); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 3f7e6362e1933..7379e6afe348a 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -152,7 +152,10 @@ module ts { } export function executeCommandLine(args: string[]): void { - var commandLine = parseCommandLine(args); + return executeCommand(parseCommandLine(args)); + } + + export function executeCommand(commandLine: ParsedCommandLine): void { var configFileName: string; // Configuration file name (if any) var configFileWatcher: FileWatcher; // Configuration file watcher var cachedProgram: Program; // Program cached from last compilation diff --git a/tests/perfsys.ts b/tests/perfsys.ts index 143d0d637d427..4c99337ab8f09 100644 --- a/tests/perfsys.ts +++ b/tests/perfsys.ts @@ -20,29 +20,9 @@ module perftest { export var getCurrentDirectory = ts.sys.getCurrentDirectory; var exit = ts.sys.exit; - var args = ts.sys.args; - // augment sys so first ts.executeCommandLine call will be finish silently ts.sys.write = (s: string) => { }; ts.sys.exit = (code: number) => { }; - ts.sys.args = [] - - export function restoreSys() { - ts.sys.args = args; - ts.sys.write = write; - } - - export function hasLogIOFlag() { - return args.length > 2 && args[0] === "--logio"; - } - - export function getArgsWithoutLogIOFlag() { - return args.slice(2); - } - - export function getArgsWithoutIOLogFile() { - return args.slice(1); - } var resolvePathLog: ts.Map = {}; @@ -54,22 +34,33 @@ module perftest { }; } - export function writeIOLog(fileNames: string[]) { - var path = args[1]; + export function writeIOLog(fileNames: string[], dstPath: string) { var log: IOLog = { fileNames: fileNames, resolvePath: resolvePathLog }; - writeFile(path, JSON.stringify(log)); + writeFile(dstPath, JSON.stringify(log)); } - export function prepare(): IO { - var log = JSON.parse(readFile(args[0])); + export function prepare(cmd: ts.ParsedCommandLine): IO { + var content = readFile(cmd.fileNames[0]); + if (content === undefined) { + throw new Error('Invalid file: ' + cmd.fileNames[0]) + } + try { + var log = JSON.parse(content); + } catch (err) { + write("Invalid IO log file, expecting JSON") + } + cmd.fileNames = [] var files: ts.Map = {}; - log.fileNames.forEach(f => { files[f] = readFile(f); }) - + log.fileNames.forEach(f => { + files[f] = readFile(f); + cmd.fileNames.push(f) + }) + ts.sys.createDirectory = (s: string) => { }; ts.sys.directoryExists = (s: string) => true; ts.sys.fileExists = (s: string) => true; @@ -96,7 +87,9 @@ module perftest { var out: string = ""; - ts.sys.write = (s: string) => { out += s; }; + ts.sys.write = (s: string) => { + out += s; + }; return { getOut: () => out, diff --git a/tests/perftsc.ts b/tests/perftsc.ts index e0189896a1521..6c56260be8ecf 100644 --- a/tests/perftsc.ts +++ b/tests/perftsc.ts @@ -2,7 +2,18 @@ /// // resolve all files used in this compilation -if (perftest.hasLogIOFlag()) { + +ts.optionDeclarations.push({ + name: "logio", + type: "string", + isFilePath: true +}) + +var commandLine = ts.parseCommandLine(ts.sys.args); +commandLine.options.diagnostics = true + +var logIoPath = commandLine.options['logio']; +if (logIoPath) { perftest.interceptIO(); var compilerHost: ts.CompilerHost = { @@ -10,7 +21,7 @@ if (perftest.hasLogIOFlag()) { var content = perftest.readFile(s); return content !== undefined ? ts.createSourceFile(s, content, v) : undefined; }, - getDefaultLibFilename: () => ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(perftest.getExecutingFilePath())), "lib.d.ts"), + getDefaultLibFileName: () => ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(perftest.getExecutingFilePath())), "lib.d.ts"), writeFile: (f: string, content: string) => { throw new Error("Unexpected operation: writeFile"); }, getCurrentDirectory: () => perftest.getCurrentDirectory(), getCanonicalFileName: (f: string) => ts.sys.useCaseSensitiveFileNames ? f : f.toLowerCase(), @@ -18,13 +29,13 @@ if (perftest.hasLogIOFlag()) { getNewLine: () => ts.sys.newLine }; - var commandLine = ts.parseCommandLine(perftest.getArgsWithoutLogIOFlag()); - var program = ts.createProgram(commandLine.filenames, commandLine.options, compilerHost); - var fileNames = program.getSourceFiles().map(f => f.filename); - perftest.writeIOLog(fileNames); + var program = ts.createProgram(commandLine.fileNames, commandLine.options, compilerHost); + var fileNames = program.getSourceFiles().map(f => f.fileName); + perftest.writeIOLog(fileNames, "" + logIoPath); } else { - var io = perftest.prepare(); - ts.executeCommandLine(perftest.getArgsWithoutIOLogFile()); + var io = perftest.prepare(commandLine); + ts.executeCommand(commandLine); + perftest.write(io.getOut()); }