2021-07-21 13:20:14 -07:00
#!/bin/sh
set -e
set -u
set -o pipefail
function on_error {
echo " $( realpath -mq " ${ 0 } " ) : $1 : error: Unexpected failure "
}
trap 'on_error $LINENO' ERR
# This protects against multiple targets copying the same framework dependency at the same time. The solution
# was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html
RSYNC_PROTECT_TMP_FILES = ( --filter "P .*.??????" )
2023-03-01 15:00:27 -06:00
variant_for_slice( )
{
case " $1 " in
2023-05-29 20:13:24 -05:00
"AppCenterAnalytics.xcframework/ios-arm64_arm64e" )
2023-03-01 15:00:27 -06:00
echo ""
; ;
"AppCenterAnalytics.xcframework/ios-arm64_x86_64-maccatalyst" )
echo "maccatalyst"
; ;
"AppCenterAnalytics.xcframework/ios-arm64_x86_64-simulator" )
echo "simulator"
; ;
2023-05-29 20:13:24 -05:00
"AppCenterAnalytics.xcframework/macos-arm64_x86_64" )
2023-03-01 15:00:27 -06:00
echo ""
; ;
2023-05-29 20:13:24 -05:00
"AppCenterAnalytics.xcframework/tvos-arm64" )
2023-03-01 15:00:27 -06:00
echo ""
; ;
2023-05-29 20:13:24 -05:00
"AppCenterAnalytics.xcframework/tvos-arm64_x86_64-simulator" )
echo "simulator"
; ;
"AppCenter.xcframework/ios-arm64_arm64e" )
2023-03-01 15:00:27 -06:00
echo ""
; ;
"AppCenter.xcframework/ios-arm64_x86_64-maccatalyst" )
echo "maccatalyst"
; ;
"AppCenter.xcframework/ios-arm64_x86_64-simulator" )
echo "simulator"
; ;
2023-05-29 20:13:24 -05:00
"AppCenter.xcframework/macos-arm64_x86_64" )
2023-03-01 15:00:27 -06:00
echo ""
; ;
2023-05-29 20:13:24 -05:00
"AppCenter.xcframework/tvos-arm64" )
echo ""
; ;
"AppCenter.xcframework/tvos-arm64_x86_64-simulator" )
echo "simulator"
; ;
"AppCenterCrashes.xcframework/ios-arm64_arm64e" )
2023-03-01 15:00:27 -06:00
echo ""
; ;
"AppCenterCrashes.xcframework/ios-arm64_x86_64-maccatalyst" )
echo "maccatalyst"
; ;
"AppCenterCrashes.xcframework/ios-arm64_x86_64-simulator" )
echo "simulator"
; ;
2023-05-29 20:13:24 -05:00
"AppCenterCrashes.xcframework/macos-arm64_x86_64" )
echo ""
; ;
"AppCenterCrashes.xcframework/tvos-arm64" )
2023-03-01 15:00:27 -06:00
echo ""
; ;
"AppCenterCrashes.xcframework/tvos-arm64_x86_64-simulator" )
echo "simulator"
; ;
esac
}
archs_for_slice( )
{
case " $1 " in
2023-05-29 20:13:24 -05:00
"AppCenterAnalytics.xcframework/ios-arm64_arm64e" )
echo "arm64 arm64e"
; ;
"AppCenterAnalytics.xcframework/ios-arm64_x86_64-maccatalyst" )
echo "arm64 x86_64"
; ;
"AppCenterAnalytics.xcframework/ios-arm64_x86_64-simulator" )
echo "arm64 x86_64"
; ;
2023-03-01 15:00:27 -06:00
"AppCenterAnalytics.xcframework/macos-arm64_x86_64" )
echo "arm64 x86_64"
; ;
"AppCenterAnalytics.xcframework/tvos-arm64" )
echo "arm64"
; ;
"AppCenterAnalytics.xcframework/tvos-arm64_x86_64-simulator" )
echo "arm64 x86_64"
; ;
2023-05-29 20:13:24 -05:00
"AppCenter.xcframework/ios-arm64_arm64e" )
echo "arm64 arm64e"
2023-03-01 15:00:27 -06:00
; ;
2023-05-29 20:13:24 -05:00
"AppCenter.xcframework/ios-arm64_x86_64-maccatalyst" )
2023-03-01 15:00:27 -06:00
echo "arm64 x86_64"
; ;
2023-05-29 20:13:24 -05:00
"AppCenter.xcframework/ios-arm64_x86_64-simulator" )
2023-03-01 15:00:27 -06:00
echo "arm64 x86_64"
; ;
"AppCenter.xcframework/macos-arm64_x86_64" )
echo "arm64 x86_64"
; ;
"AppCenter.xcframework/tvos-arm64" )
echo "arm64"
; ;
2023-05-29 20:13:24 -05:00
"AppCenter.xcframework/tvos-arm64_x86_64-simulator" )
2023-03-01 15:00:27 -06:00
echo "arm64 x86_64"
; ;
2023-05-29 20:13:24 -05:00
"AppCenterCrashes.xcframework/ios-arm64_arm64e" )
2023-03-01 15:00:27 -06:00
echo "arm64 arm64e"
; ;
2023-05-29 20:13:24 -05:00
"AppCenterCrashes.xcframework/ios-arm64_x86_64-maccatalyst" )
echo "arm64 x86_64"
; ;
"AppCenterCrashes.xcframework/ios-arm64_x86_64-simulator" )
2023-03-01 15:00:27 -06:00
echo "arm64 x86_64"
; ;
"AppCenterCrashes.xcframework/macos-arm64_x86_64" )
echo "arm64 x86_64"
; ;
"AppCenterCrashes.xcframework/tvos-arm64" )
echo "arm64"
; ;
"AppCenterCrashes.xcframework/tvos-arm64_x86_64-simulator" )
echo "arm64 x86_64"
; ;
esac
}
2021-07-21 13:20:14 -07:00
copy_dir( )
{
local source = " $1 "
local destination = " $2 "
# Use filter instead of exclude so missing patterns don't throw errors.
2023-03-01 15:00:27 -06:00
echo "rsync --delete -av " ${ RSYNC_PROTECT_TMP_FILES [@] } " --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" \" ${ source } *\" \" ${ destination } \" "
rsync --delete -av " ${ RSYNC_PROTECT_TMP_FILES [@] } " --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" " ${ source } " /* " ${ destination } "
2021-07-21 13:20:14 -07:00
}
SELECT_SLICE_RETVAL = ""
select_slice( ) {
2023-03-01 15:00:27 -06:00
local xcframework_name = " $1 "
xcframework_name = " ${ xcframework_name ##*/ } "
local paths = ( " ${ @ : 2 } " )
2021-07-21 13:20:14 -07:00
# Locate the correct slice of the .xcframework for the current architectures
local target_path = ""
# Split archs on space so we can find a slice that has all the needed archs
local target_archs = $( echo $ARCHS | tr " " "\n" )
local target_variant = ""
if [ [ " $PLATFORM_NAME " = = *"simulator" ] ] ; then
target_variant = "simulator"
fi
if [ [ ! -z ${ EFFECTIVE_PLATFORM_NAME +x } && " $EFFECTIVE_PLATFORM_NAME " = = *"maccatalyst" ] ] ; then
target_variant = "maccatalyst"
fi
for i in ${ !paths[@] } ; do
local matched_all_archs = "1"
2023-03-01 15:00:27 -06:00
local slice_archs = " $( archs_for_slice " ${ xcframework_name } / ${ paths [ $i ] } " ) "
local slice_variant = " $( variant_for_slice " ${ xcframework_name } / ${ paths [ $i ] } " ) "
for target_arch in $target_archs ; do
if ! [ [ " ${ slice_variant } " = = " $target_variant " ] ] ; then
2021-07-21 13:20:14 -07:00
matched_all_archs = "0"
break
fi
2023-03-01 15:00:27 -06:00
if ! echo " ${ slice_archs } " | tr " " "\n" | grep -F -q -x " $target_arch " ; then
2021-07-21 13:20:14 -07:00
matched_all_archs = "0"
break
fi
done
if [ [ " $matched_all_archs " = = "1" ] ] ; then
# Found a matching slice
echo " Selected xcframework slice ${ paths [ $i ] } "
SELECT_SLICE_RETVAL = ${ paths [ $i ] }
break
fi
done
}
install_xcframework( ) {
local basepath = " $1 "
local name = " $2 "
local package_type = " $3 "
2023-03-01 15:00:27 -06:00
local paths = ( " ${ @ : 4 } " )
2021-07-21 13:20:14 -07:00
# Locate the correct slice of the .xcframework for the current architectures
2023-03-01 15:00:27 -06:00
select_slice " ${ basepath } " " ${ paths [@] } "
2021-07-21 13:20:14 -07:00
local target_path = " $SELECT_SLICE_RETVAL "
if [ [ -z " $target_path " ] ] ; then
2023-03-01 15:00:27 -06:00
echo " warning: [CP] $( basename ${ basepath } ) : Unable to find matching slice in ' ${ paths [@] } ' for the current build architectures ( $ARCHS ) and platform ( ${ EFFECTIVE_PLATFORM_NAME - ${ PLATFORM_NAME } } ). "
2021-07-21 13:20:14 -07:00
return
fi
local source = " $basepath / $target_path "
local destination = " ${ PODS_XCFRAMEWORKS_BUILD_DIR } / ${ name } "
if [ ! -d " $destination " ] ; then
mkdir -p " $destination "
fi
copy_dir " $source / " " $destination "
echo " Copied $source to $destination "
}
2023-05-29 20:13:24 -05:00
install_xcframework " ${ PODS_ROOT } /AppCenter/AppCenter-SDK-Apple/AppCenterAnalytics.xcframework " "AppCenter/Analytics" "framework" "ios-arm64_arm64e" "ios-arm64_x86_64-maccatalyst" "ios-arm64_x86_64-simulator"
install_xcframework " ${ PODS_ROOT } /AppCenter/AppCenter-SDK-Apple/AppCenter.xcframework " "AppCenter/Core" "framework" "ios-arm64_arm64e" "ios-arm64_x86_64-maccatalyst" "ios-arm64_x86_64-simulator"
install_xcframework " ${ PODS_ROOT } /AppCenter/AppCenter-SDK-Apple/AppCenterCrashes.xcframework " "AppCenter/Crashes" "framework" "ios-arm64_arm64e" "ios-arm64_x86_64-maccatalyst" "ios-arm64_x86_64-simulator"
2021-07-21 13:20:14 -07:00