33var fs = require ( "fs" ) ;
44var os = require ( "os" ) ;
55var path = require ( "path" ) ;
6+ var child_process = require ( "child_process" ) ;
67
78// Variables
89var compilerDirectory = "src/compiler/" ;
@@ -25,8 +26,7 @@ var thirdParty = "ThirdPartyNoticeText.txt";
2526var nodeModulesPathPrefix = path . resolve ( "./node_modules/.bin/" ) + path . delimiter ;
2627if ( 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) {
203203var useDebugMode = true ;
204204var host = ( process . env . host || process . env . TYPESCRIPT_HOST || "node" ) ;
205205var 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
319325file ( 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
325342desc ( "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
390406var serverFile = path . join ( builtLocalDirectory , "tsserver.js" ) ;
@@ -433,8 +449,10 @@ compileFile(word2mdJs,
433449file ( 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")
485503desc ( "Builds the test infrastructure using the built compiler" ) ;
486504task ( "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- */
538551function deleteTemporaryProjectOutput ( ) {
539552 if ( fs . existsSync ( path . join ( localBaseline , "projectOutput/" ) ) ) {
540553 jake . rmRf ( path . join ( localBaseline , "projectOutput/" ) ) ;
541554 }
542- complete ( ) ;
543555}
544556
545557var 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
575587desc ( "Generates code coverage data via instanbul" )
576588task ( "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() {
622635desc ( "Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable" ) ;
623636task ( 'diff' , function ( ) {
624637 var cmd = '"' + getDiffTool ( ) + '" ' + refBaseline + ' ' + localBaseline ;
638+ console . log ( cmd )
625639 exec ( cmd ) ;
626640} , { async : true } ) ;
627641
628642desc ( "Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable" ) ;
629643task ( '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
678700var loggedIOpath = harnessDirectory + 'loggedIO.ts' ;
679701var 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
693717var instrumenterPath = harnessDirectory + 'instrumenter.ts' ;
@@ -697,6 +721,10 @@ compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath],
697721desc ( "Builds an instrumented tsc.js" ) ;
698722task ( '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 } ) ;
0 commit comments