Skip to content

Commit

Permalink
Fixing issues with fvm and puby link
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexios80 committed Apr 26, 2024
1 parent 04a14a4 commit 815fee6
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 32 deletions.
3 changes: 2 additions & 1 deletion bin/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Future<void> linkDependencies(
project.resolveWithCommand(Command(['pub', 'get', '--offline']));
if (resolved.exclude) return;

final flutterVersionOverride = resolved.getFlutterVersionOverride();
final flutterVersionOverride =
await resolved.getFlutterVersionOverride();

final entry = Entrypoint(resolved.path, _pubCache);
try {
Expand Down
13 changes: 7 additions & 6 deletions bin/projects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,16 @@ extension ProjectExtension on Project {
return copyWith(engine: resolvedEngine, exclude: exclude);
}

Version? getFlutterVersionOverride() {
Future<Version?> getFlutterVersionOverride() async {
if (engine != Engine.fvm) return null;

final result = Process.runSync(
'fvm',
['flutter', '--version', '--machine'],
workingDirectory: path,
);
try {
// TODO: Do this a better way (https://github.com/leoafarias/fvm/issues/710)
final result = await Process.run(
'fvm',
['flutter', '--version', '--machine'],
workingDirectory: path,
).timeout(Duration(seconds: 1));
final versionString =
jsonDecode(result.stdout as String)['frameworkVersion'] as String?;
if (versionString == null) {
Expand Down
16 changes: 9 additions & 7 deletions bin/puby.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Future<int> runInProject({
if (!command.silent) {
stdout.write(line);
}
if (!command.raw && shouldKill(resolved, line)) {
if (!command.raw && shouldKill(resolved, command, line)) {
killed = process.kill();
}
}).asFuture();
Expand Down Expand Up @@ -234,19 +234,21 @@ Future<int> runInProject({
}

/// Check if we should continue after this line is received
bool shouldKill(Project project, String line) {
bool shouldKill(Project project, Command command, String line) {
if (project.engine == Engine.fvm) {
final flutterVersionNotInstalledMatch =
RegExp(r'Flutter SDK: SDK Version : (.+?) is not installed\.')
.firstMatch(line);
if (flutterVersionNotInstalledMatch != null) {
// FVM will ask for input from the user, kill the process to avoid
// hanging
print(
redPen(
'\nRun `fvm install ${flutterVersionNotInstalledMatch[1]}` first',
),
);
if (!command.silent) {
print(
redPen(
'\nRun `fvm install ${flutterVersionNotInstalledMatch[1]}` first',
),
);
}
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum Engine {
case Engine.flutter:
return [name];
case Engine.fvm:
return ['fvm' 'flutter'];
return ['fvm', 'flutter'];
}
}
}
8 changes: 8 additions & 0 deletions test/link_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:path/path.dart' as p;
import 'package:test/test.dart';

Expand All @@ -22,5 +24,11 @@ void main() {

// fvm
expectLine(stdout, ['fvm_puby_test', 'fvm flutter pub get --offline']);
// Ensure the correct flutter version was used
expect(
File('test_resources/fvm_puby_test/.dart_tool/version')
.readAsStringSync(),
'3.10.0',
);
});
}
2 changes: 1 addition & 1 deletion test_resources/fvm_puby_test/.fvmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"flutter": "stable",
"flutter": "3.10.0",
"flavors": {}
}
2 changes: 1 addition & 1 deletion test_resources/fvm_puby_test/example/.fvmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"flutter": "stable",
"flutter": "3.10.0",
"flavors": {}
}
22 changes: 15 additions & 7 deletions test_resources/fvm_puby_test/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,39 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.17.1"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
url: "https://pub.dev"
source: hosted
version: "0.8.0"
version: "0.2.0"
meta:
dependency: transitive
description:
name: meta
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.9.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -52,4 +60,4 @@ packages:
source: hosted
version: "2.1.4"
sdks:
dart: ">=3.2.0-0 <4.0.0"
dart: ">=3.0.0 <4.0.0"
2 changes: 1 addition & 1 deletion test_resources/fvm_puby_test/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: example
publish_to: none

environment:
sdk: ">=2.16.2 <3.0.0"
sdk: ^3.0.0

dependencies:
flutter:
Expand Down
22 changes: 15 additions & 7 deletions test_resources/fvm_puby_test/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,39 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.17.1"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
url: "https://pub.dev"
source: hosted
version: "0.8.0"
version: "0.2.0"
meta:
dependency: transitive
description:
name: meta
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.9.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -52,4 +60,4 @@ packages:
source: hosted
version: "2.1.4"
sdks:
dart: ">=3.2.0-0 <4.0.0"
dart: ">=3.0.0 <4.0.0"

0 comments on commit 815fee6

Please sign in to comment.