Skip to content

Commit

Permalink
Add build-mode and pub-get argument to the serve and build CL…
Browse files Browse the repository at this point in the history
…I tools (#6695)
  • Loading branch information
kenzieschmoll authored Nov 9, 2023
1 parent 3674ca5 commit d13316c
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 170 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ of launch configurations for running and debugging DevTools:

### Workflow for making changes

1. Change your local Flutter SDK to the latest flutter candidate branch: `devtools_tool update-flutter-sdk --local`
1. Change your local Flutter SDK to the latest flutter candidate branch: `devtools_tool update-flutter-sdk --from-path`
2. Create a branch from your cloned DevTools repo: `git checkout -b myBranch`
3. Ensure your branch, dependencies, and generated code are up-to-date: `devtools_tool sync`
4. Implement your changes, and commit to your branch: `git commit -m “description”`
Expand Down Expand Up @@ -173,7 +173,7 @@ command palette (`F1`)) and add the following to your settings:
"env": {
"LOCAL_DART_SDK": "/path/to/dart-sdk/sdk"
// Path to the version that Flutter DevTools is pinned to.
"FLUTTER_ROOT": "C:\\Dev\\Google\\devtools\\tool\\flutter-sdk"
"FLUTTER_ROOT": "/path/to/devtools/tool/flutter-sdk"
}
},
```
Expand Down
2 changes: 1 addition & 1 deletion tool/RELEASE_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Make sure:
c. The local checkout is at `main` branch: `git rebase-update`

2. Your Flutter version is equal to latest candidate release branch:
- Run `devtools_tool update-flutter-sdk --local`
- Run `devtools_tool update-flutter-sdk --from-path`
3. You have goma [configured](http://go/ma-mac-setup)

### Prepare the release
Expand Down
117 changes: 117 additions & 0 deletions tool/lib/commands/build.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright 2023 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';

import 'package:args/command_runner.dart';
import 'package:devtools_tool/commands/shared.dart';
import 'package:devtools_tool/model.dart';
import 'package:io/io.dart';
import 'package:path/path.dart' as path;

import '../utils.dart';

/// This command builds the DevTools Flutter web app.
///
/// By default, this command builds DevTools in release mode, but this can be
/// overridden by passing 'debug' or 'profile' as the
/// [BuildCommandArgs.buildMode] argument.
///
/// If the [BuildCommandArgs.useFlutterFromPath] argument is present, the
/// Flutter SDK will not be updated to the latest Flutter candidate before
/// building DevTools. Use this flag to save the cost of updating the Flutter
/// SDK when you already have the proper SDK checked out. This is helpful when
/// developing with the DevTools server.
///
/// If the [BuildCommandArgs.updatePerfetto] argument is present, the
/// precompiled bits for Perfetto will be updated from the
/// `devtools_tool update-perfetto` command as part of the DevTools build
/// process.
///
/// If [BuildCommandArgs.pubGet] argument is negated (e.g. --no-pub-get), then
/// `devtools_tool pub-get --only-main` command will not be run before building
/// the DevTools web app. Use this flag to save the cost of updating pub
/// packages if your pub cahce does not need to be updated. This is helpful when
/// developing with the DevTools server.
class BuildCommand extends Command {
BuildCommand() {
argParser
..addUseFlutterFromPathFlag()
..addUpdatePerfettoFlag()
..addPubGetFlag()
..addBulidModeOption();
}

@override
String get name => 'build';

@override
String get description => 'Prepares a release build of DevTools.';

@override
Future run() async {
final repo = DevToolsRepo.getInstance();
final processManager = ProcessManager();

final useLocalFlutter =
argResults![BuildCommandArgs.useFlutterFromPath.flagName];
final updatePerfetto =
argResults![BuildCommandArgs.updatePerfetto.flagName];
final runPubGet = argResults![BuildCommandArgs.pubGet.flagName];
final buildMode = argResults![BuildCommandArgs.buildMode.flagName];

final webBuildDir =
Directory(path.join(repo.devtoolsAppDirectoryPath, 'build', 'web'));

if (!useLocalFlutter) {
logStatus('updating tool/flutter-sdk to the latest flutter candidate');
await processManager.runProcess(CliCommand.tool('update-flutter-sdk'));
}

if (updatePerfetto) {
logStatus('updating the bundled Perfetto assets');
await processManager.runProcess(CliCommand.tool('update-perfetto'));
}

logStatus('cleaning project');
if (webBuildDir.existsSync()) {
webBuildDir.deleteSync(recursive: true);
}
await processManager.runProcess(
CliCommand.flutter('clean'),
workingDirectory: repo.devtoolsAppDirectoryPath,
);

logStatus('building DevTools in release mode');
await processManager.runAll(
commands: [
if (runPubGet) CliCommand.tool('pub-get --only-main'),
CliCommand.flutter(
[
'build',
'web',
'--web-renderer',
'canvaskit',
'--pwa-strategy=offline-first',
if (buildMode != 'debug') '--$buildMode',
'--no-tree-shake-icons',
].join(' '),
),
],
workingDirectory: repo.devtoolsAppDirectoryPath,
);

// TODO(kenz): investigate if we need to perform a windows equivalent of
// `chmod` or if we even need to perform `chmod` for linux / mac anymore.
if (!Platform.isWindows) {
final canvaskitDir = Directory(path.join(webBuildDir.path, 'canvaskit'));
for (final file in canvaskitDir.listSync()) {
if (RegExp(r'canvaskit\..*').hasMatch(file.path)) {
await processManager
.runProcess(CliCommand('chmod 0755 ${file.path}'));
}
}
}
}
}
96 changes: 0 additions & 96 deletions tool/lib/commands/build_release.dart

This file was deleted.

95 changes: 56 additions & 39 deletions tool/lib/commands/serve.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,61 @@ import 'dart:io';

import 'package:args/command_runner.dart';
import 'package:devtools_tool/model.dart';
import 'package:devtools_tool/utils.dart';
import 'package:io/io.dart';
import 'package:path/path.dart' as path;

import '../utils.dart';
import 'shared.dart';

const _useLocalFlutterFlag = 'use-local-flutter';
const _updatePerfettoFlag = 'update-perfetto';
const _buildAppFlag = 'build-app';
const _machineFlag = 'machine';
const _allowEmbeddingFlag = 'allow-embedding';

/// This command builds DevTools in release mode by running the
/// `devtools_tool build-release` command and then serves DevTools with a
/// locally running DevTools server.
/// `devtools_tool build` command and then serves DevTools with a locally
/// running DevTools server.
///
/// If the [_buildAppFlag] is negated (e.g. --no-build-app), then the DevTools
/// web app will not be rebuilt before serving.
/// If the [_buildAppFlag] argument is negated (e.g. --no-build-app), then the
/// DevTools web app will not be rebuilt before serving. The following arguments
/// are ignored if '--no-build-app' is present in the list of arguments passed
/// to this command. All of the following commands are passed along to the
/// `devtools_tool build` command.
///
/// If [_useLocalFlutterFlag] is present, the Flutter SDK will not be updated to
/// the latest Flutter candidate. Use this flag to save the cost of updating the
/// Flutter SDK when you already have the proper SDK checked out.
/// If the [BuildCommandArgs.useFlutterFromPath] argument is present, the
/// Flutter SDK will not be updated to the latest Flutter candidate before
/// building DevTools. Use this flag to save the cost of updating the Flutter
/// SDK when you already have the proper SDK checked out. This is helpful when
/// developing with the DevTools server.
///
/// If [_updatePerfettoFlag] is present, the precompiled bits for Perfetto will
/// be updated from the `devtools_tool update-perfetto` command as part of the
/// DevTools build process (e.g. running `devtools_tool build-release`).
/// If the [BuildCommandArgs.updatePerfetto] argument is present, the
/// precompiled bits for Perfetto will be updated from the
/// `devtools_tool update-perfetto` command as part of the DevTools build
/// process.
///
/// If [BuildCommandArgs.pubGet] argument is negated (e.g. --no-pub-get), then
/// `devtools_tool pub-get --only-main` command will not be run before building
/// the DevTools web app. Use this flag to save the cost of updating pub
/// packages if your pub cahce does not need to be updated. This is helpful when
/// developing with the DevTools server.
///
/// The [BuildCommandArgs.buildMode] argument specifies the Flutter build mode
/// that the DevTools web app will be built in ('release', 'profile', 'debug').
/// This defaults to 'release' if unspecified.
class ServeCommand extends Command {
ServeCommand() {
argParser
..addFlag(
_useLocalFlutterFlag,
negatable: false,
defaultsTo: false,
help:
'Whether to use the Flutter SDK on PATH instead of the Flutter SDK '
'contained in the "tool/flutter-sdk" directory.',
)
..addFlag(
_updatePerfettoFlag,
negatable: false,
defaultsTo: false,
help: 'Whether to update the Perfetto assets before building DevTools.',
)
..addFlag(
_buildAppFlag,
negatable: true,
defaultsTo: true,
help:
'Whether to build the DevTools app in release mode before starting '
'the DevTools server.',
'Whether to build the DevTools web app before starting the DevTools'
' server.',
)
..addUseFlutterFromPathFlag()
..addUpdatePerfettoFlag()
..addPubGetFlag()
..addBulidModeOption()
// Flags defined in the server in DDS.
..addFlag(
_machineFlag,
Expand All @@ -81,15 +86,25 @@ class ServeCommand extends Command {
final repo = DevToolsRepo.getInstance();
final processManager = ProcessManager();

final useLocalFlutter = argResults![_useLocalFlutterFlag];
final updatePerfetto = argResults![_updatePerfettoFlag];
final buildApp = argResults![_buildAppFlag];
final useFlutterFromPath =
argResults![BuildCommandArgs.useFlutterFromPath.flagName];
final updatePerfetto =
argResults![BuildCommandArgs.updatePerfetto.flagName];
final runPubGet = argResults![BuildCommandArgs.pubGet.flagName];
final devToolsAppBuildMode =
argResults![BuildCommandArgs.buildMode.flagName];

final remainingArguments = List.of(argResults!.arguments)
..remove(_useLocalFlutterFlag)
..remove(_updatePerfettoFlag)
..remove(_buildAppFlag)
..remove('--no-$_buildAppFlag');
..remove(BuildCommandArgs.useFlutterFromPath.asArg())
..remove(BuildCommandArgs.updatePerfetto.asArg())
..remove(valueAsArg(_buildAppFlag))
..remove(valueAsArg(_buildAppFlag, negated: true))
..remove(BuildCommandArgs.pubGet.asArg())
..remove(BuildCommandArgs.pubGet.asArg(negated: true))
..removeWhere(
(element) => element.startsWith(BuildCommandArgs.buildMode.asArg()),
);

final localDartSdkLocation = Platform.environment['LOCAL_DART_SDK'];
if (localDartSdkLocation == null) {
Expand All @@ -114,14 +129,16 @@ class ServeCommand extends Command {
if (buildApp) {
final process = await processManager.runProcess(
CliCommand.tool(
'build-release'
' ${useLocalFlutter ? '--$_useLocalFlutterFlag' : ''}'
' ${updatePerfetto ? '--$_updatePerfettoFlag' : ''}',
'build'
'${useFlutterFromPath ? ' ${BuildCommandArgs.useFlutterFromPath.asArg()}' : ''}'
'${updatePerfetto ? ' ${BuildCommandArgs.updatePerfetto.asArg()}' : ''}'
' ${BuildCommandArgs.buildMode.asArg()}=$devToolsAppBuildMode'
' ${BuildCommandArgs.pubGet.asArg(negated: !runPubGet)}',
),
);
if (process.exitCode == 1) {
throw Exception(
'Something went wrong while running `devtools_tool build-release`',
'Something went wrong while running `devtools_tool build`',
);
}
logStatus('completed building DevTools: $devToolsBuildLocation');
Expand Down
Loading

0 comments on commit d13316c

Please sign in to comment.