@@ -6,56 +6,61 @@ import 'dart:io';
66
77import 'package:args/command_runner.dart' ;
88import 'package:devtools_tool/model.dart' ;
9+ import 'package:devtools_tool/utils.dart' ;
910import 'package:io/io.dart' ;
1011import 'package:path/path.dart' as path;
1112
12- import '../utils .dart' ;
13+ import 'shared .dart' ;
1314
14- const _useLocalFlutterFlag = 'use-local-flutter' ;
15- const _updatePerfettoFlag = 'update-perfetto' ;
1615const _buildAppFlag = 'build-app' ;
1716const _machineFlag = 'machine' ;
1817const _allowEmbeddingFlag = 'allow-embedding' ;
1918
2019/// This command builds DevTools in release mode by running the
21- /// `devtools_tool build-release ` command and then serves DevTools with a
22- /// locally running DevTools server.
20+ /// `devtools_tool build` command and then serves DevTools with a locally
21+ /// running DevTools server.
2322///
24- /// If the [_buildAppFlag] is negated (e.g. --no-build-app), then the DevTools
25- /// web app will not be rebuilt before serving.
23+ /// If the [_buildAppFlag] argument is negated (e.g. --no-build-app), then the
24+ /// DevTools web app will not be rebuilt before serving. The following arguments
25+ /// are ignored if '--no-build-app' is present in the list of arguments passed
26+ /// to this command. All of the following commands are passed along to the
27+ /// `devtools_tool build` command.
2628///
27- /// If [_useLocalFlutterFlag] is present, the Flutter SDK will not be updated to
28- /// the latest Flutter candidate. Use this flag to save the cost of updating the
29- /// Flutter SDK when you already have the proper SDK checked out.
29+ /// If the [BuildCommandArgs.useFlutterFromPath] argument is present, the
30+ /// Flutter SDK will not be updated to the latest Flutter candidate before
31+ /// building DevTools. Use this flag to save the cost of updating the Flutter
32+ /// SDK when you already have the proper SDK checked out. This is helpful when
33+ /// developing with the DevTools server.
3034///
31- /// If [_updatePerfettoFlag] is present, the precompiled bits for Perfetto will
32- /// be updated from the `devtools_tool update-perfetto` command as part of the
33- /// DevTools build process (e.g. running `devtools_tool build-release` ).
35+ /// If the [BuildCommandArgs.updatePerfetto] argument is present, the
36+ /// precompiled bits for Perfetto will be updated from the
37+ /// `devtools_tool update-perfetto` command as part of the DevTools build
38+ /// process.
39+ ///
40+ /// If [BuildCommandArgs.pubGet] argument is negated (e.g. --no-pub-get), then
41+ /// `devtools_tool pub-get --only-main` command will not be run before building
42+ /// the DevTools web app. Use this flag to save the cost of updating pub
43+ /// packages if your pub cahce does not need to be updated. This is helpful when
44+ /// developing with the DevTools server.
45+ ///
46+ /// The [BuildCommandArgs.buildMode] argument specifies the Flutter build mode
47+ /// that the DevTools web app will be built in ('release', 'profile', 'debug').
48+ /// This defaults to 'release' if unspecified.
3449class ServeCommand extends Command {
3550 ServeCommand () {
3651 argParser
37- ..addFlag (
38- _useLocalFlutterFlag,
39- negatable: false ,
40- defaultsTo: false ,
41- help:
42- 'Whether to use the Flutter SDK on PATH instead of the Flutter SDK '
43- 'contained in the "tool/flutter-sdk" directory.' ,
44- )
45- ..addFlag (
46- _updatePerfettoFlag,
47- negatable: false ,
48- defaultsTo: false ,
49- help: 'Whether to update the Perfetto assets before building DevTools.' ,
50- )
5152 ..addFlag (
5253 _buildAppFlag,
5354 negatable: true ,
5455 defaultsTo: true ,
5556 help:
56- 'Whether to build the DevTools app in release mode before starting '
57- 'the DevTools server.' ,
57+ 'Whether to build the DevTools web app before starting the DevTools '
58+ ' server.' ,
5859 )
60+ ..addUseFlutterFromPathFlag ()
61+ ..addUpdatePerfettoFlag ()
62+ ..addPubGetFlag ()
63+ ..addBulidModeOption ()
5964 // Flags defined in the server in DDS.
6065 ..addFlag (
6166 _machineFlag,
@@ -81,15 +86,25 @@ class ServeCommand extends Command {
8186 final repo = DevToolsRepo .getInstance ();
8287 final processManager = ProcessManager ();
8388
84- final useLocalFlutter = argResults! [_useLocalFlutterFlag];
85- final updatePerfetto = argResults! [_updatePerfettoFlag];
8689 final buildApp = argResults! [_buildAppFlag];
90+ final useFlutterFromPath =
91+ argResults! [BuildCommandArgs .useFlutterFromPath.flagName];
92+ final updatePerfetto =
93+ argResults! [BuildCommandArgs .updatePerfetto.flagName];
94+ final runPubGet = argResults! [BuildCommandArgs .pubGet.flagName];
95+ final devToolsAppBuildMode =
96+ argResults! [BuildCommandArgs .buildMode.flagName];
8797
8898 final remainingArguments = List .of (argResults! .arguments)
89- ..remove (_useLocalFlutterFlag)
90- ..remove (_updatePerfettoFlag)
91- ..remove (_buildAppFlag)
92- ..remove ('--no-$_buildAppFlag ' );
99+ ..remove (BuildCommandArgs .useFlutterFromPath.asArg ())
100+ ..remove (BuildCommandArgs .updatePerfetto.asArg ())
101+ ..remove (valueAsArg (_buildAppFlag))
102+ ..remove (valueAsArg (_buildAppFlag, negated: true ))
103+ ..remove (BuildCommandArgs .pubGet.asArg ())
104+ ..remove (BuildCommandArgs .pubGet.asArg (negated: true ))
105+ ..removeWhere (
106+ (element) => element.startsWith (BuildCommandArgs .buildMode.asArg ()),
107+ );
93108
94109 final localDartSdkLocation = Platform .environment['LOCAL_DART_SDK' ];
95110 if (localDartSdkLocation == null ) {
@@ -114,14 +129,16 @@ class ServeCommand extends Command {
114129 if (buildApp) {
115130 final process = await processManager.runProcess (
116131 CliCommand .tool (
117- 'build-release'
118- ' ${useLocalFlutter ? '--$_useLocalFlutterFlag ' : '' }'
119- ' ${updatePerfetto ? '--$_updatePerfettoFlag ' : '' }' ,
132+ 'build'
133+ '${useFlutterFromPath ? ' ${BuildCommandArgs .useFlutterFromPath .asArg ()}' : '' }'
134+ '${updatePerfetto ? ' ${BuildCommandArgs .updatePerfetto .asArg ()}' : '' }'
135+ ' ${BuildCommandArgs .buildMode .asArg ()}=$devToolsAppBuildMode '
136+ ' ${BuildCommandArgs .pubGet .asArg (negated : !runPubGet )}' ,
120137 ),
121138 );
122139 if (process.exitCode == 1 ) {
123140 throw Exception (
124- 'Something went wrong while running `devtools_tool build-release `' ,
141+ 'Something went wrong while running `devtools_tool build`' ,
125142 );
126143 }
127144 logStatus ('completed building DevTools: $devToolsBuildLocation ' );
0 commit comments