Skip to content
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

feat(shorebird_cli): scope Flutter installations by revision #1007

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions bin/shorebird.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/shorebird_cli/lib/src/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/shorebird_cli/lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/shorebird_cli/lib/src/ios_deploy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class IOSDeploy {
@visibleForTesting
static File get iosDeployExecutable => File(
p.join(
shorebirdEnv.flutterDirectory.path,
shorebirdEnv.flutterDirectory().path,
'bin',
'cache',
'artifacts',
Expand Down
2 changes: 1 addition & 1 deletion packages/shorebird_cli/lib/src/process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/shorebird_cli/lib/src/shorebird_build_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ mixin ShorebirdBuildMixin on ShorebirdCommand {
];

final result = await process.run(
shorebirdEnv.genSnapshotFile.path,
shorebirdEnv.genSnapshotFile().path,
arguments,
);

Expand Down
20 changes: 13 additions & 7 deletions packages/shorebird_cli/lib/src/shorebird_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ShorebirdFlutterValidator extends Validator {
Future<List<ValidationIssue>> validate() async {
final issues = <ValidationIssue>[];

if (!shorebirdEnv.flutterDirectory.existsSync()) {
if (!shorebirdEnv.flutterDirectory().existsSync()) {
final message = 'No Flutter directory found at '
'${shorebirdEnv.flutterDirectory}';
issues.add(
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/shorebird_cli/test/src/cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion packages/shorebird_cli/test/src/command_runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/shorebird_cli/test/src/ios_deploy_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Loading