Skip to content

Commit 212aeb5

Browse files
Revert "Run jake in interactive mode so output isn't lost."
1 parent fedc809 commit 212aeb5

6 files changed

Lines changed: 208 additions & 46 deletions

File tree

.travis.yml

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

66
sudo: false
77

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

1110
after_script:
1211
- cat coverage/lcov.info | codeclimate

Jakefile

Lines changed: 70 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var fs = require("fs");
44
var os = require("os");
55
var path = require("path");
6+
var child_process = require("child_process");
67

78
// Variables
89
var compilerDirectory = "src/compiler/";
@@ -25,8 +26,7 @@ var thirdParty = "ThirdPartyNoticeText.txt";
2526
var nodeModulesPathPrefix = path.resolve("./node_modules/.bin/") + path.delimiter;
2627
if (process.env.path !== undefined) {
2728
process.env.path = nodeModulesPathPrefix + process.env.path;
28-
}
29-
else if (process.env.PATH !== undefined) {
29+
} else if (process.env.PATH !== undefined) {
3030
process.env.PATH = nodeModulesPathPrefix + process.env.PATH;
3131
}
3232

@@ -203,8 +203,7 @@ function concatenateFiles(destinationFile, sourceFiles) {
203203
var useDebugMode = true;
204204
var host = (process.env.host || process.env.TYPESCRIPT_HOST || "node");
205205
var compilerFilename = "tsc.js";
206-
207-
/* Compiles a file from a list of sources
206+
/* Compiles a file from a list of sources
208207
* @param outFile: the target file name
209208
* @param sources: an array of the names of the source files
210209
* @param prereqs: prerequisite tasks to compiling the file
@@ -215,9 +214,8 @@ var compilerFilename = "tsc.js";
215214
* @param outDir: true to compile using --outDir
216215
* @param keepComments: false to compile using --removeComments
217216
* @param callback: a function to execute after the compilation process ends
218-
* @async
219217
*/
220-
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, preserveConstEnums, keepComments, noResolve, stripInternal, callback) {
218+
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, preserveConstEnums, keepComments, noResolve, stripInternal, callback) {
221219
file(outFile, prereqs, function() {
222220
var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory;
223221
var options = "--module commonjs -noImplicitAny";
@@ -256,9 +254,17 @@ var compilerFilename = "tsc.js";
256254

257255
var cmd = host + " " + dir + compilerFilename + " " + options + " ";
258256
cmd = cmd + sources.join(" ");
257+
console.log(cmd + "\n");
259258

260-
exec(cmd, function() {
261-
console.log("")
259+
var ex = jake.createExec([cmd]);
260+
// Add listeners for output and error
261+
ex.addListener("stdout", function(output) {
262+
process.stdout.write(output);
263+
});
264+
ex.addListener("stderr", function(error) {
265+
process.stderr.write(error);
266+
});
267+
ex.addListener("cmdEnd", function() {
262268
if (!useDebugMode && prefixes && fs.existsSync(outFile)) {
263269
for (var i in prefixes) {
264270
prependFile(prefixes[i], outFile);
@@ -268,14 +274,14 @@ var compilerFilename = "tsc.js";
268274
if (callback) {
269275
callback();
270276
}
271-
else {
272-
complete();
273-
}
274-
}, /* errorHandler */ function() {
277+
278+
complete();
279+
});
280+
ex.addListener("error", function() {
275281
fs.unlinkSync(outFile);
276282
fail("Compilation of " + outFile + " unsuccessful");
277283
});
278-
284+
ex.run();
279285
}, {async: true});
280286
}
281287

@@ -318,8 +324,19 @@ compileFile(processDiagnosticMessagesJs,
318324
// The generated diagnostics map; built for the compiler and for the 'generate-diagnostics' task
319325
file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson], function () {
320326
var cmd = "node " + processDiagnosticMessagesJs + " " + diagnosticMessagesJson;
321-
322-
exec(cmd);
327+
console.log(cmd);
328+
var ex = jake.createExec([cmd]);
329+
// Add listeners for output and error
330+
ex.addListener("stdout", function(output) {
331+
process.stdout.write(output);
332+
});
333+
ex.addListener("stderr", function(error) {
334+
process.stderr.write(error);
335+
});
336+
ex.addListener("cmdEnd", function() {
337+
complete();
338+
});
339+
ex.run();
323340
}, {async: true})
324341

325342
desc("Generates a diagnostic file in TypeScript based on an input JSON file");
@@ -384,7 +401,6 @@ compileFile(nodeDefinitionsFile, servicesSources,[builtLocalDirectory, copyright
384401

385402
// Delete the temp dir
386403
jake.rmRf(tempDirPath, {silent: true});
387-
complete();
388404
});
389405

390406
var serverFile = path.join(builtLocalDirectory, "tsserver.js");
@@ -433,8 +449,10 @@ compileFile(word2mdJs,
433449
file(specMd, [word2mdJs, specWord], function () {
434450
var specWordFullPath = path.resolve(specWord);
435451
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd;
436-
437-
exec(cmd);
452+
console.log(cmd);
453+
child_process.exec(cmd, function () {
454+
complete();
455+
});
438456
}, {async: true})
439457

440458

@@ -485,24 +503,22 @@ var refTest262Baseline = path.join(internalTests, "baselines/test262/reference")
485503
desc("Builds the test infrastructure using the built compiler");
486504
task("tests", ["local", run].concat(libraryTargets));
487505

488-
/* Executes a command
489-
* @param cmd: command to execute
490-
* @param completeHandler?: a function to execute after the command ends
491-
* @param errorHandler?: a function to execute if an error occurs
492-
* @async
493-
*/
494-
function exec(cmd, completeHandler, errorHandler) {
495-
console.log(cmd);
496-
var ex = jake.createExec([cmd], {windowsVerbatimArguments: true, interactive: true});
506+
function exec(cmd, completeHandler) {
507+
var ex = jake.createExec([cmd], {windowsVerbatimArguments: true});
508+
// Add listeners for output and error
509+
ex.addListener("stdout", function(output) {
510+
process.stdout.write(output);
511+
});
512+
ex.addListener("stderr", function(error) {
513+
process.stderr.write(error);
514+
});
497515
ex.addListener("cmdEnd", function() {
498516
if (completeHandler) {
499517
completeHandler();
500518
}
501-
else {
502-
complete();
503-
}
519+
complete();
504520
});
505-
ex.addListener("error", errorHandler || function(e, status) {
521+
ex.addListener("error", function(e, status) {
506522
fail("Process exited with code " + status);
507523
})
508524

@@ -521,7 +537,7 @@ function cleanTestDirs() {
521537
}
522538

523539
jake.mkdirP(localRwcBaseline);
524-
jake.mkdirP(localTest262Baseline);
540+
jake.mkdirP(localTest262Baseline);
525541
jake.mkdirP(localBaseline);
526542
}
527543

@@ -532,14 +548,10 @@ function writeTestConfigFile(tests, testConfigFile) {
532548
fs.writeFileSync('test.config', testConfigContents);
533549
}
534550

535-
/* Removes project output
536-
* @async
537-
*/
538551
function deleteTemporaryProjectOutput() {
539552
if (fs.existsSync(path.join(localBaseline, "projectOutput/"))) {
540553
jake.rmRf(path.join(localBaseline, "projectOutput/"));
541554
}
542-
complete();
543555
}
544556

545557
var testTimeout = 20000;
@@ -568,14 +580,14 @@ task("runtests", ["tests", builtLocalDirectory], function() {
568580
// timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally
569581
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
570582
var cmd = host + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run;
571-
583+
console.log(cmd);
572584
exec(cmd, deleteTemporaryProjectOutput);
573585
}, {async: true});
574586

575587
desc("Generates code coverage data via instanbul")
576588
task("generate-code-coverage", ["tests", builtLocalDirectory], function () {
577589
var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run;
578-
590+
console.log(cmd);
579591
exec(cmd);
580592
}, { async: true });
581593

@@ -607,6 +619,7 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function(
607619

608620
tests = tests ? tests : '';
609621
var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + tests
622+
console.log(cmd);
610623
exec(cmd);
611624
}, {async: true});
612625

@@ -622,12 +635,14 @@ function getDiffTool() {
622635
desc("Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable");
623636
task('diff', function () {
624637
var cmd = '"' + getDiffTool() + '" ' + refBaseline + ' ' + localBaseline;
638+
console.log(cmd)
625639
exec(cmd);
626640
}, {async: true});
627641

628642
desc("Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable");
629643
task('diff-rwc', function () {
630644
var cmd = '"' + getDiffTool() + '" ' + refRwcBaseline + ' ' + localRwcBaseline;
645+
console.log(cmd)
631646
exec(cmd);
632647
}, {async: true});
633648

@@ -674,6 +689,13 @@ task("webhost", [webhostJsPath], function() {
674689
jake.cpR(path.join(builtLocalDirectory, "lib.d.ts"), "tests/webhost/", {silent: true});
675690
});
676691

692+
// Perf compiler
693+
var perftscPath = "tests/perftsc.ts";
694+
var perftscJsPath = "built/local/perftsc.js";
695+
compileFile(perftscJsPath, [perftscPath], [tscFile, perftscPath, "tests/perfsys.ts"].concat(libraryTargets), [], /*useBuiltCompiler*/ true);
696+
desc("Builds augmented version of the compiler for perf tests");
697+
task("perftsc", [perftscJsPath]);
698+
677699
// Instrumented compiler
678700
var loggedIOpath = harnessDirectory + 'loggedIO.ts';
679701
var loggedIOJsPath = builtLocalDirectory + 'loggedIO.js';
@@ -682,12 +704,14 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() {
682704
jake.mkdirP(temp);
683705
var options = "--outdir " + temp + ' ' + loggedIOpath;
684706
var cmd = host + " " + LKGDirectory + compilerFilename + " " + options + " ";
685-
686-
exec(cmd, function() {
707+
console.log(cmd + "\n");
708+
var ex = jake.createExec([cmd]);
709+
ex.addListener("cmdEnd", function() {
687710
fs.renameSync(temp + '/harness/loggedIO.js', loggedIOJsPath);
688711
jake.rmRf(temp);
689712
complete();
690713
});
714+
ex.run();
691715
}, {async: true});
692716

693717
var instrumenterPath = harnessDirectory + 'instrumenter.ts';
@@ -697,6 +721,10 @@ compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath],
697721
desc("Builds an instrumented tsc.js");
698722
task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function() {
699723
var cmd = host + ' ' + instrumenterJsPath + ' record iocapture ' + builtLocalDirectory + compilerFilename;
700-
701-
exec(cmd);
724+
console.log(cmd);
725+
var ex = jake.createExec([cmd]);
726+
ex.addListener("cmdEnd", function() {
727+
complete();
728+
});
729+
ex.run();
702730
}, { async: true });

package.json

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

src/compiler/tsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ module ts {
258258
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes));
259259
}
260260

261-
function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void) {
261+
function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError ?: (message: string) => void) {
262262
// Return existing SourceFile object if one is available
263263
if (cachedProgram) {
264264
var sourceFile = cachedProgram.getSourceFile(fileName);

tests/perfsys.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/// <reference path="..\src\compiler\sys.ts"/>
2+
/// <reference path="..\src\compiler\types.ts"/>
3+
4+
module perftest {
5+
6+
interface IOLog {
7+
resolvePath: ts.Map<string>;
8+
fileNames: string[];
9+
}
10+
11+
export interface IO {
12+
getOut(): string;
13+
}
14+
15+
export var readFile = ts.sys.readFile;
16+
var writeFile = ts.sys.writeFile;
17+
export var write = ts.sys.write;
18+
var resolvePath = ts.sys.resolvePath;
19+
export var getExecutingFilePath = ts.sys.getExecutingFilePath;
20+
export var getCurrentDirectory = ts.sys.getCurrentDirectory;
21+
var exit = ts.sys.exit;
22+
23+
var args = ts.sys.args;
24+
25+
// augment sys so first ts.executeCommandLine call will be finish silently
26+
ts.sys.write = (s: string) => { };
27+
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+
}
46+
47+
var resolvePathLog: ts.Map<string> = {};
48+
49+
export function interceptIO() {
50+
ts.sys.resolvePath = (s) => {
51+
var result = resolvePath(s);
52+
resolvePathLog[s] = result;
53+
return result;
54+
};
55+
}
56+
57+
export function writeIOLog(fileNames: string[]) {
58+
var path = args[1];
59+
var log: IOLog = {
60+
fileNames: fileNames,
61+
resolvePath: resolvePathLog
62+
};
63+
64+
writeFile(path, JSON.stringify(log));
65+
}
66+
67+
export function prepare(): IO {
68+
var log = <IOLog>JSON.parse(readFile(args[0]));
69+
70+
var files: ts.Map<string> = {};
71+
log.fileNames.forEach(f => { files[f] = readFile(f); })
72+
73+
ts.sys.createDirectory = (s: string) => { };
74+
ts.sys.directoryExists = (s: string) => true;
75+
ts.sys.fileExists = (s: string) => true;
76+
77+
var currentDirectory = ts.sys.getCurrentDirectory();
78+
ts.sys.getCurrentDirectory = () => currentDirectory;
79+
80+
var executingFilePath = ts.sys.getExecutingFilePath();
81+
ts.sys.getExecutingFilePath = () => executingFilePath;
82+
83+
ts.sys.readFile = (s: string) => {
84+
return files[s];
85+
}
86+
87+
ts.sys.resolvePath = (s: string) => {
88+
var path = log.resolvePath[s];
89+
if (!path) {
90+
throw new Error("Unexpected path '" + s + "'");
91+
}
92+
return path
93+
}
94+
95+
ts.sys.writeFile = (path: string, data: string) => { };
96+
97+
var out: string = "";
98+
99+
ts.sys.write = (s: string) => { out += s; };
100+
101+
return {
102+
getOut: () => out,
103+
};
104+
}
105+
}

0 commit comments

Comments
 (0)