-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·343 lines (312 loc) · 15.1 KB
/
build
File metadata and controls
executable file
·343 lines (312 loc) · 15.1 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/bin/bash
# BrightSign OE Patch and Build Script
# Uses pre-built Docker image with source already included
set -e
# Check if running as root, which can cause permission issues.
if [ "$(id -u)" -eq 0 ]; then
echo "Error: This script must not be run as root. Please run as a regular user."
exit 1
fi
# get the directory of this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Default values
TARGET=""
CLEAN=false
QUIET=false
VERBOSE=false
DISTCLEAN=false
EXTRACT_SDK=false
NO_PATCH=false
BRIGHTSIGN_OS_VERSION=${BRIGHTSIGN_OS_VERSION:-9.1.52}
usage() {
echo "Usage: $0 [OPTIONS] [TARGET]"
echo "Build BrightSign OE packages using pre-built Docker image"
echo ""
echo "Arguments:"
echo " TARGET Package or recipe to build (default: brightsign-sdk)"
echo " Examples: python3-tqdm, python3-opencv, brightsign-sdk"
echo ""
echo "Options:"
echo " -c, --clean Clean build artifacts for the target (bitbake -c cleanall)."
echo " --distclean Perform a deeper clean, removing tmp-glibc and sstate-cache. Implies --clean."
echo " --extract-sdk Extract built SDK to host after successful build."
echo " --no-patch Build without applying any patches (vanilla build)."
echo " -q, --quiet Use quieter build output."
echo " -v, --verbose Enable verbose output."
echo " -h, --help Show this help message."
echo " --interactive Launch container and keep interactive shell."
echo ""
echo "Examples:"
echo " $0 # Build full SDK with patches applied"
echo " $0 python3-tqdm # Build specific package with patches"
echo " $0 python3-tqdm --clean # Clean then build specific package"
echo " $0 --no-patch python3-tqdm # Build package without any patches"
echo " $0 --distclean brightsign-sdk # Clean and distclean then build full SDK"
echo " $0 brightsign-sdk --extract-sdk # Build SDK and extract to host"
echo ""
echo "Note: Builds require Docker image 'bsoe-build' with pre-built source"
echo " Build Docker image first: docker build -t bsoe-build ."
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-c|--clean)
CLEAN=true
shift
;;
--distclean)
DISTCLEAN=true
CLEAN=true # distclean implies clean
shift
;;
--extract-sdk)
EXTRACT_SDK=true
shift
;;
--no-patch)
NO_PATCH=true
shift
;;
-q|--quiet)
QUIET=true
shift
;;
-v|--verbose)
VERBOSE=true
shift
;;
-h|--help)
usage
exit 0
;;
--interactive)
INTERACTIVE=true
shift
;;
-*)
echo "Unknown option: $1"
usage
exit 1
;;
*)
if [ -z "$TARGET" ]; then
TARGET="$1"
else
echo "Multiple targets specified. Only one target allowed."
usage
exit 1
fi
shift
;;
esac
done
# Set default target if not provided
if [ -z "$TARGET" ]; then
TARGET="brightsign-sdk"
fi
# Interactive shell option
if [ "$INTERACTIVE" = true ]; then
echo "Launching interactive shell in Docker container..."
docker run --rm -it \
-v "${SCRIPT_DIR}/srv:/srv" \
-v "${SCRIPT_DIR}/bsoe-recipes:/home/builder/patches:ro" \
-w /home/builder/bsoe/brightsign-oe/build \
bsoe-build bash
exit 0
fi
# Verbose output
if [ "$VERBOSE" = true ]; then
echo "BrightSign OE Patch and Build"
echo "=============================="
echo "Script directory: $SCRIPT_DIR"
echo "Target: $TARGET"
echo "Clean build: $CLEAN"
echo "Distclean: $DISTCLEAN"
echo "Extract SDK: $EXTRACT_SDK"
echo "No patches: $NO_PATCH"
echo "Quiet mode: $QUIET"
echo "BrightSign OS Version: $BRIGHTSIGN_OS_VERSION"
echo ""
fi
# Check if Docker image exists
if ! docker images | grep -q "^bsoe-build "; then
echo "Error: Docker image 'bsoe-build' not found."
echo "Please build the Docker image first:"
echo " docker build --rm --build-arg USER_ID=\\$(id -u) --build-arg GROUP_ID=\\$(id -g) \\\\"
echo " --build-arg BRIGHTSIGN_OS_VERSION=${BRIGHTSIGN_OS_VERSION} -t bsoe-build ."
exit 1
fi
# Build quiet flag
QUIET_FLAG=""
if [ "$QUIET" = true ]; then
QUIET_FLAG="-q"
fi
# Prepare Docker run command with bind mounts
DOCKER_CMD="docker run --rm \
-v \"${SCRIPT_DIR}/srv:/srv\" \
-w /home/builder/bsoe/brightsign-oe/build \
bsoe-build"
# Add patch volume only if patches will be applied
if [ "$NO_PATCH" != true ]; then
DOCKER_CMD="docker run --rm \
-v \"${SCRIPT_DIR}/bsoe-recipes:/home/builder/patches:ro\" \
-v \"${SCRIPT_DIR}/sh:/home/builder/host-scripts:ro\" \
-v \"${SCRIPT_DIR}/srv:/srv\" \
-w /home/builder/bsoe/brightsign-oe/build \
bsoe-build"
fi
# Build command construction
BUILD_CMD="MACHINE=cobra ./bsbb $QUIET_FLAG ${TARGET}"
# Add SDK extraction if requested
if [ "$EXTRACT_SDK" = true ] && [ "$TARGET" = "brightsign-sdk" ]; then
BUILD_CMD="$BUILD_CMD && if [ -d tmp-glibc/deploy/sdk ]; then cp tmp-glibc/deploy/sdk/brightsign-x86_64-*-toolchain-*.sh /srv/ 2>/dev/null || true; echo 'SDK copied to /srv for extraction'; fi"
fi
# Construct full container command
CONTAINER_CMD=""
# Add distclean if requested
if [ "$DISTCLEAN" = true ]; then
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🧹 DISTCLEAN: Removing build directories (may take 1-2 minutes)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
CONTAINER_CMD="$CONTAINER_CMD if [ -d /home/builder/bsoe/brightsign-oe/build/tmp-glibc ]; then rm -rf /home/builder/bsoe/brightsign-oe/build/tmp-glibc; echo '✅ Removed tmp-glibc'; fi; "
CONTAINER_CMD="$CONTAINER_CMD if [ -d /home/builder/bsoe/brightsign-oe/sstate-cache ]; then rm -rf /home/builder/bsoe/brightsign-oe/sstate-cache; echo '✅ Removed sstate-cache'; fi; "
fi
# Add patch application if not --no-patch mode
if [ "$NO_PATCH" != true ]; then
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🔧 PATCHING: Applying custom recipes to build environment"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
CONTAINER_CMD="$CONTAINER_CMD /usr/local/bin/setup-patches.sh && "
else
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🔧 VANILLA BUILD: Building without custom patches"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
fi
# Add clean if requested
if [ "$CLEAN" = true ]; then
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🧹 CLEAN: Removing previous build artifacts for $TARGET"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
CONTAINER_CMD="$CONTAINER_CMD MACHINE=cobra ./bsbb -c cleanall $TARGET 2>/dev/null || true; "
fi
# Add the main build command
CONTAINER_CMD="$CONTAINER_CMD $BUILD_CMD"
# Execute everything in a single container run
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🔨 BUILDING: $TARGET"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Provide time estimates based on target
if [ "$TARGET" = "brightsign-sdk" ]; then
echo "⏱️ Estimated time: 30-60 minutes (full SDK build)"
echo "💡 Tip: This is a good time for a coffee break!"
else
echo "⏱️ Estimated time: 5-15 minutes (individual package)"
fi
echo ""
echo "📊 Progress updates:"
echo " • BitBake will show task progress as packages are built"
echo " • Look for 'NOTE: Tasks Summary:' at the end for build stats"
echo " • Any errors will be clearly marked with ERROR:"
echo ""
echo "Starting build now..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
eval "$DOCKER_CMD bash -c \"$CONTAINER_CMD\""
if [ $? -eq 0 ]; then
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ SUCCESS: $TARGET built successfully"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Extract SDK if requested
if [ "$EXTRACT_SDK" = true ] && [ "$TARGET" = "brightsign-sdk" ]; then
echo ""
echo "📦 Extracting and installing SDK..."
# Look for SDK file in srv directory (copied during build)
SDK_FILE=$(ls "${SCRIPT_DIR}/srv/brightsign-x86_64-"*"-toolchain-"*".sh" 2>/dev/null | head -n 1)
if [ -n "$SDK_FILE" ] && [ -f "$SDK_FILE" ]; then
SDK_BASENAME=$(basename "$SDK_FILE")
cp "$SDK_FILE" "${SCRIPT_DIR}/${SDK_BASENAME}"
echo "✅ SDK extracted to ${SCRIPT_DIR}/${SDK_BASENAME}"
# Clean up the copy in srv
rm -f "$SDK_FILE"
# Also install and patch SDK if requested
echo "📦 Installing SDK to ./sdk directory..."
if "${SCRIPT_DIR}/${SDK_BASENAME}" -d "${SCRIPT_DIR}/sdk" -y; then
echo "✅ SDK installed to ./sdk"
# Patch SDK with Rockchip libraries (same as reference project)
echo "🔧 Adding librknnrt.so to SDK..."
cd "${SCRIPT_DIR}/sdk/sysroots/aarch64-oe-linux/usr/lib"
if [ ! -f "librknnrt.so" ]; then
if wget -q https://github.com/airockchip/rknn-toolkit2/raw/v2.3.2/rknpu2/runtime/Linux/librknn_api/aarch64/librknnrt.so; then
echo "✅ librknnrt.so downloaded to SDK"
else
echo "⚠️ Failed to download librknnrt.so - continuing anyway"
fi
else
echo "✅ librknnrt.so already present in SDK"
fi
cd "${SCRIPT_DIR}"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🎉 COMPLETE: SDK ready for packaging"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "📋 Next steps:"
echo " 1. Package the extension: ./package"
echo " 2. Deploy to player: See docs/deployment.md"
echo " 3. Test with Model Zoo: See docs/model-zoo-guide.md"
echo ""
else
echo "⚠️ SDK installation failed - SDK installer is available for manual installation"
echo ""
echo "💡 Manual installation:"
echo " ./${SDK_BASENAME} -d ./sdk -y"
fi
else
echo "❌ SDK file not found in /srv directory"
echo " Expected: ${SCRIPT_DIR}/srv/brightsign-x86_64-*-toolchain-*.sh"
fi
elif [ "$TARGET" != "brightsign-sdk" ]; then
echo ""
echo "📋 Next steps:"
echo " 1. Rebuild full SDK: ./build --extract-sdk"
echo " 2. Package extension: ./package"
echo " 3. Deploy to player: See docs/deployment.md"
echo ""
fi
else
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "❌ BUILD FAILED: $TARGET"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "🔍 Troubleshooting steps:"
echo ""
echo "1. Check the error message above for specific failures"
echo " Look for lines starting with 'ERROR:' or 'FATAL:'"
echo ""
echo "2. Common issues and solutions:"
echo " • 'Nothing PROVIDES' → Missing dependency, check DEPENDS/RDEPENDS"
echo " • 'do_compile failed' → Check recipe syntax and build dependencies"
echo " • 'Permission denied' → Run ./build --distclean $TARGET"
echo " • 'Files not shipped' → Add FILES:\${PN} definition to recipe"
echo ""
echo "3. Get detailed logs:"
echo " ./build --interactive"
echo " # Then inside container:"
echo " cd /home/builder/bsoe/brightsign-oe/build"
echo " find tmp-glibc/work -name 'log.do_*' | grep $TARGET"
echo ""
echo "4. Try a clean build:"
echo " ./build --clean $TARGET"
echo ""
echo "5. For persistent issues:"
echo " ./build --distclean $TARGET"
echo ""
echo "6. Check documentation:"
echo " • FAQ: FAQ.md"
echo " • Troubleshooting: docs/troubleshooting.md"
echo " • Workflows: WORKFLOWS.md"
echo ""
exit 1
fi