From 97ffcc35201f31d7d9fa75c96c68d0b88e0d0348 Mon Sep 17 00:00:00 2001 From: jbondc Date: Wed, 18 Feb 2015 07:55:29 -0500 Subject: [PATCH 1/6] Run jake in interactive mode so output isn't lost. Fix jake perftsc. --- .travis.yml | 3 +- Jakefile | 78 +++++++++++++++++---------------------------- package.json | 2 +- src/compiler/tsc.ts | 5 ++- tests/perfsys.ts | 50 +++++++++++++---------------- tests/perftsc.ts | 27 +++++++++++----- 6 files changed, 77 insertions(+), 88 deletions(-) diff --git a/.travis.yml b/.travis.yml index 305fad1e4a7..50ff61e20f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ node_js: sudo: false -before_script: npm install -g codeclimate-test-reporter +before_script: + - npm install -g codeclimate-test-reporter after_script: - cat coverage/lcov.info | codeclimate diff --git a/Jakefile b/Jakefile index dc8070fd751..9d56ddc0ed5 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) { @@ -303,19 +296,10 @@ compileFile(processDiagnosticMessagesJs, // The generated diagnostics map; built for the compiler and for the 'generate-diagnostics' task 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"); @@ -421,8 +405,8 @@ compileFile(word2mdJs, file(specMd, [word2mdJs, specWord], function () { var specWordFullPath = path.resolve(specWord); var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd; - console.log(cmd); - child_process.exec(cmd, function () { + + exec(cmd, function () { complete(); }); }, {async: true}) @@ -476,19 +460,12 @@ 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); - }); + console.log(cmd); + var ex = jake.createExec([cmd], {windowsVerbatimArguments: true, interactive: true}); ex.addListener("cmdEnd", function() { if (completeHandler) { completeHandler(); } - complete(); }); ex.addListener("error", function(e, status) { fail("Process exited with code " + status); @@ -509,7 +486,7 @@ function cleanTestDirs() { } jake.mkdirP(localRwcBaseline); - jake.mkdirP(localTest262Baseline); + jake.mkdirP(localTest262Baseline); jake.mkdirP(localBaseline); } @@ -552,15 +529,17 @@ task("runtests", ["tests", builtLocalDirectory], function() { // timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer var cmd = host + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run; - console.log(cmd); + exec(cmd, deleteTemporaryProjectOutput); }, {async: true}); desc("Generates code coverage data via instanbul") task("generate-code-coverage", ["tests", builtLocalDirectory], function () { var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run; - console.log(cmd); - exec(cmd); + + exec(cmd, function(){ + complete(); + }); }, { async: true }); // Browser tests @@ -571,7 +550,9 @@ compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile desc("Runs browserify on run.js to produce a file suitable for running tests in the browser"); task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() { var cmd = 'browserify built/local/run.js -o built/local/bundle.js'; - exec(cmd); + exec(cmd, function(){ + complete(); + }); }, {async: true}); 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( tests = tests ? tests : ''; var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + tests - console.log(cmd); - exec(cmd); + exec(cmd, function(){ + complete(); + }); }, {async: true}); function getDiffTool() { @@ -607,15 +589,17 @@ function getDiffTool() { desc("Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable"); task('diff', function () { var cmd = '"' + getDiffTool() + '" ' + refBaseline + ' ' + localBaseline; - console.log(cmd) - exec(cmd); + exec(cmd, function(){ + complete(); + }); }, {async: true}); desc("Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable"); task('diff-rwc', function () { var cmd = '"' + getDiffTool() + '" ' + refRwcBaseline + ' ' + localRwcBaseline; - console.log(cmd) - exec(cmd); + exec(cmd, function(){ + complete(); + }); }, {async: true}); desc("Builds the test sources and automation in debug mode"); @@ -676,14 +660,12 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() { jake.mkdirP(temp); 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'; @@ -693,10 +675,8 @@ compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath], 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/package.json b/package.json index 2bd89706606..e390be43217 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,6 @@ "codeclimate-test-reporter": "latest" }, "scripts": { - "test": "jake generate-code-coverage" + "test": "jake --trace generate-code-coverage" } } diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 3f7e6362e19..7379e6afe34 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 143d0d637d4..71f0535233d 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,34 @@ 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 +88,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 e0189896a15..6c56260be8e 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()); } From bf3f498688aaafc5d00c3dc21fc08fe51ba467dd Mon Sep 17 00:00:00 2001 From: jbondc Date: Thu, 19 Feb 2015 09:49:03 -0500 Subject: [PATCH 2/6] Tabs to spaces. --- Jakefile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Jakefile b/Jakefile index 9d56ddc0ed5..8b23e6580e9 100644 --- a/Jakefile +++ b/Jakefile @@ -538,8 +538,8 @@ task("generate-code-coverage", ["tests", builtLocalDirectory], function () { var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run; exec(cmd, function(){ - complete(); - }); + complete(); + }); }, { async: true }); // Browser tests @@ -551,8 +551,8 @@ desc("Runs browserify on run.js to produce a file suitable for running tests in task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() { var cmd = 'browserify built/local/run.js -o built/local/bundle.js'; exec(cmd, function(){ - complete(); - }); + complete(); + }); }, {async: true}); 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]"); @@ -573,8 +573,8 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function( tests = tests ? tests : ''; var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + tests exec(cmd, function(){ - complete(); - }); + complete(); + }); }, {async: true}); function getDiffTool() { @@ -590,16 +590,16 @@ desc("Diffs the compiler baselines using the diff tool specified by the 'DIFF' e task('diff', function () { var cmd = '"' + getDiffTool() + '" ' + refBaseline + ' ' + localBaseline; exec(cmd, function(){ - complete(); - }); + complete(); + }); }, {async: true}); desc("Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable"); task('diff-rwc', function () { var cmd = '"' + getDiffTool() + '" ' + refRwcBaseline + ' ' + localRwcBaseline; exec(cmd, function(){ - complete(); - }); + complete(); + }); }, {async: true}); desc("Builds the test sources and automation in debug mode"); From 9ee494a1c9fe583e34d5ad93e36515378a276056 Mon Sep 17 00:00:00 2001 From: jbondc Date: Thu, 19 Feb 2015 15:20:34 -0500 Subject: [PATCH 3/6] Perfsys no longer used --- Jakefile | 8 ---- src/compiler/tsc.ts | 7 +--- tests/perfsys.ts | 99 --------------------------------------------- tests/perftsc.ts | 41 ------------------- 4 files changed, 2 insertions(+), 153 deletions(-) delete mode 100644 tests/perfsys.ts delete mode 100644 tests/perftsc.ts diff --git a/Jakefile b/Jakefile index 8b23e6580e9..27042812977 100644 --- a/Jakefile +++ b/Jakefile @@ -3,7 +3,6 @@ var fs = require("fs"); var os = require("os"); var path = require("path"); -var child_process = require("child_process"); // Variables var compilerDirectory = "src/compiler/"; @@ -645,13 +644,6 @@ task("webhost", [webhostJsPath], function() { jake.cpR(path.join(builtLocalDirectory, "lib.d.ts"), "tests/webhost/", {silent: true}); }); -// Perf compiler -var perftscPath = "tests/perftsc.ts"; -var perftscJsPath = "built/local/perftsc.js"; -compileFile(perftscJsPath, [perftscPath], [tscFile, perftscPath, "tests/perfsys.ts"].concat(libraryTargets), [], /*useBuiltCompiler*/ true); -desc("Builds augmented version of the compiler for perf tests"); -task("perftsc", [perftscJsPath]); - // Instrumented compiler var loggedIOpath = harnessDirectory + 'loggedIO.ts'; var loggedIOJsPath = builtLocalDirectory + 'loggedIO.js'; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 7379e6afe34..b5eb465fd32 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -152,10 +152,7 @@ module ts { } export function executeCommandLine(args: string[]): void { - return executeCommand(parseCommandLine(args)); - } - - export function executeCommand(commandLine: ParsedCommandLine): void { + var commandLine = parseCommandLine(args); var configFileName: string; // Configuration file name (if any) var configFileWatcher: FileWatcher; // Configuration file watcher var cachedProgram: Program; // Program cached from last compilation @@ -261,7 +258,7 @@ module ts { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes)); } - function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError ?: (message: string) => void) { + function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void) { // Return existing SourceFile object if one is available if (cachedProgram) { var sourceFile = cachedProgram.getSourceFile(fileName); diff --git a/tests/perfsys.ts b/tests/perfsys.ts deleted file mode 100644 index 71f0535233d..00000000000 --- a/tests/perfsys.ts +++ /dev/null @@ -1,99 +0,0 @@ -/// -/// - -module perftest { - - interface IOLog { - resolvePath: ts.Map; - fileNames: string[]; - } - - export interface IO { - getOut(): string; - } - - export var readFile = ts.sys.readFile; - var writeFile = ts.sys.writeFile; - export var write = ts.sys.write; - var resolvePath = ts.sys.resolvePath; - export var getExecutingFilePath = ts.sys.getExecutingFilePath; - export var getCurrentDirectory = ts.sys.getCurrentDirectory; - var exit = ts.sys.exit; - - // augment sys so first ts.executeCommandLine call will be finish silently - ts.sys.write = (s: string) => { }; - ts.sys.exit = (code: number) => { }; - - var resolvePathLog: ts.Map = {}; - - export function interceptIO() { - ts.sys.resolvePath = (s) => { - var result = resolvePath(s); - resolvePathLog[s] = result; - return result; - }; - } - - export function writeIOLog(fileNames: string[], dstPath: string) { - var log: IOLog = { - fileNames: fileNames, - resolvePath: resolvePathLog - }; - - writeFile(dstPath, JSON.stringify(log)); - } - - 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); - cmd.fileNames.push(f) - }) - - ts.sys.createDirectory = (s: string) => { }; - ts.sys.directoryExists = (s: string) => true; - ts.sys.fileExists = (s: string) => true; - - var currentDirectory = ts.sys.getCurrentDirectory(); - ts.sys.getCurrentDirectory = () => currentDirectory; - - var executingFilePath = ts.sys.getExecutingFilePath(); - ts.sys.getExecutingFilePath = () => executingFilePath; - - ts.sys.readFile = (s: string) => { - return files[s]; - } - - ts.sys.resolvePath = (s: string) => { - var path = log.resolvePath[s]; - if (!path) { - throw new Error("Unexpected path '" + s + "'"); - } - return path - } - - ts.sys.writeFile = (path: string, data: string) => { }; - - var out: string = ""; - - ts.sys.write = (s: string) => { - out += s; - }; - - return { - getOut: () => out, - }; - } -} diff --git a/tests/perftsc.ts b/tests/perftsc.ts deleted file mode 100644 index 6c56260be8e..00000000000 --- a/tests/perftsc.ts +++ /dev/null @@ -1,41 +0,0 @@ -/// -/// - -// resolve all files used in this compilation - -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"), - 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 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(commandLine); - ts.executeCommand(commandLine); - - perftest.write(io.getOut()); -} From dd8ea1536d6a42db7f19c5dacb9630e384c607d3 Mon Sep 17 00:00:00 2001 From: jbondc Date: Thu, 19 Feb 2015 15:43:09 -0500 Subject: [PATCH 4/6] If there's a callback, make it its responsibility to call complete() --- Jakefile | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/Jakefile b/Jakefile index 27042812977..dfac39321e8 100644 --- a/Jakefile +++ b/Jakefile @@ -244,9 +244,9 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu if (callback) { callback(); + } else { + complete(); } - - complete(); }); ex.addListener("error", function() { fs.unlinkSync(outFile); @@ -359,6 +359,7 @@ compileFile(nodeDefinitionsFile, servicesSources,[builtLocalDirectory, copyright // Delete the temp dir jake.rmRf(tempDirPath, {silent: true}); + complete(); }); // Local target to build the compiler and services @@ -405,9 +406,7 @@ file(specMd, [word2mdJs, specWord], function () { var specWordFullPath = path.resolve(specWord); var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd; - exec(cmd, function () { - complete(); - }); + exec(cmd); }, {async: true}) @@ -464,6 +463,8 @@ function exec(cmd, completeHandler) { ex.addListener("cmdEnd", function() { if (completeHandler) { completeHandler(); + } else { + complete(); } }); ex.addListener("error", function(e, status) { @@ -500,6 +501,7 @@ function deleteTemporaryProjectOutput() { if (fs.existsSync(path.join(localBaseline, "projectOutput/"))) { jake.rmRf(path.join(localBaseline, "projectOutput/")); } + complete(); } var testTimeout = 20000; @@ -536,9 +538,7 @@ desc("Generates code coverage data via instanbul") task("generate-code-coverage", ["tests", builtLocalDirectory], function () { var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run; - exec(cmd, function(){ - complete(); - }); + exec(cmd); }, { async: true }); // Browser tests @@ -549,9 +549,7 @@ compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile desc("Runs browserify on run.js to produce a file suitable for running tests in the browser"); task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() { var cmd = 'browserify built/local/run.js -o built/local/bundle.js'; - exec(cmd, function(){ - complete(); - }); + exec(cmd); }, {async: true}); 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]"); @@ -571,9 +569,7 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function( tests = tests ? tests : ''; var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + tests - exec(cmd, function(){ - complete(); - }); + exec(cmd); }, {async: true}); function getDiffTool() { @@ -588,17 +584,13 @@ function getDiffTool() { desc("Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable"); task('diff', function () { var cmd = '"' + getDiffTool() + '" ' + refBaseline + ' ' + localBaseline; - exec(cmd, function(){ - complete(); - }); + exec(cmd); }, {async: true}); desc("Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable"); task('diff-rwc', function () { var cmd = '"' + getDiffTool() + '" ' + refRwcBaseline + ' ' + localRwcBaseline; - exec(cmd, function(){ - complete(); - }); + exec(cmd); }, {async: true}); desc("Builds the test sources and automation in debug mode"); @@ -668,7 +660,5 @@ desc("Builds an instrumented tsc.js"); task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function() { var cmd = host + ' ' + instrumenterJsPath + ' record iocapture ' + builtLocalDirectory + compilerFilename; - exec(cmd, function() { - complete(); - }); + exec(cmd); }, { async: true }); From 3f97fe875f9a6b5d0ba783f596e4236f806a03a3 Mon Sep 17 00:00:00 2001 From: jbondc Date: Thu, 19 Feb 2015 16:06:46 -0500 Subject: [PATCH 5/6] Wrap all commands in exec() --- Jakefile | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Jakefile b/Jakefile index dfac39321e8..7f8739f2439 100644 --- a/Jakefile +++ b/Jakefile @@ -232,10 +232,9 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu var cmd = host + " " + dir + compilerFilename + " " + options + " "; cmd = cmd + sources.join(" "); - console.log(cmd + "\n"); - var ex = jake.createExec([cmd], {interactive: true}); - ex.addListener("cmdEnd", function() { + exec(cmd, function() { + console.log("") if (!useDebugMode && prefixes && fs.existsSync(outFile)) { for (var i in prefixes) { prependFile(prefixes[i], outFile); @@ -247,12 +246,11 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu } else { complete(); } - }); - ex.addListener("error", function() { + }, /* errorHandler */ function() { fs.unlinkSync(outFile); fail("Compilation of " + outFile + " unsuccessful"); }); - ex.run(); + }, {async: true}); } @@ -457,7 +455,7 @@ var refTest262Baseline = path.join(internalTests, "baselines/test262/reference") desc("Builds the test infrastructure using the built compiler"); task("tests", ["local", run].concat(libraryTargets)); -function exec(cmd, completeHandler) { +function exec(cmd, completeHandler, errorHandler) { console.log(cmd); var ex = jake.createExec([cmd], {windowsVerbatimArguments: true, interactive: true}); ex.addListener("cmdEnd", function() { @@ -467,7 +465,7 @@ function exec(cmd, completeHandler) { complete(); } }); - ex.addListener("error", function(e, status) { + ex.addListener("error", errorHandler ? errorHandler : function(e, status) { fail("Process exited with code " + status); }) From cb6852af73251843ec379093379fa0d75d768053 Mon Sep 17 00:00:00 2001 From: jbondc Date: Thu, 19 Feb 2015 18:31:55 -0500 Subject: [PATCH 6/6] Code review --- Jakefile | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Jakefile b/Jakefile index 7f8739f2439..ae106b12e16 100644 --- a/Jakefile +++ b/Jakefile @@ -24,7 +24,8 @@ var thirdParty = "ThirdPartyNoticeText.txt"; var nodeModulesPathPrefix = path.resolve("./node_modules/.bin/") + path.delimiter; if (process.env.path !== undefined) { process.env.path = nodeModulesPathPrefix + process.env.path; -} else if (process.env.PATH !== undefined) { +} +else if (process.env.PATH !== undefined) { process.env.PATH = nodeModulesPathPrefix + process.env.PATH; } @@ -181,7 +182,8 @@ function concatenateFiles(destinationFile, sourceFiles) { var useDebugMode = true; var host = (process.env.host || process.env.TYPESCRIPT_HOST || "node"); var compilerFilename = "tsc.js"; -/* Compiles a file from a list of sources + + /* Compiles a file from a list of sources * @param outFile: the target file name * @param sources: an array of the names of the source files * @param prereqs: prerequisite tasks to compiling the file @@ -192,8 +194,9 @@ var compilerFilename = "tsc.js"; * @param outDir: true to compile using --outDir * @param keepComments: false to compile using --removeComments * @param callback: a function to execute after the compilation process ends + * @async */ -function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, preserveConstEnums, keepComments, noResolve, stripInternal, callback) { + function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, preserveConstEnums, keepComments, noResolve, stripInternal, callback) { file(outFile, prereqs, function() { var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory; var options = "--module commonjs -noImplicitAny"; @@ -243,7 +246,8 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu if (callback) { callback(); - } else { + } + else { complete(); } }, /* errorHandler */ function() { @@ -294,9 +298,7 @@ compileFile(processDiagnosticMessagesJs, file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson], function () { var cmd = "node " + processDiagnosticMessagesJs + " " + diagnosticMessagesJson; - exec(cmd, function() { - complete(); - }); + exec(cmd); }, {async: true}) desc("Generates a diagnostic file in TypeScript based on an input JSON file"); @@ -455,17 +457,24 @@ var refTest262Baseline = path.join(internalTests, "baselines/test262/reference") desc("Builds the test infrastructure using the built compiler"); task("tests", ["local", run].concat(libraryTargets)); +/* Executes a command + * @param cmd: command to execute + * @param completeHandler?: a function to execute after the command ends + * @param errorHandler?: a function to execute if an error occurs + * @async + */ function exec(cmd, completeHandler, errorHandler) { console.log(cmd); var ex = jake.createExec([cmd], {windowsVerbatimArguments: true, interactive: true}); ex.addListener("cmdEnd", function() { if (completeHandler) { completeHandler(); - } else { + } + else { complete(); } }); - ex.addListener("error", errorHandler ? errorHandler : function(e, status) { + ex.addListener("error", errorHandler || function(e, status) { fail("Process exited with code " + status); }) @@ -495,6 +504,9 @@ function writeTestConfigFile(tests, testConfigFile) { fs.writeFileSync('test.config', testConfigContents); } +/* Removes project output + * @async + */ function deleteTemporaryProjectOutput() { if (fs.existsSync(path.join(localBaseline, "projectOutput/"))) { jake.rmRf(path.join(localBaseline, "projectOutput/"));