Skip to content

Commit f328c7c

Browse files
committed
Handle missing files more gracefully; big perf gains in loggedIO
1 parent 1249e9d commit f328c7c

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

src/harness/harness.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,10 @@ module Harness {
732732

733733
var filemap: { [name: string]: ts.SourceFile; } = {};
734734
var register = (file: { unitName: string; content: string; }) => {
735-
var filename = Path.switchToForwardSlashes(file.unitName);
736-
filemap[getCanonicalFileName(filename)] = ts.createSourceFile(filename, file.content, options.target, /*version:*/ "0");
735+
if (file.content) {
736+
var filename = Path.switchToForwardSlashes(file.unitName);
737+
filemap[getCanonicalFileName(filename)] = ts.createSourceFile(filename, file.content, options.target, /*version:*/ "0");
738+
}
737739
};
738740
inputFiles.forEach(register);
739741
otherFiles.forEach(register);
@@ -824,7 +826,7 @@ module Harness {
824826
globalErrors.forEach(err => outputErrorText(err));
825827

826828
// 'merge' the lines of each input file with any errors associated with it
827-
inputFiles.forEach(inputFile => {
829+
inputFiles.filter(f => f.content !== undefined).forEach(inputFile => {
828830
// Filter down to the errors in the file
829831
var fileErrors = diagnostics.filter(e => {
830832
var errFn = e.filename;
@@ -1253,7 +1255,7 @@ module Harness {
12531255
}
12541256

12551257
export function isLibraryFile(filePath: string): boolean {
1256-
return filePath.indexOf('lib.d.ts') >= 0 || filePath.indexOf('lib.core.d.ts') >= 0;
1258+
return (Path.getFileName(filePath) === 'lib.d.ts') || (Path.getFileName(filePath) === 'lib.core.d.ts');
12571259
}
12581260

12591261
if (Error) (<any>Error).stackTraceLimit = 1;

src/harness/loggedIO.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,46 @@ module Playback {
173173
}
174174

175175
function findResultByPath<T>(wrapper: { resolvePath(s: string): string }, logArray: { path: string; result?: T }[], expectedPath: string, defaultValue?: T): T {
176-
var results = logArray.filter(e => pathsAreEquivalent(e.path, expectedPath, wrapper));
177-
if (results.length === 0) {
178-
if (defaultValue === undefined) {
179-
throw new Error('No matching result in log array for path: ' + expectedPath);
180-
} else {
181-
return defaultValue;
176+
var normalizedName = Harness.Path.switchToForwardSlashes(expectedPath).toLowerCase();
177+
// Try to find the result through normal filename
178+
for (var i = 0; i < logArray.length; i++) {
179+
if (Harness.Path.switchToForwardSlashes(logArray[i].path).toLowerCase() === normalizedName) {
180+
return logArray[i].result;
182181
}
183182
}
184-
return results[0].result;
183+
// Fallback, try to resolve the target paths as well
184+
if (replayLog.pathsResolved.length > 0) {
185+
var normalizedResolvedName = wrapper.resolvePath(expectedPath).toLowerCase();
186+
for (var i = 0; i < logArray.length; i++) {
187+
if (wrapper.resolvePath(logArray[i].path).toLowerCase() === normalizedResolvedName) {
188+
return logArray[i].result;
189+
}
190+
}
191+
}
192+
// If we got here, we didn't find a match
193+
if (defaultValue === undefined) {
194+
throw new Error('No matching result in log array for path: ' + expectedPath);
195+
} else {
196+
return defaultValue;
197+
}
185198
}
186199

200+
var pathEquivCache: any = {};
187201
function pathsAreEquivalent(left: string, right: string, wrapper: { resolvePath(s: string): string }) {
202+
var key = left + '-~~-' + right;
188203
function areSame(a: string, b: string) {
189204
return Harness.Path.switchToForwardSlashes(a).toLowerCase() === Harness.Path.switchToForwardSlashes(b).toLowerCase();
190205
}
191-
return areSame(left, right) || areSame(wrapper.resolvePath(left), right) || areSame(left, wrapper.resolvePath(right)) || areSame(wrapper.resolvePath(left), wrapper.resolvePath(right));
206+
function check() {
207+
if (Harness.Path.getFileName(left).toLowerCase() === Harness.Path.getFileName(right).toLowerCase()) {
208+
return areSame(left, right) || areSame(wrapper.resolvePath(left), right) || areSame(left, wrapper.resolvePath(right)) || areSame(wrapper.resolvePath(left), wrapper.resolvePath(right));
209+
}
210+
}
211+
if (pathEquivCache.hasOwnProperty(key)) {
212+
return pathEquivCache[key];
213+
} else {
214+
return pathEquivCache[key] = check();
215+
}
192216
}
193217

194218
function noOpReplay(name: string) {

src/harness/rwcRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ module RWC {
8989
});
9090

9191
// do not use lib since we shouldnt be reading any files that arent in the ioLog
92-
opts.options.noLib = true;
92+
opts.options.noLib = false;
9393

9494
// Emit the results
9595
harnessCompiler.compileFiles(inputFiles, otherFiles, compileResult => {

0 commit comments

Comments
 (0)