33var fs = require ( "fs" ) ;
44var os = require ( "os" ) ;
55var path = require ( "path" ) ;
6- var child_process = require ( "child_process" ) ;
76
87// Variables
98var compilerDirectory = "src/compiler/" ;
@@ -26,7 +25,8 @@ var thirdParty = "ThirdPartyNoticeText.txt";
2625var nodeModulesPathPrefix = path . resolve ( "./node_modules/.bin/" ) + path . delimiter ;
2726if ( process . env . path !== undefined ) {
2827 process . env . path = nodeModulesPathPrefix + process . env . path ;
29- } else if ( process . env . PATH !== undefined ) {
28+ }
29+ else if ( process . env . PATH !== undefined ) {
3030 process . env . PATH = nodeModulesPathPrefix + process . env . PATH ;
3131}
3232
@@ -203,7 +203,8 @@ function concatenateFiles(destinationFile, sourceFiles) {
203203var useDebugMode = true ;
204204var host = ( process . env . host || process . env . TYPESCRIPT_HOST || "node" ) ;
205205var compilerFilename = "tsc.js" ;
206- /* Compiles a file from a list of sources
206+
207+ /* Compiles a file from a list of sources
207208 * @param outFile: the target file name
208209 * @param sources: an array of the names of the source files
209210 * @param prereqs: prerequisite tasks to compiling the file
@@ -214,8 +215,9 @@ var compilerFilename = "tsc.js";
214215 * @param outDir: true to compile using --outDir
215216 * @param keepComments: false to compile using --removeComments
216217 * @param callback: a function to execute after the compilation process ends
218+ * @async
217219 */
218- function compileFile ( outFile , sources , prereqs , prefixes , useBuiltCompiler , noOutFile , generateDeclarations , outDir , preserveConstEnums , keepComments , noResolve , stripInternal , callback ) {
220+ function compileFile ( outFile , sources , prereqs , prefixes , useBuiltCompiler , noOutFile , generateDeclarations , outDir , preserveConstEnums , keepComments , noResolve , stripInternal , callback ) {
219221 file ( outFile , prereqs , function ( ) {
220222 var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory ;
221223 var options = "--module commonjs -noImplicitAny" ;
@@ -254,17 +256,9 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
254256
255257 var cmd = host + " " + dir + compilerFilename + " " + options + " " ;
256258 cmd = cmd + sources . join ( " " ) ;
257- console . log ( cmd + "\n" ) ;
258259
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 ( ) {
260+ exec ( cmd , function ( ) {
261+ console . log ( "" )
268262 if ( ! useDebugMode && prefixes && fs . existsSync ( outFile ) ) {
269263 for ( var i in prefixes ) {
270264 prependFile ( prefixes [ i ] , outFile ) ;
@@ -274,14 +268,14 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
274268 if ( callback ) {
275269 callback ( ) ;
276270 }
277-
278- complete ( ) ;
279- } ) ;
280- ex . addListener ( "error" , function ( ) {
271+ else {
272+ complete ( ) ;
273+ }
274+ } , /* errorHandler */ function ( ) {
281275 fs . unlinkSync ( outFile ) ;
282276 fail ( "Compilation of " + outFile + " unsuccessful" ) ;
283277 } ) ;
284- ex . run ( ) ;
278+
285279 } , { async : true } ) ;
286280}
287281
@@ -324,19 +318,8 @@ compileFile(processDiagnosticMessagesJs,
324318// The generated diagnostics map; built for the compiler and for the 'generate-diagnostics' task
325319file ( diagnosticInfoMapTs , [ processDiagnosticMessagesJs , diagnosticMessagesJson ] , function ( ) {
326320 var cmd = "node " + processDiagnosticMessagesJs + " " + diagnosticMessagesJson ;
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 ( ) ;
321+
322+ exec ( cmd ) ;
340323} , { async : true } )
341324
342325desc ( "Generates a diagnostic file in TypeScript based on an input JSON file" ) ;
@@ -401,6 +384,7 @@ compileFile(nodeDefinitionsFile, servicesSources,[builtLocalDirectory, copyright
401384
402385 // Delete the temp dir
403386 jake . rmRf ( tempDirPath , { silent : true } ) ;
387+ complete ( ) ;
404388 } ) ;
405389
406390var serverFile = path . join ( builtLocalDirectory , "tsserver.js" ) ;
@@ -449,10 +433,8 @@ compileFile(word2mdJs,
449433file ( specMd , [ word2mdJs , specWord ] , function ( ) {
450434 var specWordFullPath = path . resolve ( specWord ) ;
451435 var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd ;
452- console . log ( cmd ) ;
453- child_process . exec ( cmd , function ( ) {
454- complete ( ) ;
455- } ) ;
436+
437+ exec ( cmd ) ;
456438} , { async : true } )
457439
458440
@@ -503,22 +485,24 @@ var refTest262Baseline = path.join(internalTests, "baselines/test262/reference")
503485desc ( "Builds the test infrastructure using the built compiler" ) ;
504486task ( "tests" , [ "local" , run ] . concat ( libraryTargets ) ) ;
505487
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- } ) ;
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 } ) ;
515497 ex . addListener ( "cmdEnd" , function ( ) {
516498 if ( completeHandler ) {
517499 completeHandler ( ) ;
518500 }
519- complete ( ) ;
501+ else {
502+ complete ( ) ;
503+ }
520504 } ) ;
521- ex . addListener ( "error" , function ( e , status ) {
505+ ex . addListener ( "error" , errorHandler || function ( e , status ) {
522506 fail ( "Process exited with code " + status ) ;
523507 } )
524508
@@ -537,7 +521,7 @@ function cleanTestDirs() {
537521 }
538522
539523 jake . mkdirP ( localRwcBaseline ) ;
540- jake . mkdirP ( localTest262Baseline ) ;
524+ jake . mkdirP ( localTest262Baseline ) ;
541525 jake . mkdirP ( localBaseline ) ;
542526}
543527
@@ -548,10 +532,14 @@ function writeTestConfigFile(tests, testConfigFile) {
548532 fs . writeFileSync ( 'test.config' , testConfigContents ) ;
549533}
550534
535+ /* Removes project output
536+ * @async
537+ */
551538function deleteTemporaryProjectOutput ( ) {
552539 if ( fs . existsSync ( path . join ( localBaseline , "projectOutput/" ) ) ) {
553540 jake . rmRf ( path . join ( localBaseline , "projectOutput/" ) ) ;
554541 }
542+ complete ( ) ;
555543}
556544
557545var testTimeout = 20000 ;
@@ -580,14 +568,14 @@ task("runtests", ["tests", builtLocalDirectory], function() {
580568 // timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally
581569 // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
582570 var cmd = host + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run ;
583- console . log ( cmd ) ;
571+
584572 exec ( cmd , deleteTemporaryProjectOutput ) ;
585573} , { async : true } ) ;
586574
587575desc ( "Generates code coverage data via instanbul" )
588576task ( "generate-code-coverage" , [ "tests" , builtLocalDirectory ] , function ( ) {
589577 var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run ;
590- console . log ( cmd ) ;
578+
591579 exec ( cmd ) ;
592580} , { async : true } ) ;
593581
@@ -619,7 +607,6 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function(
619607
620608 tests = tests ? tests : '' ;
621609 var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + tests
622- console . log ( cmd ) ;
623610 exec ( cmd ) ;
624611} , { async : true } ) ;
625612
@@ -635,14 +622,12 @@ function getDiffTool() {
635622desc ( "Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable" ) ;
636623task ( 'diff' , function ( ) {
637624 var cmd = '"' + getDiffTool ( ) + '" ' + refBaseline + ' ' + localBaseline ;
638- console . log ( cmd )
639625 exec ( cmd ) ;
640626} , { async : true } ) ;
641627
642628desc ( "Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable" ) ;
643629task ( 'diff-rwc' , function ( ) {
644630 var cmd = '"' + getDiffTool ( ) + '" ' + refRwcBaseline + ' ' + localRwcBaseline ;
645- console . log ( cmd )
646631 exec ( cmd ) ;
647632} , { async : true } ) ;
648633
@@ -689,13 +674,6 @@ task("webhost", [webhostJsPath], function() {
689674 jake . cpR ( path . join ( builtLocalDirectory , "lib.d.ts" ) , "tests/webhost/" , { silent : true } ) ;
690675} ) ;
691676
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-
699677// Instrumented compiler
700678var loggedIOpath = harnessDirectory + 'loggedIO.ts' ;
701679var loggedIOJsPath = builtLocalDirectory + 'loggedIO.js' ;
@@ -704,14 +682,12 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() {
704682 jake . mkdirP ( temp ) ;
705683 var options = "--outdir " + temp + ' ' + loggedIOpath ;
706684 var cmd = host + " " + LKGDirectory + compilerFilename + " " + options + " " ;
707- console . log ( cmd + "\n" ) ;
708- var ex = jake . createExec ( [ cmd ] ) ;
709- ex . addListener ( "cmdEnd" , function ( ) {
685+
686+ exec ( cmd , function ( ) {
710687 fs . renameSync ( temp + '/harness/loggedIO.js' , loggedIOJsPath ) ;
711688 jake . rmRf ( temp ) ;
712689 complete ( ) ;
713690 } ) ;
714- ex . run ( ) ;
715691} , { async : true } ) ;
716692
717693var instrumenterPath = harnessDirectory + 'instrumenter.ts' ;
@@ -721,10 +697,6 @@ compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath],
721697desc ( "Builds an instrumented tsc.js" ) ;
722698task ( 'tsc-instrumented' , [ loggedIOJsPath , instrumenterJsPath , tscFile ] , function ( ) {
723699 var cmd = host + ' ' + instrumenterJsPath + ' record iocapture ' + builtLocalDirectory + compilerFilename ;
724- console . log ( cmd ) ;
725- var ex = jake . createExec ( [ cmd ] ) ;
726- ex . addListener ( "cmdEnd" , function ( ) {
727- complete ( ) ;
728- } ) ;
729- ex . run ( ) ;
700+
701+ exec ( cmd ) ;
730702} , { async : true } ) ;
0 commit comments