33// found in the LICENSE file.
44
55import 'dart:async' ;
6- import 'dart:io' show Directory;
76
87import 'package:args/command_runner.dart' ;
98import 'package:path/path.dart' as path;
@@ -13,12 +12,18 @@ import 'environment.dart';
1312import 'pipeline.dart' ;
1413import 'utils.dart' ;
1514
15+ enum RuntimeMode {
16+ profile,
17+ release,
18+ }
19+
1620const Map <String , String > targetAliases = < String , String > {
1721 'sdk' : 'flutter/web_sdk' ,
1822 'web_sdk' : 'flutter/web_sdk' ,
1923 'canvaskit' : 'flutter/third_party/canvaskit:canvaskit_group' ,
2024 'canvaskit_chromium' : 'flutter/third_party/canvaskit:canvaskit_chromium_group' ,
2125 'skwasm' : 'flutter/lib/web_ui/skwasm' ,
26+ 'archive' : 'flutter/web_sdk:flutter_web_sdk_archive' ,
2227};
2328
2429class BuildCommand extends Command <bool > with ArgUtils <bool > {
@@ -34,6 +39,12 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
3439 help: 'Build the host build instead of the wasm build, which is '
3540 'currently needed for `flutter run --local-engine` to work.'
3641 );
42+ argParser.addFlag (
43+ 'profile' ,
44+ help: 'Build in profile mode instead of release mode. In this mode, the '
45+ 'output will be located at "out/wasm_profile".\n This only applies to '
46+ 'the wasm build. The host build is always built in release mode.' ,
47+ );
3748 }
3849
3950 @override
@@ -46,15 +57,22 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
4657
4758 bool get host => boolArg ('host' );
4859
60+ RuntimeMode get runtimeMode =>
61+ boolArg ('profile' ) ? RuntimeMode .profile : RuntimeMode .release;
62+
4963 List <String > get targets => argResults? .rest ?? < String > [];
5064
5165 @override
5266 FutureOr <bool > run () async {
5367 final FilePath libPath = FilePath .fromWebUi ('lib' );
5468 final List <PipelineStep > steps = < PipelineStep > [
55- GnPipelineStep (host: host),
69+ GnPipelineStep (
70+ host: host,
71+ runtimeMode: runtimeMode,
72+ ),
5673 NinjaPipelineStep (
57- buildDirectory: host ? environment.hostDebugUnoptDir : environment.wasmReleaseOutDir,
74+ host: host,
75+ runtimeMode: runtimeMode,
5876 targets: targets.map ((String target) => targetAliases[target] ?? target),
5977 ),
6078 ];
@@ -82,16 +100,27 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
82100class GnPipelineStep extends ProcessStep {
83101 GnPipelineStep ({
84102 required this .host,
103+ required this .runtimeMode,
85104 });
86105
87106 final bool host;
107+ final RuntimeMode runtimeMode;
88108
89109 @override
90110 String get description => 'gn' ;
91111
92112 @override
93113 bool get isSafeToInterrupt => false ;
94114
115+ String get runtimeModeFlag {
116+ switch (runtimeMode) {
117+ case RuntimeMode .profile:
118+ return 'profile' ;
119+ case RuntimeMode .release:
120+ return 'release' ;
121+ }
122+ }
123+
95124 List <String > get _gnArgs {
96125 if (host) {
97126 return < String > [
@@ -101,7 +130,7 @@ class GnPipelineStep extends ProcessStep {
101130 } else {
102131 return < String > [
103132 '--web' ,
104- '--runtime-mode=release ' ,
133+ '--runtime-mode=$ runtimeModeFlag ' ,
105134 ];
106135 }
107136 }
@@ -120,18 +149,33 @@ class GnPipelineStep extends ProcessStep {
120149///
121150/// Can be safely interrupted.
122151class NinjaPipelineStep extends ProcessStep {
123- NinjaPipelineStep ({required this .buildDirectory, required this .targets});
152+ NinjaPipelineStep ({
153+ required this .host,
154+ required this .runtimeMode,
155+ required this .targets,
156+ });
124157
125158 @override
126159 String get description => 'ninja' ;
127160
128161 @override
129162 bool get isSafeToInterrupt => true ;
130163
131- /// The directory to build.
132- final Directory buildDirectory;
133-
164+ final bool host;
134165 final Iterable <String > targets;
166+ final RuntimeMode runtimeMode;
167+
168+ String get buildDirectory {
169+ if (host) {
170+ return environment.hostDebugUnoptDir.path;
171+ }
172+ switch (runtimeMode) {
173+ case RuntimeMode .profile:
174+ return environment.wasmProfileOutDir.path;
175+ case RuntimeMode .release:
176+ return environment.wasmReleaseOutDir.path;
177+ }
178+ }
135179
136180 @override
137181 Future <ProcessManager > createProcess () {
@@ -140,7 +184,7 @@ class NinjaPipelineStep extends ProcessStep {
140184 'autoninja' ,
141185 < String > [
142186 '-C' ,
143- buildDirectory.path ,
187+ buildDirectory,
144188 ...targets,
145189 ],
146190 );
0 commit comments