Skip to content

Commit 97ffcc3

Browse files
author
jbondc
committed
Run jake in interactive mode so output isn't lost.
Fix jake perftsc.
1 parent d2c992c commit 97ffcc3

6 files changed

Lines changed: 77 additions & 88 deletions

File tree

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ node_js:
55

66
sudo: false
77

8-
before_script: npm install -g codeclimate-test-reporter
8+
before_script:
9+
- npm install -g codeclimate-test-reporter
910

1011
after_script:
1112
- cat coverage/lcov.info | codeclimate

Jakefile

Lines changed: 29 additions & 49 deletions
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) {
@@ -303,19 +296,10 @@ compileFile(processDiagnosticMessagesJs,
303296
// The generated diagnostics map; built for the compiler and for the 'generate-diagnostics' task
304297
file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson], function () {
305298
var cmd = "node " + processDiagnosticMessagesJs + " " + diagnosticMessagesJson;
306-
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() {
299+
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");
@@ -421,8 +405,8 @@ compileFile(word2mdJs,
421405
file(specMd, [word2mdJs, specWord], function () {
422406
var specWordFullPath = path.resolve(specWord);
423407
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd;
424-
console.log(cmd);
425-
child_process.exec(cmd, function () {
408+
409+
exec(cmd, function () {
426410
complete();
427411
});
428412
}, {async: true})
@@ -476,19 +460,12 @@ 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+
console.log(cmd);
464+
var ex = jake.createExec([cmd], {windowsVerbatimArguments: true, interactive: true});
487465
ex.addListener("cmdEnd", function() {
488466
if (completeHandler) {
489467
completeHandler();
490468
}
491-
complete();
492469
});
493470
ex.addListener("error", function(e, status) {
494471
fail("Process exited with code " + status);
@@ -509,7 +486,7 @@ function cleanTestDirs() {
509486
}
510487

511488
jake.mkdirP(localRwcBaseline);
512-
jake.mkdirP(localTest262Baseline);
489+
jake.mkdirP(localTest262Baseline);
513490
jake.mkdirP(localBaseline);
514491
}
515492

@@ -552,15 +529,17 @@ task("runtests", ["tests", builtLocalDirectory], function() {
552529
// timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally
553530
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
554531
var cmd = host + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run;
555-
console.log(cmd);
532+
556533
exec(cmd, deleteTemporaryProjectOutput);
557534
}, {async: true});
558535

559536
desc("Generates code coverage data via instanbul")
560537
task("generate-code-coverage", ["tests", builtLocalDirectory], function () {
561538
var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run;
562-
console.log(cmd);
563-
exec(cmd);
539+
540+
exec(cmd, function(){
541+
complete();
542+
});
564543
}, { async: true });
565544

566545
// Browser tests
@@ -571,7 +550,9 @@ compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile
571550
desc("Runs browserify on run.js to produce a file suitable for running tests in the browser");
572551
task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() {
573552
var cmd = 'browserify built/local/run.js -o built/local/bundle.js';
574-
exec(cmd);
553+
exec(cmd, function(){
554+
complete();
555+
});
575556
}, {async: true});
576557

577558
desc("Runs the tests using the built run.js file like 'jake runtests'. Syntax is jake runtests-browser. Additional optional parameters tests=[regex], port=, browser=[chrome|IE]");
@@ -591,8 +572,9 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function(
591572

592573
tests = tests ? tests : '';
593574
var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + tests
594-
console.log(cmd);
595-
exec(cmd);
575+
exec(cmd, function(){
576+
complete();
577+
});
596578
}, {async: true});
597579

598580
function getDiffTool() {
@@ -607,15 +589,17 @@ function getDiffTool() {
607589
desc("Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable");
608590
task('diff', function () {
609591
var cmd = '"' + getDiffTool() + '" ' + refBaseline + ' ' + localBaseline;
610-
console.log(cmd)
611-
exec(cmd);
592+
exec(cmd, function(){
593+
complete();
594+
});
612595
}, {async: true});
613596

614597
desc("Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable");
615598
task('diff-rwc', function () {
616599
var cmd = '"' + getDiffTool() + '" ' + refRwcBaseline + ' ' + localRwcBaseline;
617-
console.log(cmd)
618-
exec(cmd);
600+
exec(cmd, function(){
601+
complete();
602+
});
619603
}, {async: true});
620604

621605
desc("Builds the test sources and automation in debug mode");
@@ -676,14 +660,12 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() {
676660
jake.mkdirP(temp);
677661
var options = "--outdir " + temp + ' ' + loggedIOpath;
678662
var cmd = host + " " + LKGDirectory + compilerFilename + " " + options + " ";
679-
console.log(cmd + "\n");
680-
var ex = jake.createExec([cmd]);
681-
ex.addListener("cmdEnd", function() {
663+
664+
exec(cmd, function() {
682665
fs.renameSync(temp + '/harness/loggedIO.js', loggedIOJsPath);
683666
jake.rmRf(temp);
684667
complete();
685668
});
686-
ex.run();
687669
}, {async: true});
688670

689671
var instrumenterPath = harnessDirectory + 'instrumenter.ts';
@@ -693,10 +675,8 @@ compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath],
693675
desc("Builds an instrumented tsc.js");
694676
task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function() {
695677
var cmd = host + ' ' + instrumenterJsPath + ' record iocapture ' + builtLocalDirectory + compilerFilename;
696-
console.log(cmd);
697-
var ex = jake.createExec([cmd]);
698-
ex.addListener("cmdEnd", function() {
678+
679+
exec(cmd, function() {
699680
complete();
700681
});
701-
ex.run();
702682
}, { async: true });

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@
4141
"codeclimate-test-reporter": "latest"
4242
},
4343
"scripts": {
44-
"test": "jake generate-code-coverage"
44+
"test": "jake --trace generate-code-coverage"
4545
}
4646
}

src/compiler/tsc.ts

Lines changed: 4 additions & 1 deletion
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

tests/perfsys.ts

Lines changed: 22 additions & 28 deletions
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,34 @@ 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+
}
54+
catch (err) {
55+
write("Invalid IO log file, expecting JSON")
56+
}
6957

58+
cmd.fileNames = []
7059
var files: ts.Map<string> = {};
71-
log.fileNames.forEach(f => { files[f] = readFile(f); })
72-
60+
log.fileNames.forEach(f => {
61+
files[f] = readFile(f);
62+
cmd.fileNames.push(f)
63+
})
64+
7365
ts.sys.createDirectory = (s: string) => { };
7466
ts.sys.directoryExists = (s: string) => true;
7567
ts.sys.fileExists = (s: string) => true;
@@ -96,7 +88,9 @@ module perftest {
9688

9789
var out: string = "";
9890

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

10195
return {
10296
getOut: () => out,

tests/perftsc.ts

Lines changed: 19 additions & 8 deletions
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)