Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions build_framework.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
#!/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 \
-quiet clean build
$QUIET_FLAG clean build &> $QUIET_OUTPUT
status "Build complete!"

# set path variables
PRODUCTS_PATH="$PWD/DerivedData/Build/Products/Release"
Expand All @@ -19,39 +48,45 @@ 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"
-output "$OUTPUT_PATH" &> $QUIET_OUTPUT

# zip the xcframework
status "Zipping CodeLanguagesContainer.xcframework..."
zip -r -q "$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-* )

for lang in $LIST ; do
name=${lang##*/}
echo "Copying queries: $name"
mkdir -p $RESOURCES_PATH/$name
highlights=$( find $lang -type f -name "*.scm" )
for highlight in $highlights ; do
highlight_name=${highlight##*/}
cp $highlight $RESOURCES_PATH/$name/$highlight_name
done
done
status "Language queries copied to package resources!"

echo "Done!"
status "Done!"