mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Refactor local engine logic (#27765)
* Refactor for iOS. * For android_xxx_unopt_arm64&ios_xxx_unopt_arm, remove the _arm64/_arm suffix. dart generated in host_xxx_unopt/host_xxx has an arch of x86_64 which supports arm64/arm. * Remove suffixes for various archs.
This commit is contained in:
parent
b6996ef326
commit
f9a6090082
|
@ -96,10 +96,15 @@ BuildApp() {
|
|||
|
||||
RunCommand rm -rf -- "${derived_dir}/App.framework"
|
||||
|
||||
local flutter_engine_flag=""
|
||||
local local_engine_flag=""
|
||||
local flutter_framework="${framework_path}/Flutter.framework"
|
||||
local flutter_podspec="${framework_path}/Flutter.podspec"
|
||||
|
||||
if [[ -n "$FLUTTER_ENGINE" ]]; then
|
||||
flutter_engine_flag="--local-engine-src-path=${FLUTTER_ENGINE}"
|
||||
fi
|
||||
|
||||
if [[ -n "$LOCAL_ENGINE" ]]; then
|
||||
if [[ $(echo "$LOCAL_ENGINE" | tr "[:upper:]" "[:lower:]") != *"$build_mode"* ]]; then
|
||||
EchoError "========================================================================"
|
||||
|
@ -114,8 +119,8 @@ BuildApp() {
|
|||
exit -1
|
||||
fi
|
||||
local_engine_flag="--local-engine=${LOCAL_ENGINE}"
|
||||
flutter_framework="${LOCAL_ENGINE}/Flutter.framework"
|
||||
flutter_podspec="${LOCAL_ENGINE}/Flutter.podspec"
|
||||
flutter_framework="${FLUTTER_ENGINE}/out/${LOCAL_ENGINE}/Flutter.framework"
|
||||
flutter_podspec="${FLUTTER_ENGINE}/out/${LOCAL_ENGINE}/Flutter.podspec"
|
||||
fi
|
||||
|
||||
if [[ -e "${project_path}/.ios" ]]; then
|
||||
|
@ -168,6 +173,7 @@ BuildApp() {
|
|||
--target="${target_path}" \
|
||||
--${build_mode} \
|
||||
--ios-arch="${archs}" \
|
||||
${flutter_engine_flag} \
|
||||
${local_engine_flag} \
|
||||
${track_widget_creation_flag}
|
||||
|
||||
|
@ -244,6 +250,7 @@ BuildApp() {
|
|||
--depfile="${build_dir}/snapshot_blob.bin.d" \
|
||||
--asset-dir="${derived_dir}/App.framework/flutter_assets" \
|
||||
${precompilation_flag} \
|
||||
${flutter_engine_flag} \
|
||||
${local_engine_flag} \
|
||||
${track_widget_creation_flag}
|
||||
|
||||
|
|
|
@ -243,8 +243,8 @@ class UserMessages {
|
|||
'Warning: this bug report contains local paths, device identifiers, and log snippets.';
|
||||
String get runnerNoRecordTo => 'record-to location not specified';
|
||||
String get runnerNoReplayFrom => 'replay-from location not specified';
|
||||
String runnerNoEngineBuildDir(String enginePackageName, String engineEnvVar) =>
|
||||
'Unable to detect local Flutter engine build directory.\n'
|
||||
String runnerNoEngineSrcDir(String enginePackageName, String engineEnvVar) =>
|
||||
'Unable to detect local Flutter engine src directory.\n'
|
||||
'Either specify a dependency_override for the $enginePackageName package in your pubspec.yaml and '
|
||||
'ensure --package-root is set if necessary, or set the \$$engineEnvVar environment variable, or '
|
||||
'use --local-engine-src-path to specify the path to the root of your flutter/engine repository.';
|
||||
|
|
|
@ -74,7 +74,9 @@ Future<void> updateGeneratedXcodeProperties({
|
|||
|
||||
if (artifacts is LocalEngineArtifacts) {
|
||||
final LocalEngineArtifacts localEngineArtifacts = artifacts;
|
||||
localsBuffer.writeln('LOCAL_ENGINE=${localEngineArtifacts.engineOutPath}');
|
||||
final String engineOutPath = localEngineArtifacts.engineOutPath;
|
||||
localsBuffer.writeln('FLUTTER_ENGINE=${fs.path.dirname(fs.path.dirname(engineOutPath))}');
|
||||
localsBuffer.writeln('LOCAL_ENGINE=${fs.path.basename(engineOutPath)}');
|
||||
|
||||
// Tell Xcode not to build universal binaries for local engines, which are
|
||||
// single-architecture.
|
||||
|
@ -82,7 +84,7 @@ Future<void> updateGeneratedXcodeProperties({
|
|||
// NOTE: this assumes that local engine binary paths are consistent with
|
||||
// the conventions uses in the engine: 32-bit iOS engines are built to
|
||||
// paths ending in _arm, 64-bit builds are not.
|
||||
final String arch = localEngineArtifacts.engineOutPath.endsWith('_arm') ? 'armv7' : 'arm64';
|
||||
final String arch = engineOutPath.endsWith('_arm') ? 'armv7' : 'arm64';
|
||||
localsBuffer.writeln('ARCHS=$arch');
|
||||
}
|
||||
|
||||
|
|
|
@ -409,25 +409,28 @@ class FlutterCommandRunner extends CommandRunner<void> {
|
|||
|
||||
if (engineSourcePath == null && globalResults['local-engine'] != null) {
|
||||
try {
|
||||
final Uri engineUri = PackageMap(PackageMap.globalPackagesPath).map[kFlutterEnginePackageName];
|
||||
if (engineUri != null) {
|
||||
engineSourcePath = fs.path.dirname(fs.path.dirname(fs.path.dirname(fs.path.dirname(engineUri.path))));
|
||||
final bool dirExists = fs.isDirectorySync(fs.path.join(engineSourcePath, 'out'));
|
||||
if (engineSourcePath == '/' || engineSourcePath.isEmpty || !dirExists)
|
||||
Uri engineUri = PackageMap(PackageMap.globalPackagesPath).map[kFlutterEnginePackageName];
|
||||
// Skip if sky_engine is the self-contained one.
|
||||
if (fs.path.join(Cache.flutterRoot, 'bin', 'cache', 'pkg', kFlutterEnginePackageName, 'lib') + fs.path.separator == engineUri?.path) {
|
||||
engineUri = null;
|
||||
}
|
||||
// If sky_engine is specified and the engineSourcePath not set, try to determine the engineSourcePath by sky_engine setting.
|
||||
// A typical engineUri looks like: file://flutter-engine-local-path/src/out/host_debug_unopt/gen/dart-pkg/sky_engine/lib/
|
||||
if (engineUri?.path != null) {
|
||||
engineSourcePath = fs.directory(engineUri.path)?.parent?.parent?.parent?.parent?.parent?.parent?.path;
|
||||
if (engineSourcePath != null && (engineSourcePath == fs.path.dirname(engineSourcePath) || engineSourcePath.isEmpty)) {
|
||||
engineSourcePath = null;
|
||||
throwToolExit(userMessages.runnerNoEngineSrcDir(kFlutterEnginePackageName, kFlutterEngineEnvironmentVariableName),
|
||||
exitCode: 2);
|
||||
}
|
||||
}
|
||||
} on FileSystemException {
|
||||
engineSourcePath = null;
|
||||
} on FormatException {
|
||||
engineSourcePath = null;
|
||||
}
|
||||
|
||||
engineSourcePath ??= _tryEnginePath(fs.path.join(Cache.flutterRoot, '../engine/src'));
|
||||
|
||||
if (engineSourcePath == null) {
|
||||
throwToolExit(userMessages.runnerNoEngineBuildDir(kFlutterEnginePackageName, kFlutterEngineEnvironmentVariableName),
|
||||
exitCode: 2);
|
||||
}
|
||||
// If engineSourcePath is still not set, try to determine it by flutter root.
|
||||
engineSourcePath ??= _tryEnginePath(fs.path.join(fs.directory(Cache.flutterRoot).parent.path, 'engine', 'src'));
|
||||
}
|
||||
|
||||
if (engineSourcePath != null && _tryEnginePath(engineSourcePath) == null) {
|
||||
|
@ -438,6 +441,19 @@ class FlutterCommandRunner extends CommandRunner<void> {
|
|||
return engineSourcePath;
|
||||
}
|
||||
|
||||
String _getHostEngineBasename(String localEngineBasename) {
|
||||
// Determine the host engine directory associated with the local engine:
|
||||
// Strip '_sim_' since there are no host simulator builds.
|
||||
String tmpBasename = localEngineBasename.replaceFirst('_sim_', '_');
|
||||
tmpBasename = tmpBasename.substring(tmpBasename.indexOf('_') + 1);
|
||||
// Strip suffix for various archs.
|
||||
final List<String> suffixes = <String>['_arm', '_arm64', '_x86', '_x64'];
|
||||
for (String suffix in suffixes) {
|
||||
tmpBasename = tmpBasename.replaceFirst(RegExp('$suffix\$'), '');
|
||||
}
|
||||
return 'host_' + tmpBasename;
|
||||
}
|
||||
|
||||
EngineBuildPaths _findEngineBuildPath(ArgResults globalResults, String enginePath) {
|
||||
String localEngine;
|
||||
if (globalResults['local-engine'] != null) {
|
||||
|
@ -451,11 +467,8 @@ class FlutterCommandRunner extends CommandRunner<void> {
|
|||
throwToolExit(userMessages.runnerNoEngineBuild(engineBuildPath), exitCode: 2);
|
||||
}
|
||||
|
||||
// Determine the host engine directory associated with the local engine:
|
||||
// * strip '_sim_' since there are no host simulator builds.
|
||||
// * replace the target platform with host.
|
||||
final String basename = fs.path.basename(engineBuildPath);
|
||||
final String hostBasename = 'host_' + basename.replaceFirst('_sim_', '_').substring(basename.indexOf('_') + 1);
|
||||
final String hostBasename = _getHostEngineBasename(basename);
|
||||
final String engineHostBuildPath = fs.path.normalize(fs.path.join(fs.path.dirname(engineBuildPath), hostBasename));
|
||||
if (!fs.isDirectorySync(engineHostBuildPath)) {
|
||||
throwToolExit(userMessages.runnerNoEngineBuild(engineHostBuildPath), exitCode: 2);
|
||||
|
|
|
@ -21,6 +21,7 @@ import 'utils.dart';
|
|||
|
||||
const String _kFlutterRoot = '/flutter/flutter';
|
||||
const String _kEngineRoot = '/flutter/engine';
|
||||
const String _kArbitraryEngineRoot = '/arbitrary/engine';
|
||||
const String _kProjectRoot = '/project';
|
||||
const String _kDotPackages = '.packages';
|
||||
|
||||
|
@ -68,8 +69,26 @@ void main() {
|
|||
Platform: () => platform,
|
||||
}, initializeFlutterRoot: false);
|
||||
|
||||
testUsingContext('works if --local-engine is specified', () async {
|
||||
fs.file(_kDotPackages).writeAsStringSync('sky_engine:file://$_kFlutterRoot/bin/cache/pkg/sky_engine/lib/');
|
||||
testUsingContext('works if --local-engine is specified and --local-engine-src-path is determined by sky_engine', () async {
|
||||
fs.directory('$_kArbitraryEngineRoot/src/out/ios_debug/gen/dart-pkg/sky_engine/lib/').createSync(recursive: true);
|
||||
fs.directory('$_kArbitraryEngineRoot/src/out/host_debug').createSync(recursive: true);
|
||||
fs.file(_kDotPackages).writeAsStringSync('sky_engine:file://$_kArbitraryEngineRoot/src/out/ios_debug/gen/dart-pkg/sky_engine/lib/');
|
||||
await runner.run(<String>['dummy', '--local-engine=ios_debug']);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
Platform: () => platform,
|
||||
}, initializeFlutterRoot: false);
|
||||
|
||||
testUsingContext('works if --local-engine is specified and --local-engine-src-path is specified', () async {
|
||||
fs.directory('$_kArbitraryEngineRoot/src/out/ios_debug').createSync(recursive: true);
|
||||
fs.directory('$_kArbitraryEngineRoot/src/out/host_debug').createSync(recursive: true);
|
||||
await runner.run(<String>['dummy', '--local-engine-src-path=$_kArbitraryEngineRoot/src', '--local-engine=ios_debug']);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
Platform: () => platform,
|
||||
}, initializeFlutterRoot: false);
|
||||
|
||||
testUsingContext('works if --local-engine is specified and --local-engine-src-path is determined by flutter root', () async {
|
||||
fs.directory('$_kEngineRoot/src/out/ios_debug').createSync(recursive: true);
|
||||
fs.directory('$_kEngineRoot/src/out/host_debug').createSync(recursive: true);
|
||||
await runner.run(<String>['dummy', '--local-engine=ios_debug']);
|
||||
|
|
Loading…
Reference in a new issue