diff --git a/packages/shorebird_cli/lib/src/executables/aot_tools.dart b/packages/shorebird_cli/lib/src/executables/aot_tools.dart index 8cf25a87c..fd2640b06 100644 --- a/packages/shorebird_cli/lib/src/executables/aot_tools.dart +++ b/packages/shorebird_cli/lib/src/executables/aot_tools.dart @@ -6,14 +6,17 @@ import 'package:shorebird_cli/src/process.dart'; class AotTools { static const executableName = 'aot-tools'; - Future _exec(List command) async { + Future _exec( + List 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. @@ -21,6 +24,7 @@ class AotTools { required String base, required String patch, required String analyzeSnapshot, + String? workingDirectory, }) async { final result = await _exec( [ @@ -29,7 +33,9 @@ class AotTools { '--patch=$patch', '--analyze-snapshot=$analyzeSnapshot', ], + workingDirectory: workingDirectory, ); + if (result.exitCode != 0) { throw Exception('Failed to link: ${result.stderr}'); } diff --git a/packages/shorebird_cli/test/src/executables/aot_tools_test.dart b/packages/shorebird_cli/test/src/executables/aot_tools_test.dart index 916dca5a6..54256410f 100644 --- a/packages/shorebird_cli/test/src/executables/aot_tools_test.dart +++ b/packages/shorebird_cli/test/src/executables/aot_tools_test.dart @@ -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, @@ -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, @@ -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); }); }); });