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

fix: old aot_tools binaries do not work #1645

Merged
merged 7 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 13 additions & 20 deletions packages/shorebird_cli/lib/src/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CacheUpdateFailure implements Exception {
String toString() => 'CacheUpdateFailure: $message';
}

typedef ArchiveExtracter = Future<void> Function(
typedef ArchiveExtractor = Future<void> Function(
eseidel marked this conversation as resolved.
Show resolved Hide resolved
String archivePath,
String outputPath,
);
Expand Down Expand Up @@ -62,7 +62,7 @@ class Cache {
registerArtifact(AotToolsArtifact(cache: this, platform: platform));
}

final ArchiveExtracter extractArchive;
final ArchiveExtractor extractArchive;

void registerArtifact(CachedArtifact artifact) => _artifacts.add(artifact);

Expand Down Expand Up @@ -133,19 +133,21 @@ abstract class CachedArtifact {
final Cache cache;
final Platform platform;

/// The on-disk name of the artifact.
eseidel marked this conversation as resolved.
Show resolved Hide resolved
String get name;

String get storageUrl;

String get fileName;

/// Should the artifact be marked executable.
bool get isExecutable;

/// The URL from which the artifact can be downloaded.
String get storageUrl;

/// Whether the artifact is required for Shorebird to function.
/// If we fail to fetch it we will exit with an error.
bool get required => true;

Future<void> extractArtifact(http.ByteStream stream, String outputPath) {
final file = File(p.join(outputPath, fileName))
..createSync(recursive: true);
final file = File(p.join(outputPath, name))..createSync(recursive: true);
return stream.pipe(file.openWrite());
}

Expand Down Expand Up @@ -185,7 +187,7 @@ allowed to access $storageUrl.''',
if (!platform.isWindows && isExecutable) {
final result = await process.start(
'chmod',
['+x', p.join(location.path, fileName)],
['+x', p.join(location.path, name)],
);
await result.exitCode;
}
Expand All @@ -196,10 +198,7 @@ class AotToolsArtifact extends CachedArtifact {
AotToolsArtifact({required super.cache, required super.platform});

@override
String get name => 'aot-tools';

@override
String get fileName => 'aot-tools.dill';
String get name => 'aot-tools.dill';

@override
bool get isExecutable => false;
Expand All @@ -218,7 +217,7 @@ class AotToolsArtifact extends CachedArtifact {

@override
String get storageUrl =>
'${cache.storageBaseUrl}/${cache.storageBucket}/shorebird/${shorebirdEnv.shorebirdEngineRevision}/aot-tools.dill';
'${cache.storageBaseUrl}/${cache.storageBucket}/shorebird/${shorebirdEnv.shorebirdEngineRevision}/$name';
eseidel marked this conversation as resolved.
Show resolved Hide resolved
}

class PatchArtifact extends CachedArtifact {
Expand All @@ -227,9 +226,6 @@ class PatchArtifact extends CachedArtifact {
@override
String get name => 'patch';

@override
String get fileName => 'patch';

@override
bool get isExecutable => true;

Expand Down Expand Up @@ -265,9 +261,6 @@ class BundleToolArtifact extends CachedArtifact {
@override
String get name => 'bundletool.jar';

@override
String get fileName => 'bundletool.jar';

@override
bool get isExecutable => false;

Expand Down
14 changes: 13 additions & 1 deletion packages/shorebird_cli/lib/src/executables/aot_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,21 @@ class AotTools {
artifact: ShorebirdArtifact.aotTools,
);

// Fallback behavior for older versions of shorebird where aot-tools was
// distributed as an executable.
final extension = p.extension(artifactPath);
if (extension != '.dill' && extension != '.dart') {
return process.run(
artifactPath,
command,
workingDirectory: workingDirectory,
);
}

// local engine versions use .dart and we distribute aot-tools as a .dill
return process.run(
shorebirdEnv.dartBinaryFile.path,
[artifactPath, ...command],
['run', artifactPath, ...command],
workingDirectory: workingDirectory,
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/shorebird_cli/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ packages:
dependency: "direct main"
description:
name: http
sha256: d4872660c46d929f6b8a9ef4e7a7eff7e49bbf0c4ec3f385ee32df5119175139
sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba
url: "https://pub.dev"
source: hosted
version: "1.1.2"
version: "1.2.0"
http_multi_server:
dependency: transitive
description:
Expand Down
5 changes: 1 addition & 4 deletions packages/shorebird_cli/test/src/cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class TestCachedArtifact extends CachedArtifact {
@override
String get name => 'test';

@override
String get fileName => 'test';

@override
bool get isExecutable => true;

Expand Down Expand Up @@ -230,7 +227,7 @@ void main() {
);
verify(
() => logger.detail(
'''[cache] optional artifact: "aot-tools" was not found, skipping...''',
'''[cache] optional artifact: "aot-tools.dill" was not found, skipping...''',
),
).called(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void main() {
() => shorebirdArtifacts.getArtifactPath(
artifact: ShorebirdArtifact.aotTools,
),
).thenReturn('aot-tools');
).thenReturn('aot-tools.dill');
when(
() => process.run(
dartBinaryFile.path,
Expand Down Expand Up @@ -136,6 +136,7 @@ void main() {
() => process.run(
dartBinaryFile.path,
[
'run',
aotToolsPath,
'link',
'--base=$base',
Expand Down Expand Up @@ -190,6 +191,7 @@ void main() {
() => process.run(
dartBinaryFile.path,
[
'run',
aotToolsPath,
'link',
'--base=$base',
Expand Down
Loading