22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5+ import 'dart:async' ;
56import 'dart:io' ;
67
78import 'package:built_collection/built_collection.dart' ;
89import 'package:io/io.dart' ;
910
1011import '../exceptions.dart' ;
1112import '../internal.dart' ;
13+ import 'aot_compiler.dart' ;
14+ import 'compiler.dart' ;
1215import 'depfile.dart' ;
1316import 'kernel_compiler.dart' ;
1417import 'processes.dart' ;
@@ -24,9 +27,14 @@ import 'processes.dart';
2427/// contents of all these files so they can be checked for freshness later.
2528///
2629/// The entrypoint script is launched using [ParentProcess.runAndSend]
27- /// which passes initial state to it and received updated state when it exits.
30+ /// or [ParentProcess.runAotSnapshotAndSend] which passes initial state to it
31+ /// and receives updated state when it exits.
2832class Bootstrapper {
29- final KernelCompiler _compiler = KernelCompiler ();
33+ final bool compileAot;
34+ final Compiler _compiler;
35+
36+ Bootstrapper ({required this .compileAot})
37+ : _compiler = compileAot ? AotCompiler () : KernelCompiler ();
3038
3139 /// Generates the entrypoint script, compiles it and runs it with [arguments] .
3240 ///
@@ -52,24 +60,46 @@ class Bootstrapper {
5260 if (! _compiler.checkFreshness (digestsAreFresh: false ).outputIsFresh) {
5361 final result = await _compiler.compile (experiments: experiments);
5462 if (! result.succeeded) {
55- if (result.messages != null ) {
63+ final bool failedDueToMirrors;
64+ if (result.messages == null ) {
65+ failedDueToMirrors = false ;
66+ } else {
5667 buildLog.error (result.messages! );
68+ failedDueToMirrors =
69+ compileAot && result.messages! .contains ('dart:mirrors' );
70+ }
71+ if (failedDueToMirrors) {
72+ // TODO(davidmorgan): when build_runner manages use of AOT compile
73+ // this will be an automatic fallback to JIT instead of a message.
74+ buildLog.error (
75+ 'Failed to compile build script. A configured builder '
76+ 'uses `dart:mirrors` and cannot be compiled AOT. Try again '
77+ 'without --force-aot to use a JIT compile.' ,
78+ );
79+ } else {
80+ buildLog.error (
81+ 'Failed to compile build script. '
82+ 'Check builder definitions and generated script '
83+ '$entrypointScriptPath .' ,
84+ );
5785 }
58- buildLog.error (
59- 'Failed to compile build script. '
60- 'Check builder definitions and generated script '
61- '$entrypointScriptPath .' ,
62- );
6386 throw const CannotBuildException ();
6487 }
6588 }
6689
67- final result = await ParentProcess .runAndSend (
68- script: entrypointDillPath,
69- arguments: arguments,
70- message: buildProcessState.serialize (),
71- jitVmArgs: jitVmArgs,
72- );
90+ final result =
91+ compileAot
92+ ? await ParentProcess .runAotSnapshotAndSend (
93+ aotSnapshot: entrypointAotPath,
94+ arguments: arguments,
95+ message: buildProcessState.serialize (),
96+ )
97+ : await ParentProcess .runAndSend (
98+ script: entrypointDillPath,
99+ arguments: arguments,
100+ message: buildProcessState.serialize (),
101+ jitVmArgs: jitVmArgs,
102+ );
73103 buildProcessState.deserializeAndSet (result.message);
74104 final exitCode = result.exitCode;
75105
@@ -94,11 +124,11 @@ class Bootstrapper {
94124 }
95125 }
96126
97- /// Checks freshness of the entrypoint script compiled to kernel .
127+ /// Checks freshness of the compiled entrypoint script .
98128 ///
99129 /// Set [digestsAreFresh] if digests were very recently updated. Then, they
100130 /// will be re-used from disk if possible instead of recomputed.
101- Future <FreshnessResult > checkKernelFreshness ({
131+ Future <FreshnessResult > checkCompileFreshness ({
102132 required bool digestsAreFresh,
103133 }) async {
104134 if (! ChildProcess .isRunning) {
@@ -116,9 +146,8 @@ class Bootstrapper {
116146 return _compiler.checkFreshness (digestsAreFresh: false );
117147 }
118148
119- /// Whether [path] is a dependency of the entrypoint script compiled to
120- /// kernel.
121- bool isKernelDependency (String path) {
149+ /// Whether [path] is a dependency of the compiled entrypoint script.
150+ bool isCompileDependency (String path) {
122151 if (! ChildProcess .isRunning) {
123152 // Any real use or realistic test has a child process; so this is only hit
124153 // in small tests. Return "not a dependency" so nothing related to
0 commit comments