From 5c04a68df1a12bf5b37d68847d47aabf5bf845e9 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Thu, 3 Aug 2023 11:08:59 -0500 Subject: [PATCH] feat(shorebird_cli): scope Flutter installations by revision (#1007) --- bin/shorebird.ps1 | 5 +- packages/shorebird_cli/lib/src/cache.dart | 2 +- .../shorebird_cli/lib/src/command_runner.dart | 2 +- .../lib/src/commands/doctor_command.dart | 2 +- .../src/commands/patch/patch_aar_command.dart | 2 +- .../commands/patch/patch_android_command.dart | 2 +- .../src/commands/patch/patch_ios_command.dart | 2 +- .../patch/patch_ios_framework_command.dart | 2 +- .../lib/src/commands/upgrade_command.dart | 2 +- .../shorebird_cli/lib/src/ios_deploy.dart | 2 +- packages/shorebird_cli/lib/src/process.dart | 2 +- .../lib/src/shorebird_build_mixin.dart | 2 +- .../shorebird_cli/lib/src/shorebird_env.dart | 20 ++-- .../shorebird_flutter_validator.dart | 4 +- .../shorebird_cli/test/src/cache_test.dart | 4 +- .../test/src/command_runner_test.dart | 4 +- .../src/commands/doctor_command_test.dart | 4 +- .../patch/patch_aar_command_test.dart | 6 +- .../patch/patch_android_command_test.dart | 6 +- .../patch/patch_ios_command_test.dart | 10 +- .../patch_ios_framework_command_test.dart | 10 +- .../src/commands/upgrade_command_test.dart | 2 +- .../test/src/ios_deploy_test.dart | 6 +- .../test/src/shorebird_env_test.dart | 102 ++++++++++++++++-- .../test/src/shorebird_process_test.dart | 8 +- .../shorebird_flutter_validator_test.dart | 2 +- third_party/flutter/bin/internal/shared.sh | 2 +- 27 files changed, 161 insertions(+), 56 deletions(-) diff --git a/bin/shorebird.ps1 b/bin/shorebird.ps1 index 7b72a252..a51b3ff8 100644 --- a/bin/shorebird.ps1 +++ b/bin/shorebird.ps1 @@ -4,11 +4,12 @@ # We are running from $shorebirdRootDir\bin $shorebirdBinDir = (Get-Item $PSScriptRoot).FullName $shorebirdRootDir = (Get-Item $shorebirdBinDir\..\).FullName +$flutterVersion = Get-Content "$shorebirdBinDir\internal\flutter.version" $shorebirdCacheDir = [IO.Path]::Combine($shorebirdRootDir, "bin", "cache") $shorebirdCliDir = [IO.Path]::Combine($shorebirdRootDir, "packages", "shorebird_cli") $snapshotPath = [IO.Path]::Combine($shorebirdCacheDir, "shorebird.snapshot") $stampPath = [IO.Path]::Combine($shorebirdCacheDir, "shorebird.stamp") -$flutterPath = [IO.Path]::Combine($shorebirdCacheDir, "flutter") +$flutterPath = [IO.Path]::Combine($shorebirdCacheDir, "flutter", $flutterVersion) $flutter = [IO.Path]::Combine($shorebirdCacheDir, "flutter", "bin", "flutter.bat") $shorebirdScript = [IO.Path]::Combine($shorebirdCliDir, "bin", "shorebird.dart") $dart = [IO.Path]::Combine($flutterPath, "bin", "cache", "dart-sdk", "bin", "dart.exe") @@ -82,8 +83,6 @@ function Update-Flutter { git -C "$flutterPath" fetch *> $null } - $flutterVersion = Get-Content "$shorebirdBinDir\internal\flutter.version" - # -c to avoid printing a warning about being in a detached head state. git -C "$flutterPath" -c advice.detachedHead=false checkout "$flutterVersion" *> $null diff --git a/packages/shorebird_cli/lib/src/cache.dart b/packages/shorebird_cli/lib/src/cache.dart index 223ce60f..82b1c720 100644 --- a/packages/shorebird_cli/lib/src/cache.dart +++ b/packages/shorebird_cli/lib/src/cache.dart @@ -174,7 +174,7 @@ class PatchArtifact extends CachedArtifact { artifactName += 'windows-x64.zip'; } - return '${cache.storageBaseUrl}/${cache.storageBucket}/shorebird/${shorebirdEnv.shorebirdEngineRevision}/$artifactName'; + return '${cache.storageBaseUrl}/${cache.storageBucket}/shorebird/${shorebirdEnv.shorebirdEngineRevision()}/$artifactName'; } } diff --git a/packages/shorebird_cli/lib/src/command_runner.dart b/packages/shorebird_cli/lib/src/command_runner.dart index 6a6f3568..9a8545c8 100644 --- a/packages/shorebird_cli/lib/src/command_runner.dart +++ b/packages/shorebird_cli/lib/src/command_runner.dart @@ -144,7 +144,7 @@ ${lightCyan.wrap('shorebird release android -- --no-pub lib/main.dart')}''', logger.info( ''' Shorebird $packageVersion -Shorebird Engine • revision ${shorebirdEnv.shorebirdEngineRevision}''', +Shorebird Engine • revision ${shorebirdEnv.shorebirdEngineRevision()}''', ); exitCode = ExitCode.success.code; } else { diff --git a/packages/shorebird_cli/lib/src/commands/doctor_command.dart b/packages/shorebird_cli/lib/src/commands/doctor_command.dart index 432b371e..75b04c19 100644 --- a/packages/shorebird_cli/lib/src/commands/doctor_command.dart +++ b/packages/shorebird_cli/lib/src/commands/doctor_command.dart @@ -34,7 +34,7 @@ class DoctorCommand extends ShorebirdCommand { logger.info(''' Shorebird v$packageVersion -Shorebird Engine • revision ${shorebirdEnv.shorebirdEngineRevision} +Shorebird Engine • revision ${shorebirdEnv.shorebirdEngineRevision()} '''); await doctor.runValidators(doctor.allValidators, applyFixes: shouldFix); diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart index caed2082..9bc7b6a0 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart @@ -172,7 +172,7 @@ Either create a new release using: ${lightCyan.wrap('shorebird release aar')} Or downgrade your Flutter version and try again using: - ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory.path}')} + ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory().path}')} ${lightCyan.wrap('git checkout ${release.flutterRevision}')} Shorebird plans to support this automatically, let us know if it's important to you: diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart index 49a9fd79..b4039c82 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart @@ -177,7 +177,7 @@ Either create a new release using: ${lightCyan.wrap('shorebird release')} Or downgrade your Flutter version and try again using: - ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory.path}')} + ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory().path}')} ${lightCyan.wrap('git checkout ${release.flutterRevision}')} Shorebird plans to support this automatically, let us know if it's important to you: diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart index 80639029..ecfe0230 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart @@ -182,7 +182,7 @@ Either create a new release using: ${lightCyan.wrap('shorebird release')} Or downgrade your Flutter version and try again using: - ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory.path}')} + ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory().path}')} ${lightCyan.wrap('git checkout ${release.flutterRevision}')} Shorebird plans to support this automatically, let us know if it's important to you: diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart index 94a8d84b..9730d728 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart @@ -139,7 +139,7 @@ Either create a new release using: ${lightCyan.wrap('shorebird release')} Or downgrade your Flutter version and try again using: - ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory.path}')} + ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory().path}')} ${lightCyan.wrap('git checkout ${release.flutterRevision}')} Shorebird plans to support this automatically, let us know if it's important to you: diff --git a/packages/shorebird_cli/lib/src/commands/upgrade_command.dart b/packages/shorebird_cli/lib/src/commands/upgrade_command.dart index f9ce125a..4b89a251 100644 --- a/packages/shorebird_cli/lib/src/commands/upgrade_command.dart +++ b/packages/shorebird_cli/lib/src/commands/upgrade_command.dart @@ -91,7 +91,7 @@ class UpgradeCommand extends ShorebirdCommand { final result = await process.run( executable, args, - workingDirectory: shorebirdEnv.flutterDirectory.path, + workingDirectory: shorebirdEnv.flutterDirectory().path, ); if (result.exitCode != 0) { diff --git a/packages/shorebird_cli/lib/src/ios_deploy.dart b/packages/shorebird_cli/lib/src/ios_deploy.dart index f071beab..9190dda2 100644 --- a/packages/shorebird_cli/lib/src/ios_deploy.dart +++ b/packages/shorebird_cli/lib/src/ios_deploy.dart @@ -33,7 +33,7 @@ class IOSDeploy { @visibleForTesting static File get iosDeployExecutable => File( p.join( - shorebirdEnv.flutterDirectory.path, + shorebirdEnv.flutterDirectory().path, 'bin', 'cache', 'artifacts', diff --git a/packages/shorebird_cli/lib/src/process.dart b/packages/shorebird_cli/lib/src/process.dart index c896bd76..adccc89d 100644 --- a/packages/shorebird_cli/lib/src/process.dart +++ b/packages/shorebird_cli/lib/src/process.dart @@ -111,7 +111,7 @@ class ShorebirdProcess { } String _resolveExecutable(String executable) { - if (executable == 'flutter') return shorebirdEnv.flutterBinaryFile.path; + if (executable == 'flutter') return shorebirdEnv.flutterBinaryFile().path; return executable; } diff --git a/packages/shorebird_cli/lib/src/shorebird_build_mixin.dart b/packages/shorebird_cli/lib/src/shorebird_build_mixin.dart index c250154f..5066d4eb 100644 --- a/packages/shorebird_cli/lib/src/shorebird_build_mixin.dart +++ b/packages/shorebird_cli/lib/src/shorebird_build_mixin.dart @@ -328,7 +328,7 @@ mixin ShorebirdBuildMixin on ShorebirdCommand { ]; final result = await process.run( - shorebirdEnv.genSnapshotFile.path, + shorebirdEnv.genSnapshotFile().path, arguments, ); diff --git a/packages/shorebird_cli/lib/src/shorebird_env.dart b/packages/shorebird_cli/lib/src/shorebird_env.dart index 95511907..a2c56437 100644 --- a/packages/shorebird_cli/lib/src/shorebird_env.dart +++ b/packages/shorebird_cli/lib/src/shorebird_env.dart @@ -29,9 +29,14 @@ class ShorebirdEnv { return File(platform.script.toFilePath()).parent.parent.parent; } - String get shorebirdEngineRevision { + String shorebirdEngineRevision({String? flutterRevision}) { return File( - p.join(flutterDirectory.path, 'bin', 'internal', 'engine.version'), + p.join( + flutterDirectory(revision: flutterRevision).path, + 'bin', + 'internal', + 'engine.version', + ), ).readAsStringSync().trim(); } @@ -42,32 +47,33 @@ class ShorebirdEnv { } /// The root of the Shorebird-vended Flutter git checkout. - Directory get flutterDirectory { + Directory flutterDirectory({String? revision}) { return Directory( p.join( shorebirdRoot.path, 'bin', 'cache', 'flutter', + revision ?? flutterRevision, ), ); } /// The Shorebird-vended Flutter binary. - File get flutterBinaryFile { + File flutterBinaryFile({String? revision}) { return File( p.join( - flutterDirectory.path, + flutterDirectory(revision: revision).path, 'bin', 'flutter', ), ); } - File get genSnapshotFile { + File genSnapshotFile({String? revision}) { return File( p.join( - flutterDirectory.path, + flutterDirectory(revision: revision).path, 'bin', 'cache', 'artifacts', diff --git a/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart b/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart index f8a410cb..3871aa25 100644 --- a/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart +++ b/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart @@ -29,7 +29,7 @@ class ShorebirdFlutterValidator extends Validator { Future> validate() async { final issues = []; - if (!shorebirdEnv.flutterDirectory.existsSync()) { + if (!shorebirdEnv.flutterDirectory().existsSync()) { final message = 'No Flutter directory found at ' '${shorebirdEnv.flutterDirectory}'; issues.add( @@ -116,7 +116,7 @@ This can cause unexpected behavior if you are switching between the tools and th final result = await process.run( 'git', ['status', '--untracked-files=no', '--porcelain'], - workingDirectory: shorebirdEnv.flutterDirectory.path, + workingDirectory: shorebirdEnv.flutterDirectory().path, ); return result.stdout.toString().trim().isEmpty; } diff --git a/packages/shorebird_cli/test/src/cache_test.dart b/packages/shorebird_cli/test/src/cache_test.dart index 90bb6159..7f7eb7ec 100644 --- a/packages/shorebird_cli/test/src/cache_test.dart +++ b/packages/shorebird_cli/test/src/cache_test.dart @@ -61,7 +61,9 @@ void main() { shorebirdRoot = Directory.systemTemp.createTempSync(); when( - () => shorebirdEnv.shorebirdEngineRevision, + () => shorebirdEnv.shorebirdEngineRevision( + flutterRevision: any(named: 'flutterRevision'), + ), ).thenReturn(shorebirdEngineRevision); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); diff --git a/packages/shorebird_cli/test/src/command_runner_test.dart b/packages/shorebird_cli/test/src/command_runner_test.dart index eb7029cb..cb5f2a37 100644 --- a/packages/shorebird_cli/test/src/command_runner_test.dart +++ b/packages/shorebird_cli/test/src/command_runner_test.dart @@ -40,7 +40,9 @@ void main() { processResult = _MockProcessResult(); when(() => processResult.exitCode).thenReturn(ExitCode.success.code); when( - () => shorebirdEnv.shorebirdEngineRevision, + () => shorebirdEnv.shorebirdEngineRevision( + flutterRevision: any(named: 'flutterRevision'), + ), ).thenReturn(shorebirdEngineRevision); commandRunner = runWithOverrides(ShorebirdCliCommandRunner.new); }); diff --git a/packages/shorebird_cli/test/src/commands/doctor_command_test.dart b/packages/shorebird_cli/test/src/commands/doctor_command_test.dart index ced74fa9..382ea5eb 100644 --- a/packages/shorebird_cli/test/src/commands/doctor_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/doctor_command_test.dart @@ -50,7 +50,9 @@ void main() { validator = _MockValidator(); when( - () => shorebirdEnv.shorebirdEngineRevision, + () => shorebirdEnv.shorebirdEngineRevision( + flutterRevision: any(named: 'flutterRevision'), + ), ).thenReturn(shorebirdEngineRevision); when(() => doctor.allValidators).thenReturn([validator]); when( diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart index 217ab4a2..049d0728 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart @@ -199,7 +199,9 @@ void main() { when(() => platform.environment).thenReturn({}); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); - when(() => shorebirdEnv.flutterDirectory).thenReturn(flutterDirectory); + when( + () => shorebirdEnv.flutterDirectory(revision: any(named: 'revision')), + ).thenReturn(flutterDirectory); when( () => shorebirdEnv.androidPackageName, ).thenReturn(androidPackageName); @@ -460,7 +462,7 @@ Either create a new release using: ${lightCyan.wrap('shorebird release aar')} Or downgrade your Flutter version and try again using: - ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory.path}')} + ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory().path}')} ${lightCyan.wrap('git checkout ${release.flutterRevision}')} Shorebird plans to support this automatically, let us know if it's important to you: diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart index b3c800a9..73482b54 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart @@ -236,7 +236,9 @@ flutter: when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); - when(() => shorebirdEnv.flutterDirectory).thenReturn(flutterDirectory); + when( + () => shorebirdEnv.flutterDirectory(revision: any(named: 'revision')), + ).thenReturn(flutterDirectory); when( () => shorebirdProcess.run( 'flutter', @@ -524,7 +526,7 @@ Either create a new release using: ${lightCyan.wrap('shorebird release aar')} Or downgrade your Flutter version and try again using: - ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory.path}')} + ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory().path}')} ${lightCyan.wrap('git checkout ${release.flutterRevision}')} Shorebird plans to support this automatically, let us know if it's important to you: diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart index cb5b7083..0dd1e303 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart @@ -257,8 +257,12 @@ flutter: when(() => platform.environment).thenReturn({}); when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); - when(() => shorebirdEnv.flutterDirectory).thenReturn(flutterDirectory); - when(() => shorebirdEnv.genSnapshotFile).thenReturn(genSnapshotFile); + when( + () => shorebirdEnv.flutterDirectory(revision: any(named: 'revision')), + ).thenReturn(flutterDirectory); + when( + () => shorebirdEnv.genSnapshotFile(revision: any(named: 'revision')), + ).thenReturn(genSnapshotFile); when( () => aotBuildProcessResult.exitCode, ).thenReturn(ExitCode.success.code); @@ -532,7 +536,7 @@ Either create a new release using: ${lightCyan.wrap('shorebird release aar')} Or downgrade your Flutter version and try again using: - ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory.path}')} + ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory().path}')} ${lightCyan.wrap('git checkout ${release.flutterRevision}')} Shorebird plans to support this automatically, let us know if it's important to you: diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart index 8f24088c..3611f1fd 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart @@ -207,8 +207,12 @@ flutter: when(() => platform.operatingSystem).thenReturn(Platform.macOS); when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); - when(() => shorebirdEnv.flutterDirectory).thenReturn(flutterDirectory); - when(() => shorebirdEnv.genSnapshotFile).thenReturn(genSnapshotFile); + when( + () => shorebirdEnv.flutterDirectory(revision: any(named: 'revision')), + ).thenReturn(flutterDirectory); + when( + () => shorebirdEnv.genSnapshotFile(revision: any(named: 'revision')), + ).thenReturn(genSnapshotFile); when( () => aotBuildProcessResult.exitCode, ).thenReturn(ExitCode.success.code); @@ -402,7 +406,7 @@ Either create a new release using: ${lightCyan.wrap('shorebird release aar')} Or downgrade your Flutter version and try again using: - ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory.path}')} + ${lightCyan.wrap('cd ${shorebirdEnv.flutterDirectory().path}')} ${lightCyan.wrap('git checkout ${release.flutterRevision}')} Shorebird plans to support this automatically, let us know if it's important to you: diff --git a/packages/shorebird_cli/test/src/commands/upgrade_command_test.dart b/packages/shorebird_cli/test/src/commands/upgrade_command_test.dart index 3a35a7e9..61d57b3f 100644 --- a/packages/shorebird_cli/test/src/commands/upgrade_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/upgrade_command_test.dart @@ -61,7 +61,7 @@ void main() { command = runWithOverrides(UpgradeCommand.new); when( - () => shorebirdEnv.flutterDirectory, + () => shorebirdEnv.flutterDirectory(revision: any(named: 'revision')), ).thenReturn(Directory('flutter')); when( shorebirdVersionManager.fetchCurrentGitHash, diff --git a/packages/shorebird_cli/test/src/ios_deploy_test.dart b/packages/shorebird_cli/test/src/ios_deploy_test.dart index ebe18e16..428574cc 100644 --- a/packages/shorebird_cli/test/src/ios_deploy_test.dart +++ b/packages/shorebird_cli/test/src/ios_deploy_test.dart @@ -66,9 +66,9 @@ void main() { final tempDir = Directory.systemTemp.createTempSync(); when(() => shorebirdEnv.shorebirdRoot).thenReturn(tempDir); - when(() => shorebirdEnv.flutterDirectory).thenReturn( - Directory(p.join(tempDir.path, 'bin', 'cache', 'flutter')), - ); + when( + () => shorebirdEnv.flutterDirectory(revision: any(named: 'revision')), + ).thenReturn(Directory(p.join(tempDir.path, 'bin', 'cache', 'flutter'))); when(() => logger.progress(any())).thenReturn(progress); when( () => shorebirdProcess.start(any(), any()), diff --git a/packages/shorebird_cli/test/src/shorebird_env_test.dart b/packages/shorebird_cli/test/src/shorebird_env_test.dart index d178b6d2..36086656 100644 --- a/packages/shorebird_cli/test/src/shorebird_env_test.dart +++ b/packages/shorebird_cli/test/src/shorebird_env_test.dart @@ -13,6 +13,7 @@ class _MockPlatform extends Mock implements Platform {} void main() { group(ShorebirdEnv, () { + const flutterRevision = 'test-flutter-revision'; late Platform platform; late Directory shorebirdRoot; late Uri platformScript; @@ -32,6 +33,11 @@ void main() { platformScript = Uri.file( p.join(shorebirdRoot.path, 'bin', 'cache', 'shorebird.snapshot'), ); + File( + p.join(shorebirdRoot.path, 'bin', 'internal', 'flutter.version'), + ) + ..createSync(recursive: true) + ..writeAsStringSync(flutterRevision, flush: true); platform = _MockPlatform(); shorebirdEnv = runWithOverrides(ShorebirdEnv.new); @@ -40,15 +46,38 @@ void main() { }); group('flutterBinaryFile', () { - test('returns correct path', () { + test('returns correct path using the default revision', () { expect( - runWithOverrides(() => shorebirdEnv.flutterBinaryFile.path), + runWithOverrides(() => shorebirdEnv.flutterBinaryFile().path), equals( p.join( shorebirdRoot.path, 'bin', 'cache', 'flutter', + flutterRevision, + 'bin', + 'flutter', + ), + ), + ); + }); + + test('returns correct path using a custom revision', () { + const customFlutterRevision = 'custom-flutter-revision'; + expect( + runWithOverrides( + () => shorebirdEnv + .flutterBinaryFile(revision: customFlutterRevision) + .path, + ), + equals( + p.join( + shorebirdRoot.path, + 'bin', + 'cache', + 'flutter', + customFlutterRevision, 'bin', 'flutter', ), @@ -58,15 +87,42 @@ void main() { }); group('genSnapshotFile', () { - test('returns correct path', () { + test('returns correct path using the default revision', () { expect( - runWithOverrides(() => shorebirdEnv.genSnapshotFile.path), + runWithOverrides(() => shorebirdEnv.genSnapshotFile().path), equals( p.join( shorebirdRoot.path, 'bin', 'cache', 'flutter', + flutterRevision, + 'bin', + 'cache', + 'artifacts', + 'engine', + 'ios-release', + 'gen_snapshot_arm64', + ), + ), + ); + }); + + test('returns correct path using a custom revision', () { + const customFlutterRevision = 'custom-flutter-revision'; + expect( + runWithOverrides( + () => shorebirdEnv + .genSnapshotFile(revision: customFlutterRevision) + .path, + ), + equals( + p.join( + shorebirdRoot.path, + 'bin', + 'cache', + 'flutter', + customFlutterRevision, 'bin', 'cache', 'artifacts', @@ -364,24 +420,52 @@ test-revision }); group('shorebirdEngineRevision', () { - test('returns correct revision', () { - const revision = 'test-revision'; + test('returns correct revision using default flutter revision', () { + const engineRevision = 'test-revision'; File( p.join( shorebirdRoot.path, 'bin', 'cache', 'flutter', + flutterRevision, 'bin', 'internal', 'engine.version', ), ) ..createSync(recursive: true) - ..writeAsStringSync(revision, flush: true); + ..writeAsStringSync(engineRevision, flush: true); expect( - runWithOverrides(() => shorebirdEnv.shorebirdEngineRevision), - equals(revision), + runWithOverrides(() => shorebirdEnv.shorebirdEngineRevision()), + equals(engineRevision), + ); + }); + + test('returns correct revision using a custom flutter revision', () { + const engineRevision = 'test-revision'; + const customFlutterRevision = 'custom-flutter-revision'; + File( + p.join( + shorebirdRoot.path, + 'bin', + 'cache', + 'flutter', + customFlutterRevision, + 'bin', + 'internal', + 'engine.version', + ), + ) + ..createSync(recursive: true) + ..writeAsStringSync(engineRevision, flush: true); + expect( + runWithOverrides( + () => shorebirdEnv.shorebirdEngineRevision( + flutterRevision: customFlutterRevision, + ), + ), + equals(engineRevision), ); }); }); diff --git a/packages/shorebird_cli/test/src/shorebird_process_test.dart b/packages/shorebird_cli/test/src/shorebird_process_test.dart index f629c225..25644741 100644 --- a/packages/shorebird_cli/test/src/shorebird_process_test.dart +++ b/packages/shorebird_cli/test/src/shorebird_process_test.dart @@ -45,11 +45,9 @@ void main() { () => ShorebirdProcess(processWrapper: processWrapper), ); - when(() => shorebirdEnv.flutterBinaryFile).thenReturn( - File( - p.join('bin', 'cache', 'flutter', 'bin', 'flutter'), - ), - ); + when( + () => shorebirdEnv.flutterBinaryFile(revision: any(named: 'revision')), + ).thenReturn(File(p.join('bin', 'cache', 'flutter', 'bin', 'flutter'))); when( () => processWrapper.run( any(), diff --git a/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart b/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart index 7dadd51b..3ae1ece0 100644 --- a/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart +++ b/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart @@ -76,7 +76,7 @@ Tools • Dart 2.19.6 • DevTools 2.20.1 when(() => shorebirdEnv.flutterRevision).thenReturn(flutterRevision); when( - () => shorebirdEnv.flutterDirectory, + () => shorebirdEnv.flutterDirectory(revision: any(named: 'revision')), ).thenReturn(flutterDirectory(tempDir)); when(() => platform.script).thenReturn(shorebirdScriptFile(tempDir).uri); when(() => platform.environment).thenReturn({}); diff --git a/third_party/flutter/bin/internal/shared.sh b/third_party/flutter/bin/internal/shared.sh index 88b3b158..f7235293 100755 --- a/third_party/flutter/bin/internal/shared.sh +++ b/third_party/flutter/bin/internal/shared.sh @@ -188,7 +188,7 @@ function shared::execute() { SNAPSHOT_PATH="$SHOREBIRD_ROOT/bin/cache/shorebird.snapshot" STAMP_PATH="$SHOREBIRD_ROOT/bin/cache/shorebird.stamp" SCRIPT_PATH="$SHOREBIRD_CLI_DIR/bin/shorebird.dart" - FLUTTER_PATH="$SHOREBIRD_ROOT/bin/cache/flutter" + FLUTTER_PATH="$SHOREBIRD_ROOT/bin/cache/flutter/$FLUTTER_VERSION" export DART_PATH="$FLUTTER_PATH/bin/cache/dart-sdk/bin/dart" # Test if running as superuser – but don't warn if running within Docker or CI.