Skip to content

Commit

Permalink
Fixes for link command running in flutter examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexios80 committed Apr 26, 2024
1 parent ae4d164 commit 7f4ecfd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
3 changes: 2 additions & 1 deletion bin/commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'projects.dart';
abstract class Commands {
static final clean = ProjectCommand(['clean'], parallel: true);
static final link = GlobalCommand(
['link'],
(command, projects) =>
linkDependencies(command: command, projects: projects),
);
Expand Down Expand Up @@ -54,7 +55,7 @@ abstract class Commands {
};

/// Check if we should continue after this line is received
static bool shouldKill(Project project, ProjectCommand command, String line) {
static bool shouldKill(Project project, Command command, String line) {
if (project.engine == Engine.fvm) {
final flutterVersionNotInstalledMatch =
RegExp(r'Flutter SDK: SDK Version : (.+?) is not installed\.')
Expand Down
5 changes: 2 additions & 3 deletions bin/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:puby/project.dart';
import 'package:puby/pub.dart';
import 'package:puby/time.dart';

import 'commands.dart';
import 'projects.dart';

final _pubCache = SystemCache();
Expand All @@ -23,11 +22,11 @@ Future<int> linkDependencies({
for (final project in projects) {
unawaited(
resolutionQueue.add(() async {
final resolved = project.resolveWithCommand(Commands.pubGetOffline);
final resolved = project.resolveWithCommand(command);
if (resolved.exclude) return;

final flutterVersionOverride =
await resolved.getFlutterVersionOverride(Commands.pubGetOffline);
await resolved.getFlutterVersionOverride(command);

final entry = Entrypoint(resolved.path, _pubCache);
try {
Expand Down
14 changes: 6 additions & 8 deletions bin/projects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ List<Project> findProjects() {
}

extension ProjectExtension on Project {
Engine _resolveEngine(ProjectCommand command) {
Engine _resolveEngine(Command command) {
final isCleanCommand = command.args[0] == 'clean';
final isTestCoverageCommand = command.args.length >= 2 &&
command.args[0] == 'test' &&
Expand Down Expand Up @@ -96,13 +96,12 @@ extension ProjectExtension on Project {
return newEngine;
}

bool _defaultExclude(ProjectCommand command) {
bool _defaultExclude(Command command) {
final isPubGetInFlutterExample = engine.isFlutter &&
example &&
command.args.length >= 2 &&
command.args[0] == 'pub' &&
command.args[1] == 'get';
final isOffline = command.args.contains('--offline');

final bool skip;
final String? message;
Expand All @@ -113,9 +112,8 @@ extension ProjectExtension on Project {
} else if (path.startsWith('build/') || path.contains('/build/')) {
message = 'Skipping project in build folder: $path';
skip = true;
} else if (isPubGetInFlutterExample && !isOffline) {
} else if (isPubGetInFlutterExample) {
// Skip flutter pub get in example projects since flutter does it anyways
// Do not skip if this is an offline pub command
message = 'Skipping flutter example project: $path';
skip = true;
} else {
Expand All @@ -129,7 +127,7 @@ extension ProjectExtension on Project {
return skip;
}

bool _explicitExclude(ProjectCommand command) {
bool _explicitExclude(Command command) {
final argString = command.args.join(' ');

final skip = config.excludes.any(argString.startsWith);
Expand All @@ -140,13 +138,13 @@ extension ProjectExtension on Project {
return skip;
}

Project resolveWithCommand(ProjectCommand command) {
Project resolveWithCommand(Command command) {
final resolvedEngine = _resolveEngine(command);
final exclude = _defaultExclude(command) || _explicitExclude(command);
return copyWith(engine: resolvedEngine, exclude: exclude);
}

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

try {
Expand Down
14 changes: 6 additions & 8 deletions lib/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ abstract class Command {
/// If fvm support should be disabled
bool get noFvm => _noFvm;

/// If output from this command should be displayed
final bool silent;

/// Constructor
Command(List<String> args) {
Command(List<String> args, {required this.silent}) {
addArgs(args);
}

Expand All @@ -35,17 +38,12 @@ class ProjectCommand extends Command {
/// Whether to run the command in all projects in parallel
final bool parallel;

/// Whether to run the command silently
///
/// Right now this is the same as [parallel]
bool get silent => parallel;

/// Constructor
ProjectCommand(
super.args, {
this.raw = false,
this.parallel = false,
});
}) : super(silent: parallel);
}

/// A command to run in the working directory
Expand All @@ -55,7 +53,7 @@ class GlobalCommand extends Command {
_run;

/// Constructor
GlobalCommand(this._run) : super([]);
GlobalCommand(super.args, this._run) : super(silent: false);

/// Run the command
Future<int> run({required List<Project> projects}) => _run(this, projects);
Expand Down
11 changes: 11 additions & 0 deletions test/link_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ void main() {
// flutter
expectLine(stdout, ['flutter_puby_test', 'Resolved dependencies for']);
expectLine(stdout, ['flutter_puby_test', 'flutter pub get --offline']);
// The link should run in the example app
expectLine(
stdout,
['flutter_puby_test/example', 'Resolved dependencies for'],
);
// The pub get should NOT run in the example app
expectLine(
stdout,
['flutter_puby_test/example', 'flutter pub get --offline'],
matches: false,
);

// fvm
expectLine(stdout, ['fvm_puby_test', 'Resolved dependencies for']);
Expand Down
4 changes: 2 additions & 2 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ Future<ProcessResult> testCommand(
);
}

void expectLine(dynamic stdout, List<String> matchers) {
void expectLine(dynamic stdout, List<String> matchers, {bool matches = true}) {
final lines = (stdout as String).split('\n');
expect(
lines.any(
(line) =>
matchers.fold(true, (prev, next) => prev && line.contains(next)),
),
isTrue,
matches,
);
}

0 comments on commit 7f4ecfd

Please sign in to comment.