-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJakefile
457 lines (416 loc) · 14.8 KB
/
Jakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
// This file contains the build logic for the public repo
var fs = require("fs");
var path = require("path");
// Variables
var compilerDirectory = "src/compiler/";
var servicesDirectory = "src/services/";
var harnessDirectory = "src/harness/";
var runnersDirectory = "tests/runners/";
var libraryDirectory = "typings/";
var builtDirectory = "built/";
var builtLocalDirectory = "built/local/";
var builtTestDirectory = "built/localtest/";
var LKGDirectory = "bin/";
var copyright = "CopyrightNotice.txt";
var thirdParty = "ThirdPartyNoticeText.txt";
var compilerSources = [
"ast.ts",
"astPath.ts",
"astWalker.ts",
"base64.ts",
"bloomFilter.ts",
"declarationEmitter.ts",
"diagnostics.ts",
"emitter.ts",
"enumerator.ts",
"flags.ts",
"hashTable.ts",
"identifierWalker.ts",
"nodeTypes.ts",
"pathUtils.ts",
"precompile.ts",
"process.ts",
"referenceResolution.ts",
"referenceResolver.ts",
"sourceMapping.ts",
"syntaxTreeToAstVisitor.ts",
"types.ts",
"core/arrayUtilities.ts",
"core/constants.ts",
"core/debug.ts",
"core/diagnostic.ts",
"core/diagnosticCategory.ts",
"core/diagnosticInfo.ts",
"core/environment.ts",
"core/errors.ts",
"core/hash.ts",
"core/hashTable.ts",
"core/integerUtilities.ts",
"core/mathPrototype.ts",
"core/references.ts",
"core/require.ts",
"core/stringTable.ts",
"core/stringUtilities.ts",
"core/timer.ts",
"resources/diagnosticCode.generated.ts",
"resources/diagnosticInformationMap.generated.ts",
"resources/references.ts",
"syntax/characterInfo.ts",
"syntax/constants.ts",
"syntax/depthLimitedWalker.ts",
"syntax/formattingOptions.ts",
"syntax/indentation.ts",
"syntax/languageVersion.ts",
"syntax/parseOptions.ts",
"syntax/parser.ts",
"syntax/positionedElement.ts",
"syntax/positionTrackingWalker.ts",
"syntax/references.ts",
"syntax/scanner.ts",
"syntax/scannerUtilities.generated.ts",
"syntax/separatedSyntaxList.ts",
"syntax/slidingWindow.ts",
"syntax/strings.ts",
"syntax/syntax.ts",
"syntax/syntaxDedenter.ts",
"syntax/syntaxElement.ts",
"syntax/syntaxFactory.generated.ts",
"syntax/syntaxFacts.ts",
"syntax/syntaxFacts2.ts",
"syntax/syntaxIndenter.ts",
"syntax/syntaxInformationMap.ts",
"syntax/syntaxIndenter.ts",
"syntax/syntaxKind.ts",
"syntax/syntaxList.ts",
"syntax/syntaxNode.ts",
"syntax/syntaxNodeInvariantsChecker.ts",
"syntax/syntaxNodeOrToken.ts",
"syntax/syntaxNodes.generated.ts",
"syntax/syntaxRewriter.generated.ts",
"syntax/syntaxToken.generated.ts",
"syntax/syntaxToken.ts",
"syntax/syntaxTokenReplacer.ts",
"syntax/syntaxTree.ts",
"syntax/syntaxTrivia.ts",
"syntax/syntaxTriviaList.ts",
"syntax/syntaxUtilities.ts",
"syntax/syntaxVisitor.generated.ts",
"syntax/syntaxWalker.generated.ts",
"syntax/textSpanWalker.ts",
"syntax/unicode.ts",
"text/characterCodes.ts",
"text/lineAndCharacter.ts",
"text/lineMap.ts",
"text/linePosition.ts",
"text/references.ts",
"text/scriptSnapshot.ts",
"text/text.ts",
"text/textChangeRange.ts",
"text/textFactory.ts",
"text/textLine.ts",
"text/textSpan.ts",
"text/textUtilities.ts",
"typecheck/dataMap.ts",
"typecheck/pullDeclCollection.ts",
"typecheck/pullDecls.ts",
"typecheck/pullFlags.ts",
"typecheck/pullHelpers.ts",
"typecheck/pullSemanticInfo.ts",
"typecheck/pullSymbolBinder.ts",
"typecheck/pullSymbolBindingContext.ts",
"typecheck/pullSymbols.ts",
"typecheck/pullTypeResolution.ts",
"typecheck/pullTypeResolutionContext.ts",
"typecheck/SemanticDiagnostic.ts",
"typescript.ts"
].map(function (f) {
return path.join(compilerDirectory, f);
});
var tscSources = [
"io.ts",
"optionsParser.ts",
"tsc.ts"
].map(function (f) {
return path.join(compilerDirectory, f);
});
var servicesSources = [
"braceMatcher.ts",
"breakpoints.ts",
"classifier.ts",
"compilerState.ts",
"completionHelpers.ts",
"completionSession.ts",
"coreServices.ts",
"getScriptLexicalStructureWalker.ts",
"diagnosticServices.ts",
"es5compat.ts",
"findReferenceHelpers.ts",
"indenter.ts",
"keywordCompletions.ts",
"languageService.ts",
"outliningElementsCollector.ts",
"pullLanguageService.ts",
"shims.ts",
"signatureInfoHelpers.ts",
"formatting/formatter.ts",
"formatting/formatting.ts",
"formatting/formattingContext.ts",
"formatting/formattingManager.ts",
"formatting/formattingRequestKind.ts",
"formatting/indentationNodeContext.ts",
"formatting/indentationNodeContextPool.ts",
"formatting/indentationTrackingWalker.ts",
"formatting/multipleTokenIndenter.ts",
"formatting/rule.ts",
"formatting/ruleAction.ts",
"formatting/ruleDescriptor.ts",
"formatting/ruleFlag.ts",
"formatting/ruleOperation.ts",
"formatting/ruleOperationContext.ts",
"formatting/rules.ts",
"formatting/rulesMap.ts",
"formatting/rulesProvider.ts",
"formatting/singleTokenIndenter.ts",
"formatting/snapshotPoint.ts",
"formatting/textEditInfo.ts",
"formatting/textSnapshot.ts",
"formatting/textSnapshotLine.ts",
"formatting/tokenRange.ts",
"formatting/tokenSpan.ts",
"typescriptServices.ts"
].map(function (f) {
return path.join(servicesDirectory, f);
});
var harnessSources = [
path.join(compilerDirectory, "io.ts"),
path.join(compilerDirectory, "optionsParser.ts"),
path.join(harnessDirectory, "exec.ts"),
path.join(harnessDirectory, "diff.ts"),
path.join(harnessDirectory, "harness.ts"),
path.join(harnessDirectory, "baselining.ts"),
path.join(harnessDirectory, "fourslash.ts"),
path.join(harnessDirectory, "dumpAST-baselining.ts"),
path.join(harnessDirectory, "runner.ts"),
path.join(runnersDirectory, "runnerbase.ts"),
path.join(runnersDirectory, "compiler/runner.ts"),
path.join(runnersDirectory, "fourslash/fsrunner.ts"),
path.join(runnersDirectory, "projects/runner.ts"),
path.join(runnersDirectory, "unittest/unittestrunner.ts")
];
var libraryFiles = [
"lib.d.ts",
"jquery.d.ts",
"winjs.d.ts",
"winrt.d.ts"
];
var librarySources = libraryFiles.map(function (f) {
return path.join(libraryDirectory, f);
});
var libraryTargets = libraryFiles.map(function (f) {
return path.join(builtLocalDirectory, f);
});
// Prepends the contents of prefixFile to destinationFile
function prependFile(prefixFile, destinationFile) {
if (!fs.existsSync(prefixFile)) {
fail(prefixFile + " does not exist!");
}
if (!fs.existsSync(destinationFile)) {
fail(destinationFile + " failed to be created!");
}
var temp = "temptemp";
jake.cpR(prefixFile, temp);
fs.appendFileSync(temp, fs.readFileSync(destinationFile));
fs.renameSync(temp, destinationFile);
}
var useDebugMode = false;
/* 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
* @param prefixes: a list of files to prepend to the target file
* @param useBuiltCompiler: true to use the built compiler, false to use the LKG
*/
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler) {
file(outFile, prereqs, function() {
var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory;
var cmd = (process.env.host || process.env.TYPESCRIPT_HOST || "node") + " " + dir + "tsc.js -removeComments -propagateEnumConstants -declaration -noImplicitAny --module commonjs " + sources.join(" ") + " -out " + outFile;
if (useDebugMode) {
cmd = cmd + " -sourcemap -mapRoot file:///" + path.resolve(path.dirname(outFile));
}
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);
});
ex.addListener("cmdEnd", function() {
if (!useDebugMode && prefixes && fs.existsSync(outFile)) {
for (var i in prefixes) {
prependFile(prefixes[i], outFile);
}
}
complete();
});
ex.addListener("error", function() {
fs.unlinkSync(outFile);
console.log("Compilation of " + outFile + " unsuccessful");
});
ex.run();
}, {async: true});
}
// Prerequisite task for built directory and library typings
directory(builtLocalDirectory);
for (var i in libraryTargets) {
(function (i) {
file(libraryTargets[i], [builtLocalDirectory, librarySources[i]], function() {
jake.cpR(librarySources[i], builtLocalDirectory);
});
})(i);
}
var typescriptFile = path.join(builtLocalDirectory, "typescript.js");
compileFile(typescriptFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright]);
var tscFile = path.join(builtLocalDirectory, "tsc.js");
compileFile(tscFile, compilerSources.concat(tscSources), [builtLocalDirectory, copyright].concat(compilerSources).concat(tscSources), [copyright]);
var serviceFile = path.join(builtLocalDirectory, "typescriptServices.js");
compileFile(serviceFile, compilerSources.concat(servicesSources), [builtLocalDirectory, thirdParty, copyright].concat(compilerSources).concat(servicesSources), [thirdParty, copyright]);
// Local target to build the compiler and services
desc("Builds the full compiler and services");
task("local", libraryTargets.concat([typescriptFile, tscFile, serviceFile]));
// Local target to build the compiler and services
desc("Emit debug mode files with sourcemaps");
task("setDebugMode", function() {
useDebugMode = true;
});
// Local target to build the compiler and services
desc("Builds the full compiler and services in debug mode");
task("local-debug", ["setDebugMode", "local"]);
// Set the default task to "local"
task("default", ["local"]);
// Cleans the built directory
desc("Cleans the compiler output, declare files, and tests");
task("clean", function() {
jake.rmRf(builtDirectory);
});
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
desc("Makes a new LKG out of the built js files");
task("LKG", libraryTargets, function() {
var expectedFiles = [typescriptFile, tscFile, serviceFile];
var missingFiles = expectedFiles.filter(function (f) {
return !fs.existsSync(f);
});
if (missingFiles.length > 0) {
fail("Cannot replace the LKG unless all built targets are present in directory " + builtLocalDirectory +
". The following files are missing:\n" + missingFiles.join("\n"));
}
// Copy all the targets into the LKG directory
jake.mkdirP(LKGDirectory);
for (var i in librarySources) {
jake.cpR(libraryTargets[i], LKGDirectory);
}
for (i in expectedFiles) {
jake.cpR(expectedFiles[i], LKGDirectory);
}
});
// Test directory
directory(builtTestDirectory);
// Task to build the tests infrastructure using the built compiler
var run = path.join(builtTestDirectory, "run.js");
var json2 = path.join(harnessDirectory, "external/json2.js")
compileFile(run, harnessSources, [builtTestDirectory, tscFile].concat(libraryTargets).concat(harnessSources), [json2], true);
// Webharness
var frontEndPath = "tests/cases/webharness/frontEnd.ts";
var perfCompilerPath = "tests/cases/webharness/perfCompiler.js";
compileFile(perfCompilerPath, [frontEndPath], [tscFile], [], true);
// Fidelity Tests
var fidelityTestsOutFile = "tests/Fidelity/program.js";
var fidelityTestsInFile = "tests/Fidelity/Program.ts";
compileFile(fidelityTestsOutFile, [fidelityTestsInFile], [tscFile], [], true);
desc("Builds the web harness front end");
task("test-harness", [perfCompilerPath]);
var localBaseline = "tests/baselines/local/";
var refBaseline = "tests/baselines/reference/";
desc("Builds the test infrastructure using the built compiler");
task("tests", [run, serviceFile, perfCompilerPath, fidelityTestsOutFile].concat(libraryTargets), function() {
// Copy the language service over to the test directory
jake.cpR(serviceFile, builtTestDirectory);
jake.cpR(path.join(libraryDirectory, "lib.d.ts"), builtTestDirectory);
});
desc("Runs the tests using the built run.js file. Syntax is jake runtests. Optional parameters 'host=' and 'tests='.");
task("runtests", ["local", "tests", builtTestDirectory], function() {
// Clean the local baselines directory
if (fs.existsSync(localBaseline)) {
jake.rmRf(localBaseline);
}
jake.mkdirP(localBaseline);
host = process.env.host || process.env.TYPESCRIPT_HOST || "node";
tests = process.env.test || process.env.tests;
tests = tests ? tests.split(',').join(' ') : ([].slice.call(arguments).join(' ') || "");
var cmd = host + " " + run + " " + tests;
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() {
complete();
});
ex.run();
}, {async: true});
desc("Builds the test sources and automation in debug mode");
task("tests-debug", ["setDebugMode", "tests"]);
// Makes the test results the new baseline
desc("Makes the most recent test results the new baseline, overwriting the old baseline");
task("baseline-accept", function() {
jake.rmRf(refBaseline);
fs.renameSync(localBaseline, refBaseline);
});
// Syntax Generator
var syntaxGeneratorOutFile = compilerDirectory + "syntax/SyntaxGenerator.js";
var syntaxGeneratorInFile = compilerDirectory + "syntax/SyntaxGenerator.ts";
// Note from Matt Browne: set this to false if the run-syntax-generator task fails;
// also see documentation in dci-docs folder for more details
var useBuiltCompiler = false;
compileFile(syntaxGeneratorOutFile, [syntaxGeneratorInFile], [tscFile], [], useBuiltCompiler);
desc("Builds and runs the syntax generator");
task("run-syntax-generator", [syntaxGeneratorOutFile], function() {
host = process.env.host || process.env.TYPESCRIPT_HOST || "node";
var cmd = host + " " + syntaxGeneratorOutFile;
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() {
complete();
});
ex.run();
}, {async: true});
desc("Builds and runs the Fidelity tests");
task("run-fidelity-tests", [fidelityTestsOutFile], function() {
host = process.env.host || process.env.TYPESCRIPT_HOST || "node";
var cmd = host + " " + fidelityTestsOutFile;
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() {
complete();
});
ex.run();
}, {async: true});