blob: 21530bd43e647839c23f9fcdc82f5ca58aeff392 [file] [log] [blame]
// Copyright 2022 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';
const argNoBuildApp = '--no-build-app';
const argNoUpdateFlutter = '--no-update-flutter';
const argUpdatePerfetto = '--update-perfetto';
/// This script builds DevTools in release mode by running the
/// `./tool/` script and then serves DevTools with a locally
/// running DevTools server.
/// If [argNoBuildApp] is present, the DevTools web app will not be rebuilt.
/// If [argNoUpdateFlutter] 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 [argUpdatePerfetto] is present, the precompiled bits for Perfetto will
/// be updated from the [] script as part of the DevTools
/// build process (e.g. []).
void main(List<String> args) async {
final shouldUpdatePerfetto = args.contains(argUpdatePerfetto);
final noUpdateFlutter = args.contains(argNoUpdateFlutter);
final noBuildApp = args.contains(argNoBuildApp);
final argsCopy = List.of(args)
final mainDevToolsDirectory = Directory.current;
if (!mainDevToolsDirectory.path.endsWith('/devtools')) {
throw Exception('Please execute this script from your top level '
'\'devtools/\' directory.');
final localDartSdkLocation = Platform.environment['LOCAL_DART_SDK'];
if (localDartSdkLocation == null) {
throw Exception('LOCAL_DART_SDK environment variable not set. Please add '
'the following to your \'.bash_profile\' or \'.bash_rc\' file:\n'
'export LOCAL_DART_SDK=<absolute/path/to/my/dart/sdk>');
final devToolsBuildLocation =
if (!noBuildApp) {
print('Running the script...');
final buildProcess = await Process.start(
if (shouldUpdatePerfetto) argUpdatePerfetto,
if (noUpdateFlutter) argNoUpdateFlutter,
workingDirectory: mainDevToolsDirectory.path,
final buildProcessExitCode = await buildProcess.exitCode;
if (buildProcessExitCode == 1) {
throw Exception(
'Something went wrong while running `tool/',
print('Completed building DevTools: $devToolsBuildLocation');
print('Run pub get for DDS in local dart sdk');
await Process.start(
['pub', 'get'],
workingDirectory: '$localDartSdkLocation/pkg/dds',
print('Serving DevTools with a local devtools server...');
final serveProcess = await Process.start(
// Pass any args that were provided to our script along. This allows IDEs
// to pass `--machine` (etc.) so that this script can behave the same as
// the "dart devtools" command for testing local DevTools/server changes.
workingDirectory: localDartSdkLocation,
await serveProcess.exitCode;
void _forwardOutputStreams(Process process) {
void _forwardInputStream(Process process) {