#!/usr/bin/env bash set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" package_dir="${repo_root}/apps/ios/TeleTuiIOS" if [[ -z "${DEVELOPER_DIR:-}" && -d /Applications/Xcode.app/Contents/Developer ]]; then export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer fi configuration="${IOS_CONFIGURATION:-Debug}" derived_data="${IOS_DERIVED_DATA:-/private/tmp/tele-tui-ios-derived-data}" destination="${IOS_DESTINATION:-generic/platform=iOS Simulator}" bundle_id="${IOS_BUNDLE_ID:-dev.teletui.TeleTuiIOSApp}" pushd "${package_dir}" >/dev/null xcodebuild \ -scheme TeleTuiIOSApp \ -destination "${destination}" \ -configuration "${configuration}" \ -derivedDataPath "${derived_data}" \ build popd >/dev/null product_dir="${derived_data}/Build/Products/${configuration}-iphonesimulator" binary_path="${product_dir}/TeleTuiIOSApp" app_path="${product_dir}/TeleTuiIOSApp.app" if [[ ! -x "${binary_path}" ]]; then printf 'Expected simulator executable was not produced: %s\n' "${binary_path}" >&2 exit 1 fi rm -rf "${app_path}" mkdir -p "${app_path}" cp "${binary_path}" "${app_path}/TeleTuiIOSApp" cp "${package_dir}/Resources/PrivacyInfo.xcprivacy" "${app_path}/PrivacyInfo.xcprivacy" printf 'APPL????' > "${app_path}/PkgInfo" cat > "${app_path}/Info.plist" < CFBundleDevelopmentRegion en CFBundleDisplayName TeleTui CFBundleExecutable TeleTuiIOSApp CFBundleIdentifier ${bundle_id} CFBundleInfoDictionaryVersion 6.0 CFBundleName TeleTuiIOSApp CFBundlePackageType APPL CFBundleShortVersionString 0.1.0 CFBundleVersion 1 LSRequiresIPhoneOS UIApplicationSupportsIndirectInputEvents UILaunchScreen UIDeviceFamily 1 2 UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight PLIST tdjson_path="${product_dir}/libtdjson.1.8.29.dylib" if [[ -f "${tdjson_path}" ]]; then mkdir -p "${app_path}/Frameworks" cp "${tdjson_path}" "${app_path}/Frameworks/libtdjson.dylib" codesign --remove-signature "${app_path}/TeleTuiIOSApp" >/dev/null 2>&1 || true if ! otool -l "${app_path}/TeleTuiIOSApp" | grep -q '@executable_path/Frameworks'; then install_name_tool -add_rpath '@executable_path/Frameworks' "${app_path}/TeleTuiIOSApp" fi codesign --force --sign - --timestamp=none "${app_path}/Frameworks/libtdjson.dylib" >/dev/null fi codesign --force --sign - --timestamp=none "${app_path}/TeleTuiIOSApp" >/dev/null codesign --force --sign - --timestamp=none "${app_path}" >/dev/null printf 'Packaged simulator app: %s\n' "${app_path}"