diff --git a/dwds/debug_extension_mv3/tool/build_extension.dart b/dwds/debug_extension_mv3/tool/build_extension.dart new file mode 100644 index 000000000..4ed884ed9 --- /dev/null +++ b/dwds/debug_extension_mv3/tool/build_extension.dart @@ -0,0 +1,91 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// INSTRUCTIONS: + +// Builds the unminifed dart2js extension (see DDC issue: +// see DDC issue: https://github.com/dart-lang/sdk/issues/49869). + +// Run from the extension root directory: +// - For dev: dart run tool/build_extension.dart +// - For prod: dart run tool/build_extension.dart prod + +import 'dart:async'; +import 'dart:convert'; +import 'dart:io'; + +import 'package:args/args.dart'; +import 'package:path/path.dart' as p; + +const _prodFlag = 'prod'; + +void main(List arguments) async { + final parser = ArgParser() + ..addFlag(_prodFlag, negatable: true, defaultsTo: false); + final argResults = parser.parse(arguments); + + exitCode = await run(isProd: argResults[_prodFlag] as bool); + if (exitCode != 0) { + _logWarning('Run terminated unexpectedly with exit code: $exitCode'); + } +} + +Future run({required bool isProd}) async { + _logInfo('Building extension for ${isProd ? 'prod' : 'dev'}'); + _logInfo('Compiling extension with dart2js to /compiled directory'); + final compileStep = await Process.start( + 'dart', + ['run', 'build_runner', 'build', 'web', '--output', 'build', '--release'], + ); + final compileExitCode = await _handleProcess(compileStep); + // Terminate early if compilation failed: + if (compileExitCode != 0) { + return compileExitCode; + } + _logInfo('Updating manifest.json in /compiled directory.'); + final updateStep = await Process.start( + 'dart', + [p.join('tool', 'update_dev_files.dart')], + ); + final updateExitCode = await _handleProcess(updateStep); + // Return exit code (0 indicates success): + return updateExitCode; +} + +Future _handleProcess(Process process) async { + _handleOutput(process.stdout, isStdout: true); + _handleOutput(process.stderr, isStdout: false); + return process.exitCode; +} + +void _handleOutput(Stream> output, {bool isStdout = true}) { + output + .transform(utf8.decoder) + .transform(const LineSplitter()) + .listen((line) => _handleOutputLine(line, isStdout: isStdout)); +} + +void _handleOutputLine(String line, {bool isStdout = true}) { + // Skip empty lines: + if (line.isEmpty) return; + // Log any unexpected errors and throw: + final outputName = isStdout ? 'stdout' : 'stderr'; + if (line.toUpperCase().contains('SEVERE') || + line.toUpperCase().contains('ERROR')) { + final error = 'Unexpected error in $outputName: $line'; + _logWarning(error); + throw Exception(error); + } + // Log message to the terminal: + final message = '$outputName: $line'; + isStdout ? _logInfo(message) : _logWarning(message); +} + +void _logInfo(String message) { + stdout.writeln(message); +} + +void _logWarning(String warning) { + stderr.writeln(warning); +} diff --git a/dwds/debug_extension_mv3/tool/build_extension.sh b/dwds/debug_extension_mv3/tool/build_extension.sh deleted file mode 100755 index 9df8f4fa9..000000000 --- a/dwds/debug_extension_mv3/tool/build_extension.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# 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. - -# INSTRUCTIONS: - -# Builds the unminifed dart2js app (see DDC issue: https://github.com/dart-lang/sdk/issues/49869): -# ./tool/build_extension.sh - - -prod="false" - -case "$1" in - prod) - prod="true" - shift;; -esac - -echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -echo "Building dart2js-compiled extension to /compiled directory." -echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -dart run build_runner build web --output build --release - -if [ $prod == true ]; then - exit 1 -fi - -echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -echo "Updating manifest.json in /compiled directory." -echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -dart tool/update_dev_files.dart diff --git a/dwds/test/puppeteer/test_utils.dart b/dwds/test/puppeteer/test_utils.dart index 5ef0719c9..0c8c93e98 100644 --- a/dwds/test/puppeteer/test_utils.dart +++ b/dwds/test/puppeteer/test_utils.dart @@ -13,10 +13,9 @@ import '../fixtures/utilities.dart'; Future buildDebugExtension() async { final extensionDir = absolutePath(pathFromDwds: 'debug_extension_mv3'); - // TODO(elliette): This doesn't work on Windows, see https://github.com/dart-lang/webdev/issues/1724. await Process.run( - p.join('tool', 'build_extension.sh'), - [], + 'dart', + [p.join('tool', 'build_extension.dart')], workingDirectory: extensionDir, ); return p.join(extensionDir, 'compiled');