-
Notifications
You must be signed in to change notification settings - Fork 32
/
build_framework.sh
executable file
·149 lines (120 loc) · 4.13 KB
/
build_framework.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env sh
# This script builds the CodeLanguagesContainer.xcframework
#
# Just call it from the root of the project
# $ ./build_framework.sh
#
# If you need debug output, set the --debug flag
# $ ./build_framework.sh --debug
#
# Created by: Lukas Pistrol on 29.10.2022
# convenience function to print a status message in green
status () {
local GREEN='\033[0;32m'
local NC='\033[0m' # No Color
echo "${GREEN}◆ $1${NC}"
}
# If --debug set -quiet flag and redirect output to /dev/null
if [ "$1" = "--debug" ]; then
QUIET_FLAG=""
QUIET_OUTPUT=/dev/stdout
else
QUIET_FLAG="-quiet"
QUIET_OUTPUT=/dev/null
fi
# Set pipefail to make sure that the script fails if any of the commands fail
set -euo pipefail
# build the framework project `CodeLanguages-Container`
status "Clean Building CodeLanguages-Container.xcodeproj..."
xcodebuild \
-project CodeLanguages-Container/CodeLanguages-Container.xcodeproj \
-scheme CodeLanguages-Container \
-destination "platform=macOS" \
-derivedDataPath DerivedData \
-configuration Release \
ARCHS="arm64 x86_64" \
ONLY_ACTIVE_ARCH=NO \
$QUIET_FLAG clean build &> $QUIET_OUTPUT
status "Build complete!"
# set path variables
PRODUCTS_PATH="$PWD/DerivedData/Build/Products/Release"
FRAMEWORK_PATH="$PRODUCTS_PATH/CodeLanguages_Container.framework"
OUTPUT_PATH="CodeLanguagesContainer.xcframework"
# remove previous generated files
rm -rf "$OUTPUT_PATH"
rm "$OUTPUT_PATH".zip
status "Removed previous generated files!"
# build the binary framework
status "Creating CodeLanguagesContainer.xcframework..."
xcodebuild \
-create-xcframework \
-framework "$FRAMEWORK_PATH" \
-output "$OUTPUT_PATH" &> $QUIET_OUTPUT
# zip the xcframework
status "Zipping CodeLanguagesContainer.xcframework..."
zip -r -q -y "$OUTPUT_PATH".zip "$OUTPUT_PATH"
# remove the unzipped xcframework
rm -rf "$OUTPUT_PATH"
status "CodeLanguagesContainer.xcframework.zip created!"
# copy language queries to package resources
# set path variables
CHECKOUTS_PATH="$PWD/DerivedData/SourcePackages/checkouts"
RESOURCES_PATH="$PWD/Sources/CodeEditLanguages/Resources"
# remove previous copied files
status "Copying language queries to package resources..."
rm -rf "$RESOURCES_PATH"
# find and copy language queries
LIST=$( echo $CHECKOUTS_PATH/tree-* )
OLD_PWD="$PWD"
for lang in $LIST ; do
# determine how many targets a given package has
cd $lang
# get package info as JSON
manifest=$(swift package dump-package)
# use jq to get the target path
targets=$(echo $manifest | jq -r '.targets[] | select(.type != "test") | .path')
# use jq to count number of targets
count=$(echo $manifest | jq '[.targets[] | select(.type != "test")] | length')
# Determine if target paths are all '.'
same=1
for target in $targets; do
if [[ $target != "." ]]; then
same=0
break
fi
done
# loop through targets
for target in $targets; do
name=${lang##*/}
# if there is only one target, use name
# otherwise use target
if [[ $count -eq 1 || ($count -ne 1 && $same -eq 1) ]]; then
mkdir -p $RESOURCES_PATH/$name
else
mkdir -p $RESOURCES_PATH/$target
fi
highlights=$( find $lang/$target -type f -name "*.scm" )
for highlight in $highlights ; do
highlight_name=${highlight##*/}
# if there is only one target, use name
# otherwise use target
if [[ $count -eq 1 || ($count -ne 1 && $same -eq 1) ]]; then
cp $highlight $RESOURCES_PATH/$name/$highlight_name
else
cp $highlight $RESOURCES_PATH/$target/$highlight_name
fi
done
# If target paths are all '.', break out of loop
if [[ $same -eq 1 || ($count -ne 1 && $same -eq 1) ]]; then
break
fi
done
done
status "Language queries copied to package resources!"
# cleanup derived derived data
cd $OLD_PWD
if [ -d "$PWD/DerivedData" ]; then
status "Cleaning up DerivedData..."
rm -rf "$PWD/DerivedData"
fi
status "Done!"