-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_build.command
More file actions
executable file
·108 lines (93 loc) · 3.93 KB
/
_build.command
File metadata and controls
executable file
·108 lines (93 loc) · 3.93 KB
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
#!/bin/bash
set -e
# macOS does not have realpath and readlink does not have -f option, so do this instead:
MY_DIR=$( cd "$(dirname "$0")" ; pwd -P )
cd "$MY_DIR"
if [ "${1:-}" == "--debug" ]; then
debug=true
shift
else
debug=false
fi
if [ "$TERM" == "" ] || [ "$TERM" == "dumb" ] ; then
SMSO=""
RMSO=""
BEL=""
GREEN=""
RMGREEN=""
GRAY=""
RMGRAY=""
RED=""
RMRED=""
else
SMSO="$(tput smso)"
RMSO="$(tput rmso)"
BEL="$(tput bel)"
GREEN="$(tput smso; tput setaf 2)"
RMGREEN="$(tput rmso; tput sgr0)"
GRAY="$(tput smso; tput setaf 7)"
RMGRAY="$(tput rmso; tput sgr0)"
RED="$(tput setaf 9; tput smso)"
RMRED="$(tput rmso; tput sgr0)"
fi
echo ""
echo "$SMSO Build $RMSO"
echo ""
# Matches the default SwiftPM build directory
BUILD_DIR="${MY_DIR}/.build"
# Directory where Sourcery binary (for testing in Swift repo) and MacOS application archive (for releases) are stored
OUTPUT_DIR="${MY_DIR}/bin"
if [ "$debug" != true ] ; then
echo "Cleaning build artifacts"
swift package clean
echo "Build using swift build in release configuration"
# Note: not using the undocumented --arch option
swift build -c release --triple arm64-apple-macosx --build-path $BUILD_DIR
swift build -c release --triple x86_64-apple-macosx --build-path $BUILD_DIR
else
echo "Warning: not cleaning, building debug binary only for this architecture"
swift build --build-path $BUILD_DIR
fi
echo "Create a bare-minimum macOS app for the Swift library"
# This is included directly in a Carthage and CocoaPods release, and packaged up below in an extra artifact for a
# SwiftPM binary release.
mkdir -p "${OUTPUT_DIR}/Sourcery.app/Contents/MacOS"
mkdir -p "${OUTPUT_DIR}/Sourcery.app/Contents/Resources"
cp "${MY_DIR}/Sourcery/ObjectBox/EntityInfo.stencil" "${OUTPUT_DIR}/Sourcery.app/Contents/Resources/"
cp "${MY_DIR}/SourceryExecutable/Info.plist" "${OUTPUT_DIR}/Sourcery.app/Contents/"
if [ "$debug" != true ] ; then
echo "Create universal binary using lipo"
lipo -create \
"${BUILD_DIR}/arm64-apple-macosx/release/Sourcery" \
"${BUILD_DIR}/x86_64-apple-macosx/release/Sourcery" \
-output "${OUTPUT_DIR}/Sourcery.app/Contents/MacOS/Sourcery"
else
echo "Just copying the single debug executable"
swiftBinPath=$(swift build --show-bin-path --build-path $BUILD_DIR)
cp "${swiftBinPath}/Sourcery" "${OUTPUT_DIR}/Sourcery.app/Contents/MacOS/Sourcery"
fi
echo "Create an artifact bundle for the Swift library Swift package"
# The Swift Package Manager requires an artifact bundle, not an app.
# Therefore, create the artifact bundle from the app.
# The name needs to be changed, since the Sourcery is already taken by Sourcery itself.
# The internals can stay unchanged because names are adjusted in the required info.json file.
rm -rf "${OUTPUT_DIR}/ObjectBoxGenerator.artifactbundle/"
cp -r "${OUTPUT_DIR}/Sourcery.app" "${OUTPUT_DIR}/ObjectBoxGenerator.artifactbundle"
# Fix the version, and add the required info.json to the artifact bundle
OBECTBOX_GENERATOR_VERSION=$(${OUTPUT_DIR}/Sourcery.app/Contents/MacOS/Sourcery --version)
echo "GEN: $OBECTBOX_GENERATOR_VERSION"
jq --arg new_version "$OBECTBOX_GENERATOR_VERSION" \
'.artifacts["objectbox-generator"].version = $new_version' \
"${MY_DIR}/Resources/info.json" > \
"${OUTPUT_DIR}/ObjectBoxGenerator.artifactbundle/info.json"
# Create the zip file we want to deploy
rm -f "${OUTPUT_DIR}/ObjectBoxGenerator.artifactbundle.zip"
( cd "${OUTPUT_DIR}/ObjectBoxGenerator.artifactbundle" && zip -r --symlinks "${OUTPUT_DIR}/ObjectBoxGenerator.artifactbundle.zip" . )
# add the sha256 for the zip file
( cd ${OUTPUT_DIR} && shasum -a 256 "ObjectBoxGenerator.artifactbundle.zip" > "ObjectBoxGenerator.artifactbundle.zip.sha256" )
echo "Copy the Sourcery binary to ${OUTPUT_DIR} for tests in Swift library"
rm -rf "${OUTPUT_DIR}/Sourcery"
cp -f "${OUTPUT_DIR}/Sourcery.app/Contents/MacOS/Sourcery" "${OUTPUT_DIR}"
echo ""
echo "$GREEN Done. $RMGREEN$BEL"
echo ""