-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuild-them.sh
More file actions
executable file
·193 lines (164 loc) · 5.76 KB
/
build-them.sh
File metadata and controls
executable file
·193 lines (164 loc) · 5.76 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
# Define the project names and paths
desktop_project="Companion.Desktop"
android_project="Companion.Android"
ios_project="Companion.iOS"
# Build output directory
output_dir="build"
# Default verbosity level
verbosity="normal"
# Function to clean previous builds
clean_builds() {
echo "Cleaning previous builds in output directory..."
rm -rf "$output_dir"
echo "Running dotnet clean for each project..."
dotnet clean $desktop_project
dotnet clean $android_project
dotnet clean $ios_project
mkdir -p "$output_dir"
}
run_tests() {
echo "Running tests..."
dotnet test --logger "trx;LogFileName=TestResults.xml"
}
# Function to create macOS .app bundle
create_macos_app_bundle() {
app_name="Companion"
src="$output_dir/$desktop_project/osx-arm64"
app_bundle="$output_dir/$desktop_project/osx-arm64/$app_name.app"
echo "Creating .app bundle at $app_bundle..."
rm -rf "$app_bundle"
mkdir -p "$app_bundle/Contents/MacOS" "$app_bundle/Contents/Resources"
# Icon (adjust path if needed)
cp "Companion/Assets/Icons/OpenIPC.icns" "$app_bundle/Contents/Resources/$app_name.icns" 2>/dev/null || true
# Copy published payload into MacOS
cp -R "$src/"* "$app_bundle/Contents/MacOS/"
# Ensure the apphost is executable; if framework-dependent, use the dll runner
if [ -f "$app_bundle/Contents/MacOS/Companion.Desktop" ]; then
chmod +x "$app_bundle/Contents/MacOS/Companion.Desktop"
fi
# Info.plist
cat > "$app_bundle/Contents/Info.plist" <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>$app_name</string>
<key>CFBundleDisplayName</key>
<string>$app_name</string>
<key>CFBundleExecutable</key>
<string>Companion.Desktop</string>
<key>CFBundleIdentifier</key>
<string>com.openipc.$app_name</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>LSMinimumSystemVersion</key>
<string>13.0</string>
<key>CFBundleIconFile</key>
<string>$app_name.icns</string>
</dict>
</plist>
EOL
echo "$app_name.app created: $app_bundle"
}
# Function to build for macOS with verbose output
build_macos() {
echo "Building $desktop_project for macOS (osx-arm64) as .app bundle..."
out="$output_dir/$desktop_project/osx-arm64"
dotnet publish "$desktop_project" -c Release -r osx-arm64 \
--output "$out" --self-contained true -v "$verbosity" \
-p:PublishSingleFile=true -p:UseAppHost=true
# Expect a native apphost when self-contained single-file
apphost="$out/Companion.Desktop"
dll="$out/Companion.Desktop.dll"
if [ -f "$apphost" ] || [ -f "$dll" ]; then
create_macos_app_bundle
else
echo "Error: macOS publish didn't produce Companion.Desktop or Companion.Desktop.dll in $out"
ls -la "$out"
fi
}
# Function to build for Windows
build_windows() {
echo "Building $desktop_project for win-arm64..."
dotnet publish $desktop_project -c Release -r win-arm64 --output "$output_dir/$desktop_project/win-arm64" --self-contained -v $verbosity -p:PublishSingleFile=true
echo "Building $desktop_project for win-x64..."
dotnet publish $desktop_project -c Release -r win-x64 --output "$output_dir/$desktop_project/win-x64" --self-contained -v $verbosity -p:PublishSingleFile=true
}
# Function to build for Linux
build_linux() {
echo "Building $desktop_project for linux-arm64..."
dotnet publish $desktop_project -c Release -r linux-arm64 --output "$output_dir/$desktop_project/linux-arm64" --self-contained -v $verbosity -p:PublishSingleFile=true
echo "Building $desktop_project for linux-x64..."
dotnet publish $desktop_project -c Release -r linux-x64 --output "$output_dir/$desktop_project/linux-x64" --self-contained -v $verbosity -p:PublishSingleFile=true
}
# Function to build for Android
build_android() {
echo "Building $android_project as APK..."
dotnet publish $android_project -c Release -r android-arm64 --output "$output_dir/$android_project" -v $verbosity
}
# Function to build for iOS
build_ios() {
echo "Building $ios_project as an IPA for iOS..."
dotnet publish $ios_project -c Release -r ios-arm64 --output "$output_dir/$ios_project" -v $verbosity
}
# Parse arguments
build_all=false
while [[ $# -gt 0 ]]; do
case $1 in
all)
build_all=true
;;
macos)
build_macos=true
;;
windows)
build_windows=true
;;
linux)
build_linux=true
;;
android)
build_android=true
;;
ios)
build_ios=true
;;
-v|--verbosity)
shift
verbosity="$1"
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [all|macos|windows|linux|android|ios] [-v verbosity_level]"
echo "Verbosity levels: quiet, minimal, normal, detailed, diagnostic"
exit 1
;;
esac
shift
done
# Clean previous builds
clean_builds
run_tests
# Execute builds based on the selected options
if [ "$build_all" = true ] || [ "$build_macos" = true ]; then
build_macos
fi
if [ "$build_all" = true ] || [ "$build_windows" = true ]; then
build_windows
fi
if [ "$build_all" = true ] || [ "$build_linux" = true ]; then
build_linux
fi
if [ "$build_all" = true ] || [ "$build_android" = true ]; then
build_android
fi
if [ "$build_all" = true ] || [ "$build_ios" = true ]; then
build_ios
fi
echo "Build process complete. Outputs are in the '$output_dir' directory."