Skip to content

Commit

Permalink
Add exception handling to build_and_copy command (#6298)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll authored Aug 31, 2023
1 parent 028ac58 commit fb28ec1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/devtools_extensions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.0.3-wip
* Add `showNotification` and `showBannerMessage` endpoints to the extensions API.
* Add hot reload and hot restart actions to the simulated DevTools environment.
* Add exception handling to `devtools_extensions build_and_copy` command.

## 0.0.2
* Add a simulated DevTools environment that for easier development.
Expand Down
36 changes: 29 additions & 7 deletions packages/devtools_extensions/bin/_build_and_copy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ class BuildExtensionCommand extends Command {

@override
Future<void> run() async {
final source = argResults?[_sourceKey]!;
final destination = argResults?[_destinationKey]!;
final source = argResults?[_sourceKey]! as String;
final destination = argResults?[_destinationKey]! as String;

final processManager = ProcessManager();

_log('Building the extension Flutter web app...');
final buildProcess = await processManager.spawn(
await _runProcess(
processManager,
'flutter',
[
'build',
Expand All @@ -68,15 +69,19 @@ class BuildExtensionCommand extends Command {
],
workingDirectory: source,
);
await buildProcess.exitCode;

_log('Setting canvaskit permissions...');
final chmodProcess = await processManager.spawn(
await _runProcess(
processManager,
'chmod',
['0755', 'build/web/canvaskit/canvaskit.*'],
[
'0755',
// Note: using a wildcard `canvaskit.*` throws.
'build/web/canvaskit/canvaskit.js',
'build/web/canvaskit/canvaskit.wasm',
],
workingDirectory: source,
);
await chmodProcess.exitCode;

_log('Copying built output to the extension destination...');
await _copyBuildToDestination(source: source, dest: destination);
Expand Down Expand Up @@ -120,4 +125,21 @@ class BuildExtensionCommand extends Command {
}

void _log(String message) => print('[$name] $message');

Future<void> _runProcess(
ProcessManager processManager,
String exe,
List<String> args, {
String? workingDirectory,
}) async {
final buildProcess = await processManager.spawn(
exe,
args,
workingDirectory: workingDirectory,
);
final code = await buildProcess.exitCode;
if (code != 0) {
throw ProcessException(exe, args, 'Failed with exit code: $code', code);
}
}
}

0 comments on commit fb28ec1

Please sign in to comment.