Skip to content

Commit 6531541

Browse files
committed
Hacking; issue with batch writes.
1 parent 7f92cfb commit 6531541

File tree

7 files changed

+33
-25
lines changed

7 files changed

+33
-25
lines changed

_test_common/lib/matchers.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,9 @@ class _AssetGraphMatcher extends Matcher {
189189
}
190190
}
191191
}
192-
if (!equals(_expected.packageLanguageVersions).matches(
193-
item.packageLanguageVersions,
194-
matchState['packageLanguageVersions'] = <String, LanguageVersion?>{},
195-
)) {
192+
if (!equals(
193+
_expected.packageLanguageVersions,
194+
).matches(item.packageLanguageVersions, matchState)) {
196195
matches = false;
197196
}
198197
return matches;

build/lib/src/asset/exceptions.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import 'id.dart';
55

66
class AssetNotFoundException implements Exception {
77
final AssetId assetId;
8+
final String? path;
89

9-
AssetNotFoundException(this.assetId);
10+
AssetNotFoundException(this.assetId, {this.path});
1011

1112
@override
12-
String toString() => 'AssetNotFoundException: $assetId';
13+
String toString() {
14+
if (path == null) return 'AssetNotFoundException: $assetId';
15+
return 'AssetNotFoundException: $assetId ($path)';
16+
}
1317
}
1418

1519
class PackageNotFoundException implements Exception {

build/lib/src/state/asset_path_provider.dart

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@
44

55
import '../asset/id.dart';
66

7-
/// Converts [AssetId] to paths.
7+
/// Converts [AssetId]s to paths.
88
abstract interface class AssetPathProvider {
99
String pathFor(AssetId id);
1010
}
11-
12-
/// Applies a function to an existing [AssetPathProvider].
13-
class OverlayAssetPathProvider implements AssetPathProvider {
14-
AssetPathProvider delegate;
15-
AssetId Function(AssetId) overlay;
16-
17-
OverlayAssetPathProvider({required this.delegate, required this.overlay});
18-
19-
@override
20-
String pathFor(AssetId id) => delegate.pathFor(overlay(id));
21-
}

build_runner_core/lib/src/asset/batch.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ final class _FileSystemWriteBatch {
5858
required AssetReader reader,
5959
required RunnerAssetWriter writer,
6060
}) {
61+
throw 'nope';
6162
final batch = _FileSystemWriteBatch._();
6263

6364
return (BatchReader(reader, batch), BatchWriter(writer, batch));
@@ -165,6 +166,9 @@ final class BatchWriter extends RunnerAssetWriter {
165166

166167
@override
167168
Future<void> writeAsBytes(AssetId id, List<int> bytes) async {
169+
if (id.path.contains('.dart_tool')) {
170+
throw 'whoops: $id, ${StackTrace.current}';
171+
}
168172
_batch._pendingWrites[id] = _PendingFileState(bytes);
169173
}
170174

@@ -174,6 +178,9 @@ final class BatchWriter extends RunnerAssetWriter {
174178
String contents, {
175179
Encoding encoding = utf8,
176180
}) async {
181+
if (id.path.contains('.dart_tool')) {
182+
throw 'whoops: $id';
183+
}
177184
_batch._pendingWrites[id] = _PendingFileState(encoding.encode(contents));
178185
}
179186

build_runner_core/lib/src/asset/build_cache.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,24 @@ class BuildCacheWriter implements RunnerAssetWriter {
6868
}
6969

7070
AssetId _cacheLocation(AssetId id, AssetGraph assetGraph, String rootPackage) {
71+
print('_cacheLocation $id');
7172
if (id.path.startsWith(generatedOutputDirectory) ||
7273
id.path.startsWith(cacheDir)) {
74+
print('--> return 1');
7375
return id;
7476
}
7577
if (!assetGraph.contains(id)) {
78+
print('--> return 2');
7679
return id;
7780
}
7881
final assetNode = assetGraph.get(id);
7982
if (assetNode is GeneratedAssetNode && assetNode.isHidden) {
83+
print('--> hit');
8084
return AssetId(
8185
rootPackage,
8286
'$generatedOutputDirectory/${id.package}/${id.path}',
8387
);
8488
}
89+
print('--> return 3');
8590
return id;
8691
}

build_runner_core/lib/src/asset/file_based.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:glob/list_local_fs.dart';
1313
import 'package:path/path.dart' as path;
1414

1515
import '../package_graph/package_graph.dart';
16+
import 'build_cache.dart';
1617
import 'writer.dart';
1718

1819
/// Basic [AssetReader] which uses a [PackageGraph] to look up where to read
@@ -44,9 +45,9 @@ class FileBasedAssetReader extends AssetReader implements AssetReaderState {
4445
FilesystemCache? cache,
4546
}) => FileBasedAssetReader(
4647
packageGraph,
47-
assetPathProvider: assetPathProvider,
48+
assetPathProvider: assetPathProvider ?? this.assetPathProvider,
4849
filesystem: filesystem,
49-
cache: cache,
50+
cache: cache ?? this.cache,
5051
);
5152

5253
@override
@@ -70,8 +71,10 @@ class FileBasedAssetReader extends AssetReader implements AssetReaderState {
7071
ifAbsent: () async {
7172
final path = assetPathProvider.pathFor(id);
7273
if (!await filesystem.exists(path)) {
73-
// TODO(davidmorgan): report the path as well?
74-
throw AssetNotFoundException(id);
74+
print(
75+
'${assetPathProvider.runtimeType} is missing $path at ${StackTrace.current}',
76+
);
77+
throw AssetNotFoundException(id, path: path);
7578
}
7679
return filesystem.readAsBytes(path);
7780
},
@@ -86,7 +89,8 @@ class FileBasedAssetReader extends AssetReader implements AssetReaderState {
8689
ifAbsent: () async {
8790
final path = assetPathProvider.pathFor(id);
8891
if (!await filesystem.exists(path)) {
89-
throw AssetNotFoundException(id);
92+
print('${assetPathProvider.runtimeType} is missing $path');
93+
throw AssetNotFoundException(id, path: path);
9094
}
9195
return filesystem.readAsBytes(path);
9296
},

build_runner_core/lib/src/environment/io_environment.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class IOEnvironment implements BuildEnvironment {
4646
PackageGraph packageGraph, {
4747
bool? assumeTty,
4848
bool outputSymlinksOnly = false,
49-
bool lowResourcesMode = false,
49+
//bool lowResourcesMode = false,
5050
}) {
5151
if (outputSymlinksOnly && Platform.isWindows) {
5252
_logger.warning(
@@ -60,7 +60,7 @@ class IOEnvironment implements BuildEnvironment {
6060
var fileWriter = FileBasedAssetWriter(packageGraph);
6161

6262
var (reader, writer) =
63-
lowResourcesMode
63+
true
6464
? (fileReader, fileWriter)
6565
: wrapInBatch(reader: fileReader, writer: fileWriter);
6666

0 commit comments

Comments
 (0)