33// found in the LICENSE file.
44
55import 'dart:async' ;
6- import 'dart:io' show Directory, Platform ;
6+ import 'dart:io' show Directory;
77
88import 'package:args/command_runner.dart' ;
99import 'package:path/path.dart' as path;
@@ -25,6 +25,12 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
2525 'build-canvaskit' ,
2626 help: 'Build CanvasKit locally instead of getting it from CIPD. Disabled '
2727 'by default.' ,
28+ defaultsTo: true
29+ );
30+ argParser.addFlag (
31+ 'host' ,
32+ help: 'Build the host build instead of the wasm build, which is currently'
33+ 'needed for `flutter run --local-engine` to work'
2834 );
2935 }
3036
@@ -38,19 +44,15 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
3844
3945 bool get buildCanvasKit => boolArg ('build-canvaskit' );
4046
47+ bool get host => boolArg ('host' );
48+
4149 @override
4250 FutureOr <bool > run () async {
4351 final FilePath libPath = FilePath .fromWebUi ('lib' );
4452 final List <PipelineStep > steps = < PipelineStep > [
45- GnPipelineStep (),
46- NinjaPipelineStep (target: environment.engineBuildDir ),
53+ GnPipelineStep (buildCanvasKit : buildCanvasKit, host : host ),
54+ NinjaPipelineStep (target: host ? environment.hostDebugUnoptDir : environment.wasmReleaseOutDir ),
4755 ];
48- if (buildCanvasKit) {
49- steps.addAll (< PipelineStep > [
50- GnPipelineStep (target: 'canvaskit' ),
51- NinjaPipelineStep (target: environment.wasmReleaseOutDir),
52- ]);
53- }
5456 final Pipeline buildPipeline = Pipeline (steps: steps);
5557 await buildPipeline.run ();
5658
@@ -73,42 +75,38 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
7375/// Not safe to interrupt as it may leave the `out/` directory in a corrupted
7476/// state. GN is pretty quick though, so it's OK to not support interruption.
7577class GnPipelineStep extends ProcessStep {
76- GnPipelineStep ({this .target = 'engine' })
77- : assert (target == 'engine' || target == 'canvaskit' );
78+ GnPipelineStep ({required this .buildCanvasKit, required this .host});
79+
80+ final bool buildCanvasKit;
81+ final bool host;
7882
7983 @override
8084 String get description => 'gn' ;
8185
8286 @override
8387 bool get isSafeToInterrupt => false ;
8488
85- /// The target to build with gn.
86- ///
87- /// Acceptable values: engine, canvaskit
88- final String target;
89-
90- @override
91- Future <ProcessManager > createProcess () {
92- print ('Running gn for $target ...' );
93- final List <String > gnArgs = < String > [];
94- if (target == 'engine' ) {
95- gnArgs.addAll (< String > [
96- '--unopt' ,
97- if (Platform .isMacOS) '--xcode-symlinks' ,
89+ List <String > get _gnArgs {
90+ if (host) {
91+ return < String > [
92+ '--unoptimized' ,
9893 '--full-dart-sdk' ,
99- if (environment.isMacosArm) '--mac-cpu=arm64' ,
100- ]);
101- } else if (target == 'canvaskit' ) {
102- gnArgs.addAll (< String > [
103- '--wasm' ,
104- '--runtime-mode=release' ,
105- ]);
94+ ];
10695 } else {
107- throw StateError ('Target was not engine or canvaskit: $target ' );
96+ return < String > [
97+ '--web' ,
98+ '--runtime-mode=release' ,
99+ if (buildCanvasKit) '--build-canvaskit' ,
100+ ];
108101 }
102+ }
103+
104+ @override
105+ Future <ProcessManager > createProcess () {
106+ print ('Running gn...' );
109107 return startProcess (
110108 path.join (environment.flutterDirectory.path, 'tools' , 'gn' ),
111- gnArgs ,
109+ _gnArgs ,
112110 );
113111 }
114112}
0 commit comments