Skip to content

Commit 30f13d5

Browse files
committed
Fix build_modules for AOT.
1 parent e4091bc commit 30f13d5

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

build_modules/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 5.1.2
2+
3+
- Make compatible with `dart run build_runner build --force-aot`.
4+
15
## 5.1.1
26

37
- Fix re-add `multiRootScheme` to build_modules exports.

build_modules/lib/src/scratch_space.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final scratchSpaceResource = Resource<ScratchSpace>(
3333
p.join(scratchSpace.tempDir.path, '.dart_tool', 'package_config.json'),
3434
);
3535
if (!packageConfigFile.existsSync()) {
36-
final originalConfigFile = File.fromUri((await Isolate.packageConfig)!);
36+
final originalConfigFile = await _findPackageConfig();
3737
final packageConfigContents = _scratchSpacePackageConfig(
3838
originalConfigFile.readAsStringSync(),
3939
originalConfigFile.absolute.uri,
@@ -134,3 +134,26 @@ String _scratchSpacePackageConfig(String rootConfig, Uri packageConfigUri) {
134134
}
135135

136136
final Uri _currentDirUri = Directory.current.uri;
137+
138+
/// Returns [Isolate.packageConfig], or finds the file if it's `null`.
139+
///
140+
/// The `null` case is hit when the builder is AOT compiled. The build runs
141+
/// within the package being built, so search upwards for the package config.
142+
Future<File> _findPackageConfig() async {
143+
final result = await Isolate.packageConfig;
144+
if (result != null) return File(result.toFilePath());
145+
var directory = Directory.current;
146+
while (true) {
147+
final packageConfigFile = File(
148+
p.join(directory.path, '.dart_tool', 'package_config.json'),
149+
);
150+
if (packageConfigFile.existsSync()) {
151+
return packageConfigFile;
152+
}
153+
final parent = directory.parent;
154+
if (parent.path == directory.path) {
155+
throw StateError('Failed to find package_config.json.');
156+
}
157+
directory = parent;
158+
}
159+
}

build_modules/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build_modules
2-
version: 5.1.1
2+
version: 5.1.2
33
description: >-
44
Builders to analyze and split Dart code into individually compilable modules
55
based on imports.

build_runner/test/integration_tests/web_compilers_test.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:test/test.dart';
1010

1111
import '../common/common.dart';
1212

13-
const defaultTimeout = Timeout(Duration(seconds: 90));
13+
const defaultTimeout = Timeout(Duration(minutes: 3));
1414

1515
void main() async {
1616
test('web compilers', () async {
@@ -55,6 +55,12 @@ void main() {
5555
},
5656
);
5757

58+
// Initial build AOT.
59+
await tester.run(
60+
'root_pkg',
61+
'dart run build_runner build --output web:build --force-aot',
62+
);
63+
5864
// Initial build.
5965
await tester.run(
6066
'root_pkg',

0 commit comments

Comments
 (0)