Skip to content

Commit ab7a990

Browse files
Throw an error if --local-engine-host is used without --local-engine (#166948)
The artifact selector will only use artifacts from the local engine if both of these flags are provided.
1 parent f20bc39 commit ab7a990

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

packages/flutter_tools/lib/src/base/user_messages.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ class UserMessages {
330330
'You are using a locally built engine (--local-engine) but have not specified --local-engine-host.\n'
331331
'You may be building with a different engine than the one you are running with. '
332332
'See https://github.com/flutter/flutter/issues/132245 for details.';
333+
String get runnerHostEngineRequiresLocalEngine =>
334+
'You must specify --local-engine if you are using --local-engine-host.';
333335
String runnerNoEngineBuild(String engineBuildPath) =>
334336
'No Flutter engine build found at $engineBuildPath.';
335337
String runnerNoWebSdk(String webSdkPath) => 'No Flutter web sdk found at $webSdkPath.';

packages/flutter_tools/lib/src/runner/local_engine.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class LocalEngineLocator {
5050
String? localWebSdk,
5151
String? packagePath,
5252
}) async {
53+
if (localHostEngine != null && localEngine == null) {
54+
throwToolExit(_userMessages.runnerHostEngineRequiresLocalEngine, exitCode: 2);
55+
}
56+
5357
engineSourcePath ??= _platform.environment[kFlutterEngineEnvironmentVariableName];
5458
if (engineSourcePath == null &&
5559
localEngine == null &&

packages/flutter_tools/test/general.shard/runner/local_engine_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,32 @@ void main() {
482482
);
483483
},
484484
);
485+
486+
testWithoutContext('fails if --local-engine-host is used without --local-engine', () async {
487+
final FileSystem fileSystem = MemoryFileSystem.test();
488+
final Directory localEngine = fileSystem.directory(
489+
'$kArbitraryEngineRoot/src/out/android_debug_unopt_arm64/',
490+
)..createSync(recursive: true);
491+
fileSystem
492+
.directory('$kArbitraryEngineRoot/src/out/host_debug_unopt/')
493+
.createSync(recursive: true);
494+
495+
final BufferLogger logger = BufferLogger.test();
496+
final LocalEngineLocator localEngineLocator = LocalEngineLocator(
497+
fileSystem: fileSystem,
498+
flutterRoot: 'flutter/flutter',
499+
logger: logger,
500+
userMessages: UserMessages(),
501+
platform: FakePlatform(environment: <String, String>{}),
502+
);
503+
504+
await expectLater(
505+
localEngineLocator.findEnginePath(localHostEngine: localEngine.path),
506+
throwsToolExit(
507+
message: 'You must specify --local-engine if you are using --local-engine-host.',
508+
),
509+
);
510+
});
485511
}
486512

487513
Matcher matchesEngineBuildPaths({String? hostEngine, String? targetEngine}) {

0 commit comments

Comments
 (0)