1 |
efrain |
1 |
#!/bin/sh
|
|
|
2 |
set -e
|
|
|
3 |
set -u
|
|
|
4 |
set -o pipefail
|
|
|
5 |
|
|
|
6 |
function on_error {
|
|
|
7 |
echo "$(realpath -mq "${0}"):$1: error: Unexpected failure"
|
|
|
8 |
}
|
|
|
9 |
trap 'on_error $LINENO' ERR
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
# This protects against multiple targets copying the same framework dependency at the same time. The solution
|
|
|
13 |
# was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html
|
|
|
14 |
RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????")
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
copy_dir()
|
|
|
18 |
{
|
|
|
19 |
local source="$1"
|
|
|
20 |
local destination="$2"
|
|
|
21 |
|
|
|
22 |
# Use filter instead of exclude so missing patterns don't throw errors.
|
|
|
23 |
echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" \"${source}*\" \"${destination}\""
|
|
|
24 |
rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" "${source}"/* "${destination}"
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
SELECT_SLICE_RETVAL=""
|
|
|
28 |
|
|
|
29 |
select_slice() {
|
|
|
30 |
local paths=("$@")
|
|
|
31 |
# Locate the correct slice of the .xcframework for the current architectures
|
|
|
32 |
local target_path=""
|
|
|
33 |
|
|
|
34 |
# Split archs on space so we can find a slice that has all the needed archs
|
|
|
35 |
local target_archs=$(echo $ARCHS | tr " " "\n")
|
|
|
36 |
|
|
|
37 |
local target_variant=""
|
|
|
38 |
if [[ "$PLATFORM_NAME" == *"simulator" ]]; then
|
|
|
39 |
target_variant="simulator"
|
|
|
40 |
fi
|
|
|
41 |
if [[ ! -z ${EFFECTIVE_PLATFORM_NAME+x} && "$EFFECTIVE_PLATFORM_NAME" == *"maccatalyst" ]]; then
|
|
|
42 |
target_variant="maccatalyst"
|
|
|
43 |
fi
|
|
|
44 |
for i in ${!paths[@]}; do
|
|
|
45 |
local matched_all_archs="1"
|
|
|
46 |
for target_arch in $target_archs
|
|
|
47 |
do
|
|
|
48 |
if ! [[ "${paths[$i]}" == *"$target_variant"* ]]; then
|
|
|
49 |
matched_all_archs="0"
|
|
|
50 |
break
|
|
|
51 |
fi
|
|
|
52 |
|
|
|
53 |
# Verifies that the path contains the variant string (simulator or maccatalyst) if the variant is set.
|
|
|
54 |
if [[ -z "$target_variant" && ("${paths[$i]}" == *"simulator"* || "${paths[$i]}" == *"maccatalyst"*) ]]; then
|
|
|
55 |
matched_all_archs="0"
|
|
|
56 |
break
|
|
|
57 |
fi
|
|
|
58 |
|
|
|
59 |
# This regex matches all possible variants of the arch in the folder name:
|
|
|
60 |
# Let's say the folder name is: ios-armv7_armv7s_arm64_arm64e/CoconutLib.framework
|
|
|
61 |
# We match the following: -armv7_, _armv7s_, _arm64_ and _arm64e/.
|
|
|
62 |
# If we have a specific variant: ios-i386_x86_64-simulator/CoconutLib.framework
|
|
|
63 |
# We match the following: -i386_ and _x86_64-
|
|
|
64 |
# When the .xcframework wraps a static library, the folder name does not include
|
|
|
65 |
# any .framework. In that case, the folder name can be: ios-arm64_armv7
|
|
|
66 |
# We also match _armv7$ to handle that case.
|
|
|
67 |
local target_arch_regex="[_\-]${target_arch}([\/_\-]|$)"
|
|
|
68 |
if ! [[ "${paths[$i]}" =~ $target_arch_regex ]]; then
|
|
|
69 |
matched_all_archs="0"
|
|
|
70 |
break
|
|
|
71 |
fi
|
|
|
72 |
done
|
|
|
73 |
|
|
|
74 |
if [[ "$matched_all_archs" == "1" ]]; then
|
|
|
75 |
# Found a matching slice
|
|
|
76 |
echo "Selected xcframework slice ${paths[$i]}"
|
|
|
77 |
SELECT_SLICE_RETVAL=${paths[$i]}
|
|
|
78 |
break
|
|
|
79 |
fi
|
|
|
80 |
done
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
install_xcframework() {
|
|
|
84 |
local basepath="$1"
|
|
|
85 |
local name="$2"
|
|
|
86 |
local package_type="$3"
|
|
|
87 |
local paths=("${@:4}")
|
|
|
88 |
|
|
|
89 |
# Locate the correct slice of the .xcframework for the current architectures
|
|
|
90 |
select_slice "${paths[@]}"
|
|
|
91 |
local target_path="$SELECT_SLICE_RETVAL"
|
|
|
92 |
if [[ -z "$target_path" ]]; then
|
|
|
93 |
echo "warning: [CP] Unable to find matching .xcframework slice in '${paths[@]}' for the current build architectures ($ARCHS)."
|
|
|
94 |
return
|
|
|
95 |
fi
|
|
|
96 |
local source="$basepath/$target_path"
|
|
|
97 |
|
|
|
98 |
local destination="${PODS_XCFRAMEWORKS_BUILD_DIR}/${name}"
|
|
|
99 |
|
|
|
100 |
if [ ! -d "$destination" ]; then
|
|
|
101 |
mkdir -p "$destination"
|
|
|
102 |
fi
|
|
|
103 |
|
|
|
104 |
copy_dir "$source/" "$destination"
|
|
|
105 |
echo "Copied $source to $destination"
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
install_xcframework "${PODS_ROOT}/FirebaseAnalytics/Frameworks/FirebaseAnalytics.xcframework" "FirebaseAnalytics/AdIdSupport" "framework" "ios-arm64_i386_x86_64-simulator" "ios-arm64_armv7" "ios-arm64_x86_64-maccatalyst"
|
|
|
109 |
|