Skip to content

Commit 13de248

Browse files
author
jbondc
committed
Run jake in interactive mode so output isn't lost.
Fix jake perftsc
1 parent cbeea38 commit 13de248

File tree

4 files changed

+50
-69
lines changed

4 files changed

+50
-69
lines changed

Diff for: Jakefile

+6-32
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
235235
cmd = cmd + sources.join(" ");
236236
console.log(cmd + "\n");
237237

238-
var ex = jake.createExec([cmd]);
239-
// Add listeners for output and error
240-
ex.addListener("stdout", function(output) {
241-
process.stdout.write(output);
242-
});
243-
ex.addListener("stderr", function(error) {
244-
process.stderr.write(error);
245-
});
238+
var ex = jake.createExec([cmd], {interactive: true});
246239
ex.addListener("cmdEnd", function() {
247240
if (!useDebugMode && prefixes && fs.existsSync(outFile)) {
248241
for (var i in prefixes) {
@@ -304,18 +297,9 @@ compileFile(processDiagnosticMessagesJs,
304297
file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson], function () {
305298
var cmd = "node " + processDiagnosticMessagesJs + " " + diagnosticMessagesJson;
306299
console.log(cmd);
307-
var ex = jake.createExec([cmd]);
308-
// Add listeners for output and error
309-
ex.addListener("stdout", function(output) {
310-
process.stdout.write(output);
311-
});
312-
ex.addListener("stderr", function(error) {
313-
process.stderr.write(error);
314-
});
315-
ex.addListener("cmdEnd", function() {
300+
exec(cmd, function() {
316301
complete();
317302
});
318-
ex.run();
319303
}, {async: true})
320304

321305
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");
476460
task("tests", ["local", run].concat(libraryTargets));
477461

478462
function exec(cmd, completeHandler) {
479-
var ex = jake.createExec([cmd], {windowsVerbatimArguments: true});
480-
// Add listeners for output and error
481-
ex.addListener("stdout", function(output) {
482-
process.stdout.write(output);
483-
});
484-
ex.addListener("stderr", function(error) {
485-
process.stderr.write(error);
486-
});
463+
var ex = jake.createExec([cmd], {windowsVerbatimArguments: true, interactive: true});
487464
ex.addListener("cmdEnd", function() {
488465
if (completeHandler) {
489466
completeHandler();
@@ -677,13 +654,12 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() {
677654
var options = "--outdir " + temp + ' ' + loggedIOpath;
678655
var cmd = host + " " + LKGDirectory + compilerFilename + " " + options + " ";
679656
console.log(cmd + "\n");
680-
var ex = jake.createExec([cmd]);
681-
ex.addListener("cmdEnd", function() {
657+
658+
exec(cmd, function() {
682659
fs.renameSync(temp + '/harness/loggedIO.js', loggedIOJsPath);
683660
jake.rmRf(temp);
684661
complete();
685662
});
686-
ex.run();
687663
}, {async: true});
688664

689665
var instrumenterPath = harnessDirectory + 'instrumenter.ts';
@@ -694,9 +670,7 @@ desc("Builds an instrumented tsc.js");
694670
task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function() {
695671
var cmd = host + ' ' + instrumenterJsPath + ' record iocapture ' + builtLocalDirectory + compilerFilename;
696672
console.log(cmd);
697-
var ex = jake.createExec([cmd]);
698-
ex.addListener("cmdEnd", function() {
673+
exec(cmd, function() {
699674
complete();
700675
});
701-
ex.run();
702676
}, { async: true });

Diff for: src/compiler/tsc.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ module ts {
152152
}
153153

154154
export function executeCommandLine(args: string[]): void {
155-
var commandLine = parseCommandLine(args);
155+
return executeCommand(parseCommandLine(args));
156+
}
157+
158+
export function executeCommand(commandLine: ParsedCommandLine): void {
156159
var configFileName: string; // Configuration file name (if any)
157160
var configFileWatcher: FileWatcher; // Configuration file watcher
158161
var cachedProgram: Program; // Program cached from last compilation

Diff for: tests/perfsys.ts

+21-28
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,9 @@ module perftest {
2020
export var getCurrentDirectory = ts.sys.getCurrentDirectory;
2121
var exit = ts.sys.exit;
2222

23-
var args = ts.sys.args;
24-
2523
// augment sys so first ts.executeCommandLine call will be finish silently
2624
ts.sys.write = (s: string) => { };
2725
ts.sys.exit = (code: number) => { };
28-
ts.sys.args = []
29-
30-
export function restoreSys() {
31-
ts.sys.args = args;
32-
ts.sys.write = write;
33-
}
34-
35-
export function hasLogIOFlag() {
36-
return args.length > 2 && args[0] === "--logio";
37-
}
38-
39-
export function getArgsWithoutLogIOFlag() {
40-
return args.slice(2);
41-
}
42-
43-
export function getArgsWithoutIOLogFile() {
44-
return args.slice(1);
45-
}
4626

4727
var resolvePathLog: ts.Map<string> = {};
4828

@@ -54,22 +34,33 @@ module perftest {
5434
};
5535
}
5636

57-
export function writeIOLog(fileNames: string[]) {
58-
var path = args[1];
37+
export function writeIOLog(fileNames: string[], dstPath: string) {
5938
var log: IOLog = {
6039
fileNames: fileNames,
6140
resolvePath: resolvePathLog
6241
};
6342

64-
writeFile(path, JSON.stringify(log));
43+
writeFile(dstPath, JSON.stringify(log));
6544
}
6645

67-
export function prepare(): IO {
68-
var log = <IOLog>JSON.parse(readFile(args[0]));
46+
export function prepare(cmd: ts.ParsedCommandLine): IO {
47+
var content = readFile(cmd.fileNames[0]);
48+
if (content === undefined) {
49+
throw new Error('Invalid file: ' + cmd.fileNames[0])
50+
}
51+
try {
52+
var log = <IOLog>JSON.parse(content);
53+
} catch (err) {
54+
write("Invalid IO log file, expecting JSON")
55+
}
6956

57+
cmd.fileNames = []
7058
var files: ts.Map<string> = {};
71-
log.fileNames.forEach(f => { files[f] = readFile(f); })
72-
59+
log.fileNames.forEach(f => {
60+
files[f] = readFile(f);
61+
cmd.fileNames.push(f)
62+
})
63+
7364
ts.sys.createDirectory = (s: string) => { };
7465
ts.sys.directoryExists = (s: string) => true;
7566
ts.sys.fileExists = (s: string) => true;
@@ -96,7 +87,9 @@ module perftest {
9687

9788
var out: string = "";
9889

99-
ts.sys.write = (s: string) => { out += s; };
90+
ts.sys.write = (s: string) => {
91+
out += s;
92+
};
10093

10194
return {
10295
getOut: () => out,

Diff for: tests/perftsc.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,40 @@
22
/// <reference path="..\src\compiler\tsc.ts"/>
33

44
// resolve all files used in this compilation
5-
if (perftest.hasLogIOFlag()) {
5+
6+
ts.optionDeclarations.push({
7+
name: "logio",
8+
type: "string",
9+
isFilePath: true
10+
})
11+
12+
var commandLine = ts.parseCommandLine(ts.sys.args);
13+
commandLine.options.diagnostics = true
14+
15+
var logIoPath = commandLine.options['logio'];
16+
if (logIoPath) {
617
perftest.interceptIO();
718

819
var compilerHost: ts.CompilerHost = {
920
getSourceFile: (s, v) => {
1021
var content = perftest.readFile(s);
1122
return content !== undefined ? ts.createSourceFile(s, content, v) : undefined;
1223
},
13-
getDefaultLibFilename: () => ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(perftest.getExecutingFilePath())), "lib.d.ts"),
24+
getDefaultLibFileName: () => ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(perftest.getExecutingFilePath())), "lib.d.ts"),
1425
writeFile: (f: string, content: string) => { throw new Error("Unexpected operation: writeFile"); },
1526
getCurrentDirectory: () => perftest.getCurrentDirectory(),
1627
getCanonicalFileName: (f: string) => ts.sys.useCaseSensitiveFileNames ? f : f.toLowerCase(),
1728
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
1829
getNewLine: () => ts.sys.newLine
1930
};
2031

21-
var commandLine = ts.parseCommandLine(perftest.getArgsWithoutLogIOFlag());
22-
var program = ts.createProgram(commandLine.filenames, commandLine.options, compilerHost);
23-
var fileNames = program.getSourceFiles().map(f => f.filename);
24-
perftest.writeIOLog(fileNames);
32+
var program = ts.createProgram(commandLine.fileNames, commandLine.options, compilerHost);
33+
var fileNames = program.getSourceFiles().map(f => f.fileName);
34+
perftest.writeIOLog(fileNames, "" + logIoPath);
2535
}
2636
else {
27-
var io = perftest.prepare();
28-
ts.executeCommandLine(perftest.getArgsWithoutIOLogFile());
37+
var io = perftest.prepare(commandLine);
38+
ts.executeCommand(commandLine);
39+
2940
perftest.write(io.getOut());
3041
}

0 commit comments

Comments
 (0)