-
Notifications
You must be signed in to change notification settings - Fork 83
[MV3 Debug Extension] Compile extension with Dart instead of shell script #1954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
00580bb
Compile extension with Dart instead of shell script
elliette 8de9846
Update year
elliette 2ca0da4
Respond to PR comments
elliette ff15136
Log failure
elliette dfa1c5f
Format
elliette 5c24de5
Using Process.start instead of Process.run
elliette 4e7d541
small tweaks
elliette 30d5aba
Use outputName
elliette 304ebc1
Remove logOutput
elliette 86c5602
Respond to PR comments
elliette File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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<int> 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<int> _handleProcess(Process process) async { | ||
_handleOutput(process.stdout, isStdout: true); | ||
_handleOutput(process.stderr, isStdout: false); | ||
return process.exitCode; | ||
} | ||
|
||
void _handleOutput(Stream<List<int>> output, {bool isStdout = true}) { | ||
output | ||
.transform(utf8.decoder) | ||
.transform(const LineSplitter()) | ||
.listen((line) => _handleOutputLine(line, isStdout: isStdout)); | ||
} | ||
|
||
void _handleOutputLine(String line, {bool isStdout = true}) { | ||
annagrin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.