Skip to content

Commit

Permalink
feat(shorebird_cli): add workingDirectory to AotTools.link (#1510)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Nov 16, 2023
1 parent 73cf456 commit 4c9c1d7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/shorebird_cli/lib/src/executables/aot_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ import 'package:shorebird_cli/src/process.dart';
class AotTools {
static const executableName = 'aot-tools';

Future<ShorebirdProcessResult> _exec(List<String> command) async {
Future<ShorebirdProcessResult> _exec(
List<String> command, {
String? workingDirectory,
}) async {
await cache.updateAll();
final executable = p.join(
cache.getArtifactDirectory(executableName).path,
executableName,
);

return process.run(executable, command);
return process.run(executable, command, workingDirectory: workingDirectory);
}

/// Generate a link vmcode file from two AOT snapshots.
Future<void> link({
required String base,
required String patch,
required String analyzeSnapshot,
String? workingDirectory,
}) async {
final result = await _exec(
[
Expand All @@ -29,7 +33,9 @@ class AotTools {
'--patch=$patch',
'--analyze-snapshot=$analyzeSnapshot',
],
workingDirectory: workingDirectory,
);

if (result.exitCode != 0) {
throw Exception('Failed to link: ${result.stderr}');
}
Expand Down
25 changes: 23 additions & 2 deletions packages/shorebird_cli/test/src/executables/aot_tools_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ void main() {

test('throws Exception when process exits with non-zero code', () async {
when(
() => process.run(any(), any()),
() => process.run(
any(),
any(),
workingDirectory: any(named: 'workingDirectory'),
),
).thenAnswer(
(_) async => const ShorebirdProcessResult(
exitCode: 1,
Expand Down Expand Up @@ -73,7 +77,11 @@ void main() {

test('completes when linking exits with code: 0', () async {
when(
() => process.run(any(), any()),
() => process.run(
any(),
any(),
workingDirectory: any(named: 'workingDirectory'),
),
).thenAnswer(
(_) async => const ShorebirdProcessResult(
exitCode: 0,
Expand All @@ -87,10 +95,23 @@ void main() {
base: base,
patch: patch,
analyzeSnapshot: analyzeSnapshot,
workingDirectory: workingDirectory.path,
),
),
completes,
);
verify(
() => process.run(
any(that: endsWith(AotTools.executableName)),
[
'link',
'--base=$base',
'--patch=$patch',
'--analyze-snapshot=$analyzeSnapshot',
],
workingDirectory: any(named: 'workingDirectory'),
),
).called(1);
});
});
});
Expand Down

0 comments on commit 4c9c1d7

Please sign in to comment.