Skip to content

Commit 6579844

Browse files
authored
Update flutter_tools internals related to Gradle/XCode to set --local-engine-host. (#132346)
Partial work towards flutter/flutter#132245. I made a minor refactor to test-only code because it was too confusing to have 2 optional parameters that are technically required together, but otherwise all other changes *should* be pass throughs. That being said, I can't say I totally understand the Gradle stuff so I could use a hand double checking that.
1 parent 9526142 commit 6579844

File tree

9 files changed

+73
-33
lines changed

9 files changed

+73
-33
lines changed

packages/flutter_tools/gradle/src/main/groovy/flutter.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ class FlutterPlugin implements Plugin<Project> {
164164
private File flutterRoot
165165
private File flutterExecutable
166166
private String localEngine
167+
private String localEngineHost
167168
private String localEngineSrcPath
168169
private Properties localProperties
169170
private String engineVersion
@@ -324,6 +325,13 @@ class FlutterPlugin implements Plugin<Project> {
324325
}
325326
localEngine = engineOut.name
326327
localEngineSrcPath = engineOut.parentFile.parent
328+
329+
String engineHostOutPath = project.property('local-engine-host-out')
330+
File engineHostOut = project.file(engineHostOutPath)
331+
if (!engineHostOut.isDirectory()) {
332+
throw new GradleException('local-engine-host-out must point to a local engine host build')
333+
}
334+
localEngineHostOut = engineHostOut.name
327335
}
328336
project.android.buildTypes.all this.&addFlutterDependencies
329337
}
@@ -1027,6 +1035,7 @@ class FlutterPlugin implements Plugin<Project> {
10271035
flutterExecutable this.flutterExecutable
10281036
buildMode variantBuildMode
10291037
localEngine this.localEngine
1038+
localEngineHost this.localEngineHost
10301039
localEngineSrcPath this.localEngineSrcPath
10311040
targetPath getFlutterTarget()
10321041
verbose this.isVerbose()
@@ -1235,6 +1244,8 @@ abstract class BaseFlutterTask extends DefaultTask {
12351244
@Optional @Input
12361245
String localEngine
12371246
@Optional @Input
1247+
String localEngineHost
1248+
@Optional @Input
12381249
String localEngineSrcPath
12391250
@Optional @Input
12401251
Boolean fastStart
@@ -1313,6 +1324,9 @@ abstract class BaseFlutterTask extends DefaultTask {
13131324
args "--local-engine", localEngine
13141325
args "--local-engine-src-path", localEngineSrcPath
13151326
}
1327+
if (localEngineHost != null) {
1328+
args "--local-engine-host", localEngineHost
1329+
}
13161330
if (verbose) {
13171331
args "--verbose"
13181332
} else {

packages/flutter_tools/lib/src/android/gradle.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
401401
command.add('-Plocal-engine-repo=${localEngineRepo.path}');
402402
command.add('-Plocal-engine-build-mode=${buildInfo.modeName}');
403403
command.add('-Plocal-engine-out=${localEngineInfo.engineOutPath}');
404+
command.add('-Plocal-engine-host-out=${localEngineInfo.engineHostOutPath}');
404405
command.add('-Ptarget-platform=${_getTargetPlatformByLocalEnginePath(
405406
localEngineInfo.engineOutPath)}');
406407
} else if (androidBuildInfo.targetArchs.isNotEmpty) {
@@ -726,6 +727,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
726727
command.add('-Plocal-engine-repo=${localEngineRepo.path}');
727728
command.add('-Plocal-engine-build-mode=${buildInfo.modeName}');
728729
command.add('-Plocal-engine-out=${localEngineInfo.engineOutPath}');
730+
command.add('-Plocal-engine-host-out=${localEngineInfo.engineHostOutPath}');
729731

730732
// Copy the local engine repo in the output directory.
731733
try {

packages/flutter_tools/lib/src/artifacts.dart

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'package:file/memory.dart';
6+
import 'package:meta/meta.dart';
67
import 'package:process/process.dart';
78

89
import 'base/common.dart';
@@ -287,10 +288,12 @@ class EngineBuildPaths {
287288
class LocalEngineInfo {
288289
const LocalEngineInfo({
289290
required this.engineOutPath,
291+
required this.engineHostOutPath,
290292
required this.localEngineName,
291293
});
292294

293295
final String engineOutPath;
296+
final String engineHostOutPath;
294297
final String localEngineName;
295298
}
296299

@@ -302,12 +305,23 @@ abstract class Artifacts {
302305
/// If a [fileSystem] is not provided, creates a new [MemoryFileSystem] instance.
303306
///
304307
/// Creates a [LocalEngineArtifacts] if `localEngine` is non-null
305-
factory Artifacts.test({String? localEngine, FileSystem? fileSystem}) {
306-
fileSystem ??= MemoryFileSystem.test();
307-
if (localEngine != null) {
308-
return _TestLocalEngine(localEngine, fileSystem);
309-
}
310-
return _TestArtifacts(fileSystem);
308+
@visibleForTesting
309+
factory Artifacts.test({FileSystem? fileSystem}) {
310+
return _TestArtifacts(fileSystem ?? MemoryFileSystem.test());
311+
}
312+
313+
/// A test-specific implementation of artifacts that returns stable paths for
314+
/// all artifacts, and uses a local engine.
315+
///
316+
/// If a [fileSystem] is not provided, creates a new [MemoryFileSystem] instance.
317+
@visibleForTesting
318+
factory Artifacts.testLocalEngine({
319+
required String localEngine,
320+
required String localEngineHost,
321+
FileSystem? fileSystem,
322+
}) {
323+
return _TestLocalEngine(
324+
localEngine, localEngineHost, fileSystem ?? MemoryFileSystem.test());
311325
}
312326

313327
static Artifacts getLocalEngine(EngineBuildPaths engineBuildPaths) {
@@ -811,6 +825,7 @@ class CachedLocalEngineArtifacts implements Artifacts {
811825
localEngineInfo =
812826
LocalEngineInfo(
813827
engineOutPath: engineOutPath,
828+
engineHostOutPath: _hostEngineOutPath,
814829
localEngineName: fileSystem.path.basename(engineOutPath)
815830
),
816831
_cache = cache,
@@ -1365,12 +1380,12 @@ class _TestArtifacts implements Artifacts {
13651380
}
13661381

13671382
class _TestLocalEngine extends _TestArtifacts {
1368-
_TestLocalEngine(String engineOutPath, super.fileSystem) :
1369-
localEngineInfo =
1370-
LocalEngineInfo(
1371-
engineOutPath: engineOutPath,
1372-
localEngineName: fileSystem.path.basename(engineOutPath)
1373-
);
1383+
_TestLocalEngine(
1384+
String engineOutPath, String engineHostOutPath, super.fileSystem)
1385+
: localEngineInfo = LocalEngineInfo(
1386+
engineOutPath: engineOutPath,
1387+
engineHostOutPath: engineHostOutPath,
1388+
localEngineName: fileSystem.path.basename(engineOutPath));
13741389

13751390
@override
13761391
bool get isLocalEngine => true;

packages/flutter_tools/lib/src/ios/mac.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class IMobileDevice {
7272
/// Create an [IMobileDevice] for testing.
7373
factory IMobileDevice.test({ required ProcessManager processManager }) {
7474
return IMobileDevice(
75+
// ignore: invalid_use_of_visible_for_testing_member
7576
artifacts: Artifacts.test(),
7677
cache: Cache.test(processManager: processManager),
7778
processManager: processManager,

packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void main() {
192192
));
193193
await commandRunner.run(<String>['assemble', '-o Output', 'debug_macos_bundle_flutter_assets']);
194194
}, overrides: <Type, Generator>{
195-
Artifacts: () => Artifacts.test(localEngine: 'out/host_release'),
195+
Artifacts: () => Artifacts.testLocalEngine(localEngine: 'out/host_release', localEngineHost: 'out/host_release'),
196196
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
197197
FileSystem: () => MemoryFileSystem.test(),
198198
ProcessManager: () => FakeProcessManager.any(),

packages/flutter_tools/test/general.shard/android/android_gradle_builder_test.dart

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ unknown crash
11871187
logger: logger,
11881188
processManager: processManager,
11891189
fileSystem: fileSystem,
1190-
artifacts: Artifacts.test(localEngine: 'out/android_arm'),
1190+
artifacts: Artifacts.testLocalEngine(localEngine: 'out/android_arm', localEngineHost: 'out/host_release'),
11911191
usage: testUsage,
11921192
gradleUtils: FakeGradleUtils(),
11931193
platform: FakePlatform(),
@@ -1200,6 +1200,7 @@ unknown crash
12001200
'-Plocal-engine-repo=/.tmp_rand0/flutter_tool_local_engine_repo.rand0',
12011201
'-Plocal-engine-build-mode=release',
12021202
'-Plocal-engine-out=out/android_arm',
1203+
'-Plocal-engine-host-out=out/host_release',
12031204
'-Ptarget-platform=android-arm',
12041205
'-Ptarget=lib/main.dart',
12051206
'-Pbase-application-name=io.flutter.app.FlutterApplication',
@@ -1266,7 +1267,7 @@ unknown crash
12661267
logger: logger,
12671268
processManager: processManager,
12681269
fileSystem: fileSystem,
1269-
artifacts: Artifacts.test(localEngine: 'out/android_arm64'),
1270+
artifacts: Artifacts.testLocalEngine(localEngine: 'out/android_arm64', localEngineHost: 'out/host_release'),
12701271
usage: testUsage,
12711272
gradleUtils: FakeGradleUtils(),
12721273
platform: FakePlatform(),
@@ -1279,6 +1280,7 @@ unknown crash
12791280
'-Plocal-engine-repo=/.tmp_rand0/flutter_tool_local_engine_repo.rand0',
12801281
'-Plocal-engine-build-mode=release',
12811282
'-Plocal-engine-out=out/android_arm64',
1283+
'-Plocal-engine-host-out=out/host_release',
12821284
'-Ptarget-platform=android-arm64',
12831285
'-Ptarget=lib/main.dart',
12841286
'-Pbase-application-name=io.flutter.app.FlutterApplication',
@@ -1345,7 +1347,7 @@ unknown crash
13451347
logger: logger,
13461348
processManager: processManager,
13471349
fileSystem: fileSystem,
1348-
artifacts: Artifacts.test(localEngine: 'out/android_x86'),
1350+
artifacts: Artifacts.testLocalEngine(localEngine: 'out/android_x86', localEngineHost: 'out/host_release'),
13491351
usage: testUsage,
13501352
gradleUtils: FakeGradleUtils(),
13511353
platform: FakePlatform(),
@@ -1358,6 +1360,7 @@ unknown crash
13581360
'-Plocal-engine-repo=/.tmp_rand0/flutter_tool_local_engine_repo.rand0',
13591361
'-Plocal-engine-build-mode=release',
13601362
'-Plocal-engine-out=out/android_x86',
1363+
'-Plocal-engine-host-out=out/host_release',
13611364
'-Ptarget-platform=android-x86',
13621365
'-Ptarget=lib/main.dart',
13631366
'-Pbase-application-name=io.flutter.app.FlutterApplication',
@@ -1424,7 +1427,7 @@ unknown crash
14241427
logger: logger,
14251428
processManager: processManager,
14261429
fileSystem: fileSystem,
1427-
artifacts: Artifacts.test(localEngine: 'out/android_x64'),
1430+
artifacts: Artifacts.testLocalEngine(localEngine: 'out/android_x64', localEngineHost: 'out/host_release'),
14281431
usage: testUsage,
14291432
gradleUtils: FakeGradleUtils(),
14301433
platform: FakePlatform(),
@@ -1437,6 +1440,7 @@ unknown crash
14371440
'-Plocal-engine-repo=/.tmp_rand0/flutter_tool_local_engine_repo.rand0',
14381441
'-Plocal-engine-build-mode=release',
14391442
'-Plocal-engine-out=out/android_x64',
1443+
'-Plocal-engine-host-out=out/host_release',
14401444
'-Ptarget-platform=android-x64',
14411445
'-Ptarget=lib/main.dart',
14421446
'-Pbase-application-name=io.flutter.app.FlutterApplication',
@@ -1565,7 +1569,7 @@ unknown crash
15651569
logger: logger,
15661570
processManager: processManager,
15671571
fileSystem: fileSystem,
1568-
artifacts: Artifacts.test(localEngine: 'out/android_arm'),
1572+
artifacts: Artifacts.testLocalEngine(localEngine: 'out/android_arm', localEngineHost: 'out/host_release'),
15691573
usage: testUsage,
15701574
gradleUtils: FakeGradleUtils(),
15711575
platform: FakePlatform(),
@@ -1586,6 +1590,7 @@ unknown crash
15861590
'-Plocal-engine-repo=/.tmp_rand0/flutter_tool_local_engine_repo.rand0',
15871591
'-Plocal-engine-build-mode=release',
15881592
'-Plocal-engine-out=out/android_arm',
1593+
'-Plocal-engine-host-out=out/host_release',
15891594
'-Ptarget-platform=android-arm',
15901595
'assembleAarRelease',
15911596
],
@@ -1653,7 +1658,7 @@ unknown crash
16531658
logger: logger,
16541659
processManager: processManager,
16551660
fileSystem: fileSystem,
1656-
artifacts: Artifacts.test(localEngine: 'out/android_arm64'),
1661+
artifacts: Artifacts.testLocalEngine(localEngine: 'out/android_arm64', localEngineHost: 'out/host_release'),
16571662
usage: testUsage,
16581663
gradleUtils: FakeGradleUtils(),
16591664
platform: FakePlatform(),
@@ -1674,6 +1679,7 @@ unknown crash
16741679
'-Plocal-engine-repo=/.tmp_rand0/flutter_tool_local_engine_repo.rand0',
16751680
'-Plocal-engine-build-mode=release',
16761681
'-Plocal-engine-out=out/android_arm64',
1682+
'-Plocal-engine-host-out=out/host_release',
16771683
'-Ptarget-platform=android-arm64',
16781684
'assembleAarRelease',
16791685
],
@@ -1741,7 +1747,7 @@ unknown crash
17411747
logger: logger,
17421748
processManager: processManager,
17431749
fileSystem: fileSystem,
1744-
artifacts: Artifacts.test(localEngine: 'out/android_x86'),
1750+
artifacts: Artifacts.testLocalEngine(localEngine: 'out/android_x86', localEngineHost: 'out/host_release'),
17451751
usage: testUsage,
17461752
gradleUtils: FakeGradleUtils(),
17471753
platform: FakePlatform(),
@@ -1762,6 +1768,7 @@ unknown crash
17621768
'-Plocal-engine-repo=/.tmp_rand0/flutter_tool_local_engine_repo.rand0',
17631769
'-Plocal-engine-build-mode=release',
17641770
'-Plocal-engine-out=out/android_x86',
1771+
'-Plocal-engine-host-out=out/host_release',
17651772
'-Ptarget-platform=android-x86',
17661773
'assembleAarRelease',
17671774
],
@@ -1829,7 +1836,7 @@ unknown crash
18291836
logger: logger,
18301837
processManager: processManager,
18311838
fileSystem: fileSystem,
1832-
artifacts: Artifacts.test(localEngine: 'out/android_x64'),
1839+
artifacts: Artifacts.testLocalEngine(localEngine: 'out/android_x64', localEngineHost: 'out/host_release'),
18331840
usage: testUsage,
18341841
gradleUtils: FakeGradleUtils(),
18351842
platform: FakePlatform(),
@@ -1850,6 +1857,7 @@ unknown crash
18501857
'-Plocal-engine-repo=/.tmp_rand0/flutter_tool_local_engine_repo.rand0',
18511858
'-Plocal-engine-build-mode=release',
18521859
'-Plocal-engine-out=out/android_x64',
1860+
'-Plocal-engine-host-out=out/host_release',
18531861
'-Ptarget-platform=android-x64',
18541862
'assembleAarRelease',
18551863
],

packages/flutter_tools/test/general.shard/android/gradle_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void main() {
211211

212212
setUp(() {
213213
fs = MemoryFileSystem.test();
214-
localEngineArtifacts = Artifacts.test(localEngine: 'out/android_arm');
214+
localEngineArtifacts = Artifacts.testLocalEngine(localEngine: 'out/android_arm', localEngineHost: 'out/host_release');
215215
});
216216

217217
void testUsingAndroidContext(String description, dynamic Function() testMethod) {

packages/flutter_tools/test/general.shard/build_info_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ void main() {
104104
testWithoutContext('defaultIOSArchsForEnvironment', () {
105105
expect(defaultIOSArchsForEnvironment(
106106
EnvironmentType.physical,
107-
Artifacts.test(localEngine: 'ios_debug_unopt'),
107+
Artifacts.testLocalEngine(localEngineHost: 'host_debug_unopt', localEngine: 'ios_debug_unopt'),
108108
).single, DarwinArch.arm64);
109109

110110
expect(defaultIOSArchsForEnvironment(
111111
EnvironmentType.simulator,
112-
Artifacts.test(localEngine: 'ios_debug_sim_unopt'),
112+
Artifacts.testLocalEngine(localEngineHost: 'host_debug_unopt', localEngine: 'ios_debug_sim_unopt'),
113113
).single, DarwinArch.x86_64);
114114

115115
expect(defaultIOSArchsForEnvironment(
116116
EnvironmentType.simulator,
117-
Artifacts.test(localEngine: 'ios_debug_sim_unopt_arm64'),
117+
Artifacts.testLocalEngine(localEngineHost: 'host_debug_unopt', localEngine: 'ios_debug_sim_unopt_arm64'),
118118
).single, DarwinArch.arm64);
119119

120120
expect(defaultIOSArchsForEnvironment(
@@ -128,11 +128,11 @@ void main() {
128128

129129
testWithoutContext('defaultMacOSArchsForEnvironment', () {
130130
expect(defaultMacOSArchsForEnvironment(
131-
Artifacts.test(localEngine: 'host_debug_unopt'),
131+
Artifacts.testLocalEngine(localEngineHost: 'host_debug_unopt', localEngine: 'host_debug_unopt'),
132132
).single, DarwinArch.x86_64);
133133

134134
expect(defaultMacOSArchsForEnvironment(
135-
Artifacts.test(localEngine: 'host_debug_unopt_arm64'),
135+
Artifacts.testLocalEngine(localEngineHost: 'host_debug_unopt', localEngine: 'host_debug_unopt_arm64'),
136136
).single, DarwinArch.arm64);
137137

138138
expect(defaultMacOSArchsForEnvironment(

packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ Information about project "Runner":
754754

755755
setUp(() {
756756
fs = MemoryFileSystem.test();
757-
localIosArtifacts = Artifacts.test(localEngine: 'out/ios_profile_arm64');
757+
localIosArtifacts = Artifacts.testLocalEngine(localEngine: 'out/ios_profile_arm64', localEngineHost: 'out/host_release');
758758
macOS = FakePlatform(operatingSystem: 'macos');
759759
fs.file(xcodebuild).createSync(recursive: true);
760760
});
@@ -938,7 +938,7 @@ Build settings for action build and target plugin2:
938938
}
939939

940940
testUsingOsxContext('exits when armv7 local engine is set', () async {
941-
localIosArtifacts = Artifacts.test(localEngine: 'out/ios_profile_arm');
941+
localIosArtifacts = Artifacts.testLocalEngine(localEngine: 'out/ios_profile_arm', localEngineHost: 'out/host_release');
942942
const BuildInfo buildInfo = BuildInfo.debug;
943943
final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
944944
await expectLater(() =>
@@ -971,7 +971,7 @@ Build settings for action build and target plugin2:
971971
final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync();
972972
expect(buildPhaseScriptContents.contains('export "ARCHS=arm64"'), isTrue);
973973
}, overrides: <Type, Generator>{
974-
Artifacts: () => Artifacts.test(localEngine: 'out/host_profile_arm64'),
974+
Artifacts: () => Artifacts.testLocalEngine(localEngine: 'out/host_profile_arm64', localEngineHost: 'out/host_release'),
975975
Platform: () => macOS,
976976
FileSystem: () => fs,
977977
ProcessManager: () => FakeProcessManager.any(),
@@ -998,7 +998,7 @@ Build settings for action build and target plugin2:
998998
final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync();
999999
expect(buildPhaseScriptContents.contains('export "ARCHS=x86_64"'), isTrue);
10001000
}, overrides: <Type, Generator>{
1001-
Artifacts: () => Artifacts.test(localEngine: 'out/host_profile'),
1001+
Artifacts: () => Artifacts.testLocalEngine(localEngine: 'out/host_profile', localEngineHost: 'out/host_release'),
10021002
Platform: () => macOS,
10031003
FileSystem: () => fs,
10041004
ProcessManager: () => FakeProcessManager.any(),
@@ -1083,7 +1083,7 @@ Build settings for action build and target plugin2:
10831083
final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync();
10841084
expect(buildPhaseScriptContents.contains('ARCHS=x86_64'), isTrue);
10851085
}, overrides: <Type, Generator>{
1086-
Artifacts: () => Artifacts.test(localEngine: 'out/ios_debug_sim_unopt'),
1086+
Artifacts: () => Artifacts.testLocalEngine(localEngine: 'out/ios_debug_sim_unopt', localEngineHost: 'out/host_debug_unopt'),
10871087
Platform: () => macOS,
10881088
FileSystem: () => fs,
10891089
ProcessManager: () => FakeProcessManager.any(),
@@ -1109,7 +1109,7 @@ Build settings for action build and target plugin2:
11091109
final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync();
11101110
expect(buildPhaseScriptContents.contains('ARCHS=arm64'), isTrue);
11111111
}, overrides: <Type, Generator>{
1112-
Artifacts: () => Artifacts.test(localEngine: 'out/ios_debug_sim_arm64'),
1112+
Artifacts: () => Artifacts.testLocalEngine(localEngine: 'out/ios_debug_sim_arm64', localEngineHost: 'out/host_debug_unopt'),
11131113
Platform: () => macOS,
11141114
FileSystem: () => fs,
11151115
ProcessManager: () => FakeProcessManager.any(),

0 commit comments

Comments
 (0)