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

This commit is contained in:
Felix Angelov
2023-08-03 11:08:59 -05:00
committed by GitHub
parent 6b50023b64
commit 5c04a68df1
27 changed files with 161 additions and 56 deletions
+2 -3
View File
@@ -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
+1 -1
View File
@@ -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';
}
}
@@ -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 {
@@ -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);
@@ -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:
@@ -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:
@@ -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:
@@ -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:
@@ -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) {
@@ -33,7 +33,7 @@ class IOSDeploy {
@visibleForTesting
static File get iosDeployExecutable => File(
p.join(
shorebirdEnv.flutterDirectory.path,
shorebirdEnv.flutterDirectory().path,
'bin',
'cache',
'artifacts',
+1 -1
View File
@@ -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;
}
@@ -328,7 +328,7 @@ mixin ShorebirdBuildMixin on ShorebirdCommand {
];
final result = await process.run(
shorebirdEnv.genSnapshotFile.path,
shorebirdEnv.genSnapshotFile().path,
arguments,
);
@@ -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',
@@ -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(
@@ -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;
}
@@ -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);
@@ -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);
});
@@ -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(
@@ -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:
@@ -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:
@@ -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:
@@ -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:
@@ -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,
@@ -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()),
@@ -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),
);
});
});
@@ -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(),
@@ -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({});
+1 -1
View File
@@ -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.