[dart2js] Fix file read logic for diagnostic reporting.
- Rather than gating reads on URIs we've seen, gate logic on file scheme. Any URI with a 'file' scheme should be readable.
- Use unmapped URI when creating SourceFile. For providers that expand their URIS (e.g. BazelRootProvider) this will make sure we're using the more readable form rather than the prefix substituted version.
Change-Id: I89a00e48a6ed4fc83d403b34c42092fcc42a8b56
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294961
Commit-Queue: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
diff --git a/pkg/compiler/lib/src/source_file_provider.dart b/pkg/compiler/lib/src/source_file_provider.dart
index 31870be..30db208 100644
--- a/pkg/compiler/lib/src/source_file_provider.dart
+++ b/pkg/compiler/lib/src/source_file_provider.dart
@@ -23,7 +23,7 @@
Uri cwd = Uri.base;
int dartCharactersRead = 0;
SourceFileByteReader byteReader;
- final Set<Uri> _readableUris = {};
+ final Set<Uri> _registeredUris = {};
final Map<Uri, Uri> _mappedUris = {};
SourceFileProvider(this.byteReader);
@@ -58,14 +58,12 @@
}
// Do not register URIs with schemes other than 'file' as these are internal
// libraries that we cannot read later.
- if (resourceUri.isScheme('file')) {
- registerUri(resourceUri);
- }
+ registerUri(resourceUri);
}
/// Registers the URI and returns true if the URI is new.
bool registerUri(Uri uri) {
- return _readableUris.add(uri);
+ return _registeredUris.add(uri);
}
api.Input<List<int>> _readFromFileSync(Uri uri, api.InputKind inputKind) {
@@ -86,8 +84,7 @@
if (resourceUri != uri) {
registerUri(uri);
}
- return _sourceToFile(
- Uri.parse(relativizeUri(resourceUri)), source, inputKind);
+ return _sourceToFile(Uri.parse(relativizeUri(uri)), source, inputKind);
}
/// Read [resourceUri] directly as a UTF-8 file. If reading fails, `null` is
@@ -115,9 +112,10 @@
/// Get the bytes for a previously accessed UTF-8 [Uri].
api.Input<List<int>>? getUtf8SourceFile(Uri resourceUri) {
- // Only access files we've previously processed and therefore know exist.
- // This is less expensive than performing an IO exists operation.
- return _readableUris.contains(resourceUri)
+ if (!resourceUri.isAbsolute) {
+ resourceUri = cwd.resolveUri(resourceUri);
+ }
+ return resourceUri.isScheme('file')
? _readFromFileSync(resourceUri, api.InputKind.UTF8)
: null;
}
@@ -127,7 +125,7 @@
// Note: this includes also indirect sources that were used to create
// `.dill` inputs to the compiler. This is OK, since this API is only
// used to calculate DEPS for gn build systems.
- Iterable<Uri> getSourceUris() => [..._readableUris, ..._mappedUris.keys];
+ Iterable<Uri> getSourceUris() => [..._registeredUris, ..._mappedUris.keys];
}
class MemoryCopySourceFileByteReader implements SourceFileByteReader {