Move iOS framework thinning into the tool (#76665)

This commit is contained in:
Jenn Magder
2021-02-24 18:02:43 -08:00
committed by GitHub
parent 9df362a73f
commit 5bc100da31
5 changed files with 364 additions and 67 deletions

View File

@@ -204,73 +204,17 @@ is set to release or run \"flutter build ios --release\", then re-run Archive fr
return 0
}
# Returns the CFBundleExecutable for the specified framework directory.
GetFrameworkExecutablePath() {
local framework_dir="$1"
local plist_path="${framework_dir}/Info.plist"
local executable="$(defaults read "${plist_path}" CFBundleExecutable)"
echo "${framework_dir}/${executable}"
}
# Destructively thins the specified executable file to include only the
# specified architectures.
LipoExecutable() {
local executable="$1"
shift
# Split $@ into an array.
read -r -a archs <<< "$@"
# Extract architecture-specific framework executables.
local all_executables=()
for arch in "${archs[@]}"; do
local output="${executable}_${arch}"
local lipo_info="$(lipo -info "${executable}")"
if [[ "${lipo_info}" == "Non-fat file:"* ]]; then
if [[ "${lipo_info}" != *"${arch}" ]]; then
echo "Non-fat binary ${executable} is not ${arch}. Running lipo -info:"
echo "${lipo_info}"
exit 1
fi
else
if lipo -output "${output}" -extract "${arch}" "${executable}"; then
all_executables+=("${output}")
else
echo "Failed to extract ${arch} for ${executable}. Running lipo -info:"
RunCommand lipo -info "${executable}"
exit 1
fi
fi
done
# Generate a merged binary from the architecture-specific executables.
# Skip this step for non-fat executables.
if [[ ${#all_executables[@]} > 0 ]]; then
local merged="${executable}_merged"
RunCommand lipo -output "${merged}" -create "${all_executables[@]}"
RunCommand cp -f -- "${merged}" "${executable}" > /dev/null
RunCommand rm -f -- "${merged}" "${all_executables[@]}"
fi
}
# Destructively thins the specified framework to include only the specified
# Destructively thins the Flutter and App frameworks to include only the specified
# architectures.
ThinFramework() {
local framework_dir="$1"
shift
local executable="$(GetFrameworkExecutablePath "${framework_dir}")"
LipoExecutable "${executable}" "$@"
}
ThinAppFrameworks() {
local xcode_frameworks_dir="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
[[ -d "${xcode_frameworks_dir}" ]] || return 0
find "${xcode_frameworks_dir}" -type d -name "*.framework" | while read framework_dir; do
ThinFramework "$framework_dir" "$ARCHS"
done
RunCommand "${FLUTTER_ROOT}/bin/flutter" \
${verbose_flag} \
assemble \
--no-version-check \
--output="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" \
-dTargetPlatform=ios \
-dIosArchs="${ARCHS}" \
"thin_ios_application_frameworks"
}
# Adds the App.framework as an embedded binary and the flutter_assets as