-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Add jake task for making instrumented tsc #581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
18de560
Add jake task for making instrumented tsc
RyanCavanaugh 7ae6739
Correctly handle async calls; fix formatting
RyanCavanaugh 1249e9d
Add timestamp to capture files for better tracking
RyanCavanaugh f328c7c
Handle missing files more gracefully; big perf gains in loggedIO
RyanCavanaugh f2546c1
Correctly handle zero-length test inputs
RyanCavanaugh 0aba039
Speed up RWC IO playback by removing unfound files from resolution ca…
RyanCavanaugh b8b5227
Address CR feedback
RyanCavanaugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,8 @@ function concatenateFiles(destinationFile, sourceFiles) { | |
| } | ||
|
|
||
| var useDebugMode = false; | ||
| var host = (process.env.host || process.env.TYPESCRIPT_HOST || "node"); | ||
| var compilerFilename = "tsc.js"; | ||
| /* 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 | ||
|
|
@@ -134,10 +136,9 @@ var useDebugMode = false; | |
| function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile) { | ||
| file(outFile, prereqs, function() { | ||
| var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory; | ||
| var compilerFilename = "tsc.js"; | ||
| var options = "-removeComments --module commonjs -noImplicitAny "; //" -propagateEnumConstants " | ||
|
|
||
| var cmd = (process.env.host || process.env.TYPESCRIPT_HOST || "node") + " " + dir + compilerFilename + " " + options + " "; | ||
| var cmd = host + " " + dir + compilerFilename + " " + options + " "; | ||
| if (useDebugMode) { | ||
| cmd = cmd + " " + path.join(harnessDirectory, "external/es5compat.ts") + " " + path.join(harnessDirectory, "external/json2.ts") + " "; | ||
| } | ||
|
|
@@ -230,7 +231,7 @@ task("generate-diagnostics", [diagnosticInfoMapTs]) | |
|
|
||
|
|
||
| // Local target to build the compiler and services | ||
| var tscFile = path.join(builtLocalDirectory, "tsc.js"); | ||
| var tscFile = path.join(builtLocalDirectory, compilerFilename); | ||
| compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false); | ||
|
|
||
| var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js"); | ||
|
|
@@ -312,9 +313,9 @@ function exec(cmd, completeHandler) { | |
| complete(); | ||
| }); | ||
| ex.addListener("error", function(e, status) { | ||
| process.stderr.write(status); | ||
| process.stderr.write(e); | ||
| complete(); | ||
| process.stderr.write(status); | ||
| process.stderr.write(e); | ||
| complete(); | ||
| }) | ||
| try{ | ||
| ex.run(); | ||
|
|
@@ -377,9 +378,9 @@ task("runtests", ["tests", builtLocalDirectory], function() { | |
|
|
||
| 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); | ||
| var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run; | ||
| console.log(cmd); | ||
| exec(cmd); | ||
| }, { async: true }); | ||
|
|
||
| // Browser tests | ||
|
|
@@ -464,7 +465,7 @@ compileFile(webhostJsPath, [webhostPath], [tscFile, webhostPath].concat(libraryT | |
|
|
||
| desc("Builds the tsc web host"); | ||
| task("webhost", [webhostJsPath], function() { | ||
| jake.cpR(path.join(builtLocalDirectory, "lib.d.ts"), "tests/webhost/", {silent: true}); | ||
| jake.cpR(path.join(builtLocalDirectory, "lib.d.ts"), "tests/webhost/", {silent: true}); | ||
| }); | ||
|
|
||
| // Perf compiler | ||
|
|
@@ -473,3 +474,36 @@ var perftscJsPath = "built/local/perftsc.js"; | |
| compileFile(perftscJsPath, [perftscPath], [tscFile, perftscPath, "tests/perfsys.ts"].concat(libraryTargets), [], 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'; | ||
| file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() { | ||
| var temp = builtLocalDirectory + 'temp'; | ||
| 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() { | ||
| fs.renameSync(temp + '/harness/loggedIO.js', loggedIOJsPath); | ||
| jake.rmRf(temp); | ||
| complete(); | ||
| }); | ||
| ex.run(); | ||
| }, {async: true}); | ||
|
|
||
| var instrumenterPath = harnessDirectory + 'instrumenter.ts'; | ||
| var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js'; | ||
| compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath], [], true); | ||
|
|
||
| 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() { | ||
| complete(); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, call complete() |
||
| ex.run(); | ||
| }, { async: true }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| declare var require: any, process: any; | ||
| var fs: any = require('fs'); | ||
| var path: any = require('path'); | ||
|
|
||
| function instrumentForRecording(fn: string, tscPath: string) { | ||
| instrument(tscPath, 'sys = Playback.wrapSystem(sys); sys.startRecord("' + fn + '");', 'sys.endRecord();'); | ||
| } | ||
|
|
||
| function instrumentForReplay(logFilename: string, tscPath: string) { | ||
| instrument(tscPath, 'sys = Playback.wrapSystem(sys); sys.startReplay("' + logFilename + '");'); | ||
| } | ||
|
|
||
| function instrument(tscPath: string, prepareCode: string, cleanupCode: string = '') { | ||
| var bak = tscPath + '.bak'; | ||
| fs.exists(bak, (backupExists: boolean) => { | ||
| var filename = tscPath; | ||
| if (backupExists) { | ||
| filename = bak; | ||
| } | ||
|
|
||
| fs.readFile(filename, 'utf-8', (err: any, tscContent: string) => { | ||
| if (err) throw err; | ||
|
|
||
| fs.writeFile(bak, tscContent, (err: any) => { | ||
| if (err) throw err; | ||
|
|
||
| fs.readFile(path.resolve(path.dirname(tscPath) + '/loggedIO.js'), 'utf-8', (err: any, loggerContent: string) => { | ||
| if (err) throw err; | ||
|
|
||
| var invocationLine = 'ts.executeCommandLine(sys.args);'; | ||
| var index1 = tscContent.indexOf(invocationLine); | ||
| var index2 = index1 + invocationLine.length; | ||
| var newContent = tscContent.substr(0, index1) + loggerContent + prepareCode + invocationLine + cleanupCode + tscContent.substr(index2) + '\r\n'; | ||
| fs.writeFile(tscPath, newContent); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| var isJson = (arg: string) => arg.indexOf(".json") > 0; | ||
|
|
||
| var record = process.argv.indexOf('record'); | ||
| var tscPath = process.argv[process.argv.length - 1]; | ||
| if (record >= 0) { | ||
| console.log('Instrumenting ' + tscPath + ' for recording'); | ||
| instrumentForRecording(process.argv[record + 1], tscPath); | ||
| } else if (process.argv.some(isJson)) { | ||
| var filename = process.argv.filter(isJson)[0]; | ||
| instrumentForReplay(filename, tscPath); | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this can be evaluated here. It may be set by the task...