Skip to content

Commit

Permalink
Run jake in interactive mode so output isn't lost.
Browse files Browse the repository at this point in the history
Fix jake perftsc
  • Loading branch information
jbondc committed Feb 17, 2015
1 parent cbeea38 commit 13de248
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 69 deletions.
38 changes: 6 additions & 32 deletions Jakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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';
Expand All @@ -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 });
5 changes: 4 additions & 1 deletion src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 21 additions & 28 deletions tests/perfsys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> = {};

Expand All @@ -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 = <IOLog>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 = <IOLog>JSON.parse(content);
} catch (err) {
write("Invalid IO log file, expecting JSON")
}

cmd.fileNames = []
var files: ts.Map<string> = {};
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;
Expand All @@ -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,
Expand Down
27 changes: 19 additions & 8 deletions tests/perftsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,40 @@
/// <reference path="..\src\compiler\tsc.ts"/>

// 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 = {
getSourceFile: (s, v) => {
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(),
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
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());
}

0 comments on commit 13de248

Please sign in to comment.