-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-build-script.sh
More file actions
executable file
·273 lines (221 loc) · 6.81 KB
/
test-build-script.sh
File metadata and controls
executable file
·273 lines (221 loc) · 6.81 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
#!/bin/bash
# Test script to validate build scripts without actually building
# This script checks:
# 1. Script syntax
# 2. Function definitions
# 3. Required files/directories
# 4. Dependency checks
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
print_status() {
echo -e "${BLUE}[TEST]${NC} $1"
}
print_success() {
echo -e "${GREEN}[PASS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[FAIL]${NC} $1"
}
# Test script syntax
test_syntax() {
print_status "Testing script syntax..."
local scripts=("build-native.sh" "build-complete-x86_64.sh" "build-complete-arm64.sh")
for script in "${scripts[@]}"; do
if [ -f "$script" ]; then
if bash -n "$script" 2>&1; then
print_success "$script syntax is valid"
else
print_error "$script has syntax errors"
return 1
fi
else
print_warning "$script not found"
fi
done
return 0
}
# Test required directories
test_directories() {
print_status "Testing required directories..."
local dirs=("ios" "android" "cpp" "android/src/main")
for dir in "${dirs[@]}"; do
if [ -d "$dir" ]; then
print_success "Directory exists: $dir"
else
print_error "Directory missing: $dir"
return 1
fi
done
return 0
}
# Test required files
test_files() {
print_status "Testing required files..."
local files=(
"ios/CMakeLists.txt"
"android/src/main/CMakeLists.txt"
"android/src/main/jni.cpp"
"cpp/cap-llama.h"
"cpp/cap-embedding.cpp"
"cpp/cap-embedding.h"
)
local missing=0
for file in "${files[@]}"; do
if [ -f "$file" ]; then
print_success "File exists: $file"
else
print_warning "File missing: $file (may be optional)"
missing=$((missing + 1))
fi
done
if [ $missing -gt 0 ]; then
print_warning "$missing files missing (some may be optional)"
fi
return 0
}
# Test function definitions in build scripts
test_functions() {
print_status "Testing function definitions..."
local script="build-native.sh"
if [ -f "$script" ]; then
local functions=("print_status" "print_success" "print_warning" "print_error" "check_macos" "check_android_sdk" "build_ios" "build_android" "main")
for func in "${functions[@]}"; do
if grep -q "^${func}()" "$script" || grep -q "^# ${func}" "$script"; then
print_success "Function found: $func"
else
print_warning "Function not found: $func (may be defined differently)"
fi
done
fi
return 0
}
# Test dependency checks
test_dependencies() {
print_status "Testing dependency detection..."
# Check CMake
if command -v cmake &> /dev/null; then
local cmake_version=$(cmake --version 2>/dev/null | head -1)
print_success "CMake found: $cmake_version"
else
print_warning "CMake not found in PATH (required for building)"
fi
# Check Make
if command -v make &> /dev/null; then
local make_version=$(make --version 2>/dev/null | head -1)
print_success "Make found: $make_version"
else
print_warning "Make not found in PATH (required for building)"
fi
# Check Ninja (optional)
if command -v ninja &> /dev/null; then
local ninja_version=$(ninja --version 2>/dev/null)
print_success "Ninja found: version $ninja_version"
else
print_warning "Ninja not found (optional, Make can be used instead)"
fi
# Check Android SDK
if [ -n "$ANDROID_HOME" ] || [ -n "$ANDROID_SDK_ROOT" ]; then
local sdk_path="${ANDROID_HOME:-$ANDROID_SDK_ROOT}"
print_success "Android SDK found: $sdk_path"
else
print_warning "Android SDK not set (ANDROID_HOME or ANDROID_SDK_ROOT)"
fi
# Check macOS for iOS builds
if [[ "$OSTYPE" == "darwin"* ]]; then
print_success "macOS detected (can build iOS)"
# Check Xcode
if command -v xcodebuild &> /dev/null; then
local xcode_version=$(xcodebuild -version 2>/dev/null | head -1)
print_success "Xcode found: $xcode_version"
else
print_warning "Xcode not found (required for iOS builds)"
fi
else
print_warning "Not macOS (iOS builds will be skipped)"
fi
return 0
}
# Test script execution (dry run)
test_execution() {
print_status "Testing script execution (dry run)..."
local script="build-native.sh"
if [ -f "$script" ]; then
# Source the script to test function definitions
# We'll just check if it can be sourced without errors
if bash -c "source '$script' 2>&1; echo 'Script sourced successfully'" 2>&1 | grep -q "Script sourced successfully"; then
print_success "Script can be sourced without errors"
else
print_warning "Script may have issues when sourced"
fi
fi
return 0
}
# Main test function
main() {
echo ""
echo "=========================================="
echo " Build Script Test Suite"
echo "=========================================="
echo ""
local tests_passed=0
local tests_failed=0
# Run tests
if test_syntax; then
tests_passed=$((tests_passed + 1))
else
tests_failed=$((tests_failed + 1))
fi
echo ""
if test_directories; then
tests_passed=$((tests_passed + 1))
else
tests_failed=$((tests_failed + 1))
fi
echo ""
if test_files; then
tests_passed=$((tests_passed + 1))
else
tests_failed=$((tests_failed + 1))
fi
echo ""
if test_functions; then
tests_passed=$((tests_passed + 1))
else
tests_failed=$((tests_failed + 1))
fi
echo ""
if test_dependencies; then
tests_passed=$((tests_passed + 1))
else
tests_failed=$((tests_failed + 1))
fi
echo ""
if test_execution; then
tests_passed=$((tests_passed + 1))
else
tests_failed=$((tests_failed + 1))
fi
echo ""
echo "=========================================="
echo " Test Results"
echo "=========================================="
echo -e "${GREEN}Passed:${NC} $tests_passed"
echo -e "${RED}Failed:${NC} $tests_failed"
echo ""
if [ $tests_failed -eq 0 ]; then
print_success "All tests passed! Build scripts are ready."
return 0
else
print_error "Some tests failed. Please review the output above."
return 1
fi
}
# Run tests
main "$@"