Skip to content

Commit 6ffee10

Browse files
authored
Split rwc input files (#18772)
* Handle translation between new and old log format styles * Iteration * Strip all backcompat * Remove new parenthesis * Handle directories in the test perf heuristic measurement * Optional catch bindings!
1 parent ecef2dc commit 6ffee10

File tree

6 files changed

+105
-18
lines changed

6 files changed

+105
-18
lines changed

Gulpfile.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,9 @@ gulp.task(instrumenterJsPath, /*help*/ false, [servicesFile], () => {
978978
.pipe(gulp.dest(builtLocalDirectory));
979979
});
980980

981-
gulp.task("tsc-instrumented", "Builds an instrumented tsc.js", ["local", loggedIOJsPath, instrumenterJsPath, servicesFile], (done) => {
982-
exec(host, [instrumenterJsPath, "record", "iocapture", builtLocalCompiler], done, done);
981+
gulp.task("tsc-instrumented", "Builds an instrumented tsc.js - run with --test=[testname]", ["local", loggedIOJsPath, instrumenterJsPath, servicesFile], (done) => {
982+
const test = cmdLineOptions["tests"] || "iocapture";
983+
exec(host, [instrumenterJsPath, "record", test, builtLocalCompiler], done, done);
983984
});
984985

985986
gulp.task("update-sublime", "Updates the sublime plugin's tsserver", ["local", serverFile], () => {

Jakefile.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,10 @@ var instrumenterPath = harnessDirectory + 'instrumenter.ts';
11041104
var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js';
11051105
compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath].concat(libraryTargets), [], /*useBuiltCompiler*/ true, { lib: "es6", types: ["node"], noOutFile: true, outDir: builtLocalDirectory });
11061106

1107-
desc("Builds an instrumented tsc.js");
1107+
desc("Builds an instrumented tsc.js - run with test=[testname]");
11081108
task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function () {
1109-
var cmd = host + ' ' + instrumenterJsPath + ' record iocapture ' + builtLocalDirectory + compilerFilename;
1109+
var test = process.env.test || process.env.tests || process.env.t || "iocapture";
1110+
var cmd = host + ' ' + instrumenterJsPath + " record " + test + " " + builtLocalDirectory + compilerFilename;
11101111
console.log(cmd);
11111112
var ex = jake.createExec([cmd]);
11121113
ex.addListener("cmdEnd", function () {

src/harness/harness.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,8 +1717,12 @@ namespace Harness {
17171717
return resultName;
17181718
}
17191719

1720-
function sanitizeTestFilePath(name: string) {
1721-
return ts.toPath(ts.normalizeSlashes(name.replace(/[\^<>:"|?*%]/g, "_")).replace(/\.\.\//g, "__dotdot/"), "", Utils.canonicalizeForHarness);
1720+
export function sanitizeTestFilePath(name: string) {
1721+
const path = ts.toPath(ts.normalizeSlashes(name.replace(/[\^<>:"|?*%]/g, "_")).replace(/\.\.\//g, "__dotdot/"), "", Utils.canonicalizeForHarness);
1722+
if (ts.startsWith(path, "/")) {
1723+
return path.substring(1);
1724+
}
1725+
return path;
17221726
}
17231727

17241728
// This does not need to exist strictly speaking, but many tests will need to be updated if it's removed
@@ -2068,7 +2072,7 @@ namespace Harness {
20682072
for (let {done, value} = gen.next(); !done; { done, value } = gen.next()) {
20692073
const [name, content, count] = value as [string, string, number | undefined];
20702074
if (count === 0) continue; // Allow error reporter to skip writing files without errors
2071-
const relativeFileName = relativeFileBase + (ts.startsWith(name, "/") ? "" : "/") + name + extension;
2075+
const relativeFileName = relativeFileBase + "/" + name + extension;
20722076
const actualFileName = localPath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder);
20732077
const comparison = compareToBaseline(content, relativeFileName, opts);
20742078
try {

src/harness/loggedIO.ts

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
/// <reference path="..\..\src\harness\typeWriter.ts" />
66

77
interface FileInformation {
8-
contents: string;
8+
contents?: string;
9+
contentsPath?: string;
910
codepage: number;
11+
bom?: string;
1012
}
1113

1214
interface FindFileResult {
@@ -27,13 +29,15 @@ interface IOLog {
2729
filesRead: IOLogFile[];
2830
filesWritten: {
2931
path: string;
30-
contents: string;
32+
contents?: string;
33+
contentsPath?: string;
3134
bom: boolean;
3235
}[];
3336
filesDeleted: string[];
3437
filesAppended: {
3538
path: string;
36-
contents: string;
39+
contents?: string;
40+
contentsPath?: string;
3741
}[];
3842
fileExists: {
3943
path: string;
@@ -129,6 +133,72 @@ namespace Playback {
129133
};
130134
}
131135

136+
export function newStyleLogIntoOldStyleLog(log: IOLog, host: ts.System | Harness.IO, baseName: string) {
137+
for (const file of log.filesAppended) {
138+
if (file.contentsPath) {
139+
file.contents = host.readFile(ts.combinePaths(baseName, file.contentsPath));
140+
delete file.contentsPath;
141+
}
142+
}
143+
for (const file of log.filesWritten) {
144+
if (file.contentsPath) {
145+
file.contents = host.readFile(ts.combinePaths(baseName, file.contentsPath));
146+
delete file.contentsPath;
147+
}
148+
}
149+
for (const file of log.filesRead) {
150+
if (file.result.contentsPath) {
151+
// `readFile` strips away a BOM (and actually reinerprets the file contents according to the correct encoding)
152+
// - but this has the unfortunate sideeffect of removing the BOM from any outputs based on the file, so we readd it here.
153+
file.result.contents = (file.result.bom || "") + host.readFile(ts.combinePaths(baseName, file.result.contentsPath));
154+
delete file.result.contentsPath;
155+
}
156+
}
157+
return log;
158+
}
159+
160+
export function oldStyleLogIntoNewStyleLog(log: IOLog, writeFile: typeof Harness.IO.writeFile, baseTestName: string) {
161+
if (log.filesAppended) {
162+
for (const file of log.filesAppended) {
163+
if (file.contents !== undefined) {
164+
file.contentsPath = ts.combinePaths("appended", Harness.Compiler.sanitizeTestFilePath(file.path));
165+
writeFile(ts.combinePaths(baseTestName, file.contentsPath), file.contents);
166+
delete file.contents;
167+
}
168+
}
169+
}
170+
if (log.filesWritten) {
171+
for (const file of log.filesWritten) {
172+
if (file.contents !== undefined) {
173+
file.contentsPath = ts.combinePaths("written", Harness.Compiler.sanitizeTestFilePath(file.path));
174+
writeFile(ts.combinePaths(baseTestName, file.contentsPath), file.contents);
175+
delete file.contents;
176+
}
177+
}
178+
}
179+
if (log.filesRead) {
180+
for (const file of log.filesRead) {
181+
const { contents } = file.result;
182+
if (contents !== undefined) {
183+
file.result.contentsPath = ts.combinePaths("read", Harness.Compiler.sanitizeTestFilePath(file.path));
184+
writeFile(ts.combinePaths(baseTestName, file.result.contentsPath), contents);
185+
const len = contents.length;
186+
if (len >= 2 && contents.charCodeAt(0) === 0xfeff) {
187+
file.result.bom = "\ufeff";
188+
}
189+
if (len >= 2 && contents.charCodeAt(0) === 0xfffe) {
190+
file.result.bom = "\ufffe";
191+
}
192+
if (len >= 3 && contents.charCodeAt(0) === 0xefbb && contents.charCodeAt(1) === 0xbf) {
193+
file.result.bom = "\uefbb\xbf";
194+
}
195+
delete file.result.contents;
196+
}
197+
}
198+
}
199+
return log;
200+
}
201+
132202
function initWrapper(wrapper: PlaybackSystem, underlying: ts.System): void;
133203
function initWrapper(wrapper: PlaybackIO, underlying: Harness.IO): void;
134204
function initWrapper(wrapper: PlaybackSystem | PlaybackIO, underlying: ts.System | Harness.IO): void {
@@ -164,9 +234,9 @@ namespace Playback {
164234
wrapper.endRecord = () => {
165235
if (recordLog !== undefined) {
166236
let i = 0;
167-
const fn = () => recordLogFileNameBase + i + ".json";
168-
while (underlying.fileExists(fn())) i++;
169-
underlying.writeFile(fn(), JSON.stringify(recordLog));
237+
const fn = () => recordLogFileNameBase + i;
238+
while (underlying.fileExists(fn() + ".json")) i++;
239+
underlying.writeFile(ts.combinePaths(fn(), "test.json"), JSON.stringify(oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(ts.combinePaths(fn(), path), string), fn()), null, 4)); // tslint:disable-line:no-null-keyword
170240
recordLog = undefined;
171241
}
172242
};

src/harness/parallel/host.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,19 @@ namespace Harness.Parallel.Host {
5757
for (const file of files) {
5858
let size: number;
5959
if (!perfData) {
60-
size = statSync(file).size;
61-
60+
try {
61+
size = statSync(file).size;
62+
}
63+
catch {
64+
// May be a directory
65+
try {
66+
size = Harness.IO.listFiles(file, /.*/g, { recursive: true }).reduce((acc, elem) => acc + statSync(elem).size, 0);
67+
}
68+
catch {
69+
// Unknown test kind, just return 0 and let the historical analysis take over after one run
70+
size = 0;
71+
}
72+
}
6273
}
6374
else {
6475
const hashedName = hashName(runner.kind(), file);

src/harness/rwcRunner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace RWC {
3636
Subfolder: "rwc",
3737
Baselinefolder: "internal/baselines"
3838
};
39-
const baseName = /(.*)\/(.*).json/.exec(ts.normalizeSlashes(jsonPath))[2];
39+
const baseName = ts.getBaseFileName(jsonPath);
4040
let currentDirectory: string;
4141
let useCustomLibraryFile: boolean;
4242
let skipTypeAndSymbolbaselines = false;
@@ -61,7 +61,7 @@ namespace RWC {
6161
this.timeout(800000); // Allow long timeouts for RWC compilations
6262
let opts: ts.ParsedCommandLine;
6363

64-
const ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath));
64+
const ioLog: IOLog = Playback.newStyleLogIntoOldStyleLog(JSON.parse(Harness.IO.readFile(`internal/cases/rwc/${jsonPath}/test.json`)), Harness.IO, `internal/cases/rwc/${baseName}`);
6565
currentDirectory = ioLog.currentDirectory;
6666
useCustomLibraryFile = ioLog.useCustomLibraryFile;
6767
skipTypeAndSymbolbaselines = ioLog.filesRead.reduce((acc, elem) => (elem && elem.result && elem.result.contents) ? acc + elem.result.contents.length : acc, 0) > typeAndSymbolSizeLimit;
@@ -253,7 +253,7 @@ namespace RWC {
253253

254254
class RWCRunner extends RunnerBase {
255255
public enumerateTestFiles() {
256-
return Harness.IO.listFiles("internal/cases/rwc/", /.+\.json$/);
256+
return Harness.IO.getDirectories("internal/cases/rwc/");
257257
}
258258

259259
public kind(): TestRunnerKind {

0 commit comments

Comments
 (0)