Fix local engine use in macOS plugins (#140222)
Currently podhelper.rb will always point plugin builds at the cached engine artifacts, even when using `--local-engine`. In most cases this is fine, since when the final build actually runs it will be using the engine bundled into the app build, which will be the correct local engine build. When trying to test a local engine build with API additions against a local plugin modified to use those additions to ensure that they are working as expected, however, compilation will fail, because the new APIs won't be present in the plugin build. This fixes that for macOS, and adds a TODO for iOS (which is more complicated to fix due to the host vs target build distinction). macOS portion of https://github.com/flutter/flutter/issues/132228
This commit is contained in:
@@ -84,6 +84,12 @@ class PluginTest {
|
||||
section('Test app');
|
||||
await app.runFlutterTest();
|
||||
}
|
||||
// Validate local engine handling. Currently only implemented for macOS.
|
||||
if (!dartOnlyPlugin) {
|
||||
section('Validate local engine configuration');
|
||||
final String fakeEngineSourcePath = path.join(tempDir.path, 'engine');
|
||||
await _testLocalEngineConfiguration(app, fakeEngineSourcePath);
|
||||
}
|
||||
} finally {
|
||||
await plugin.delete();
|
||||
await app.delete();
|
||||
@@ -95,6 +101,22 @@ class PluginTest {
|
||||
rmTree(tempDir);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _testLocalEngineConfiguration(_FlutterProject app, String fakeEngineSourcePath) async {
|
||||
// The tool requires that a directory that looks like an engine build
|
||||
// actually exists when passing --local-engine, so create a fake skeleton.
|
||||
final Directory buildDir = Directory(path.join(fakeEngineSourcePath, 'out', 'foo'));
|
||||
buildDir.createSync(recursive: true);
|
||||
// Currently this test is only implemented for macOS; it can be extended to
|
||||
// others as needed.
|
||||
if (buildTarget == 'macos') {
|
||||
// Clean before regenerating the config to ensure that the pod steps run.
|
||||
await inDirectory(Directory(app.rootPath), () async {
|
||||
await evalFlutter('clean');
|
||||
});
|
||||
await app.build(buildTarget, configOnly: true, localEngine: buildDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _FlutterProject {
|
||||
@@ -369,13 +391,28 @@ s.dependency 'AppAuth', '1.6.0'
|
||||
podspec.writeAsStringSync(podspecContent, flush: true);
|
||||
}
|
||||
|
||||
Future<void> build(String target, {bool validateNativeBuildProject = true}) async {
|
||||
Future<void> build(
|
||||
String target, {
|
||||
bool validateNativeBuildProject = true,
|
||||
bool configOnly = false,
|
||||
Directory? localEngine,
|
||||
}) async {
|
||||
await inDirectory(Directory(rootPath), () async {
|
||||
final String buildOutput = await evalFlutter('build', options: <String>[
|
||||
target,
|
||||
'-v',
|
||||
if (target == 'ios')
|
||||
'--no-codesign',
|
||||
if (configOnly)
|
||||
'--config-only',
|
||||
if (localEngine != null)
|
||||
// The engine directory is of the form <fake-source-path>/out/<fakename>,
|
||||
// which has to be broken up into the component flags.
|
||||
...<String>[
|
||||
'--local-engine-src-path=${localEngine.parent.parent.path}',
|
||||
'--local-engine=${path.basename(localEngine.path)}',
|
||||
'--local-engine-host=${path.basename(localEngine.path)}',
|
||||
]
|
||||
]);
|
||||
|
||||
if (target == 'ios' || target == 'macos') {
|
||||
@@ -422,6 +459,13 @@ s.dependency 'AppAuth', '1.6.0'
|
||||
throw TaskResult.failure('Transitive dependency build setting MACOSX_DEPLOYMENT_TARGET=10.9 not removed');
|
||||
}
|
||||
}
|
||||
|
||||
if (localEngine != null) {
|
||||
final RegExp localEngineSearchPath = RegExp('FRAMEWORK_SEARCH_PATHS\\s*=[^;]*${localEngine.path}');
|
||||
if (!localEngineSearchPath.hasMatch(podsProjectContent)) {
|
||||
throw TaskResult.failure('FRAMEWORK_SEARCH_PATHS does not contain the --local-engine path');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user