-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·279 lines (246 loc) · 6.3 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·279 lines (246 loc) · 6.3 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
#!/bin/sh
prefix="./out"
# https://stackoverflow.com/questions/29832037/how-to-get-script-directory-in-posix-sh
srcdir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
projects=""
buildType="release"
branch="master"
installDeps="0"
target=""
args=""
platform=""
testProject=""
err() {
echo "error: $@"
exit 1
}
# Build flags from environment variables
buildFlags() {
passC=""
passL=""
[ -n "$CFLAGS" ] && passC="--passC:$CFLAGS"
[ -n "$LDFLAGS" ] && passL="--passL:$LDFLAGS"
}
# Set up platform-specific library paths
setupPlatform() {
if [ "$platform" = "darwin" ]; then
opensslPrefix=$(brew --prefix openssl)
libarchivePrefix=$(brew --prefix libarchive)
export LDFLAGS="-L$opensslPrefix/lib -L$libarchivePrefix/lib"
export CFLAGS="-I$opensslPrefix/include -I$libarchivePrefix/include"
export PKG_CONFIG_PATH="$opensslPrefix/lib/pkgconfig:$libarchivePrefix/lib/pkgconfig"
fi
}
# Unified build function
# $1: project name
# $2: source file (relative to project dir or full path)
# $3: output path
# $4: threads setting (on/off)
# $5: extra flags (optional)
# $6: use deepcopy (1 or empty)
# $7: use branch/ssl (1 or empty)
buildNim() {
cd "$srcdir" || err "Failed to change to source directory"
buildFlags
project="$1"
sourceFile="$2"
outputPath="$3"
threads="$4"
extraFlags="$5"
useDeepcopy="$6"
useBranchSsl="$7"
# Determine source path
case "$sourceFile" in
/*)
sourcePath="$sourceFile"
;;
*)
sourcePath="$srcdir/$project/$sourceFile"
;;
esac
# Build command arguments
set -- nim c -d:$buildType
[ -n "$CC" ] && set -- "$@" --cc:$CC
[ -n "$args" ] && set -- "$@" $args
[ -n "$target" ] && set -- "$@" $target
[ -n "$passC" ] && set -- "$@" $passC
[ -n "$passL" ] && set -- "$@" $passL
[ -n "$useDeepcopy" ] && set -- "$@" --deepcopy:on
[ -n "$useBranchSsl" ] && set -- "$@" -d:branch=$branch -d:ssl
set -- "$@" --threads:$threads -o:"$outputPath"
[ -n "$extraFlags" ] && set -- "$@" $extraFlags
set -- "$@" "$sourcePath"
"$@" || err "building $project failed"
cd - > /dev/null
}
# Run tests for a project
# $1: project name
runTests() {
cd "$srcdir" || err "Failed to change to source directory"
buildFlags
project="$1"
testDir="$srcdir/tests/$project"
if [ ! -d "$testDir" ]; then
err "Test directory not found: $testDir"
fi
# Find all test files
testFiles=$(find "$testDir" -name 'test_*.nim' -type f 2>/dev/null)
if [ -z "$testFiles" ]; then
err "No test files found in $testDir"
fi
echo "Running tests for $project"
echo "================================"
testCount=0
failCount=0
for testFile in $testFiles; do
testName=$(basename "$testFile" .nim)
testBinary="$srcdir/out/tests/$project/$testName"
echo ""
echo "--- $testName ---"
# Ensure output directory exists
mkdir -p "$(dirname "$testBinary")"
# Build the test
set -- nim c -d:debug -d:ssl -d:run3NoLibArchive
[ -n "$passC" ] && set -- "$@" $passC
[ -n "$passL" ] && set -- "$@" $passL
set -- "$@" --threads:on --deepcopy:on -o:"$testBinary" "$testFile"
if ! "$@"; then
echo "FAIL: $testName (compilation failed)"
failCount=$((failCount + 1))
testCount=$((testCount + 1))
continue
fi
# Run the test
if "$testBinary"; then
echo "PASS: $testName"
else
echo "FAIL: $testName (execution failed)"
failCount=$((failCount + 1))
fi
testCount=$((testCount + 1))
done
echo ""
echo "================================"
echo "Tests: $testCount, Passed: $((testCount - failCount)), Failed: $failCount"
if [ "$failCount" -gt 0 ]; then
exit 1
fi
cd - > /dev/null
}
printHelp() {
printf "Usage: './build.sh [ARGUMENTS]'
Options:
-d, --debug: Enable debug on built projects
-t, --target [ARCHITECTURE]: Set architecture for built binary
-p, --projects [PROJECTS]: Enable projects, separate by comma
-P, --platform [PLATFORM]: Set platform for library paths (e.g., darwin for macOS)
-T, --test [PROJECT]: Run tests for a project (e.g., kpkg)
-i, --installDeps: Install dependencies before continuing
-c, --clean: Clean binaries
-b, --branch [BRANCH]: Set default branch for repositories. 'master' by default.
-a, --args [ARGUMENTS]: Set arguments for nimc.
"
}
echo "Kreato Linux - Source tree build script"
if [ "$#" = "0" ]; then
printHelp
exit 0
fi
while [ "$#" -gt 0 ]; do
case $1 in
-t|--target)
shift
[ -z "$1" ] && err "--target requires an argument"
target="--cpu:$1"
;;
-d|--debug)
buildType="debug"
;;
-p|--projects)
shift
[ -z "$1" ] && err "--projects requires an argument"
projects="$1"
;;
-P|--platform)
shift
[ -z "$1" ] && err "--platform requires an argument"
platform="$1"
;;
-i|--installDeps)
installDeps="1"
;;
-c|--clean)
echo "Cleaning binaries"
rm -rf "$prefix"
rm -f "$srcdir/kreastrap/kreastrap"
rm -f "$srcdir/kreaiso/kreaiso"
;;
-b|--branch)
shift
[ -z "$1" ] && err "--branch requires an argument"
branch="$1"
;;
-a|--args)
shift
[ -z "$1" ] && err "--args requires an argument"
args="$1"
;;
-T|--test)
shift
[ -z "$1" ] && err "--test requires a project name"
testProject="$1"
;;
*)
printHelp
exit 1
;;
esac
shift
done
if [ "$installDeps" = "1" ]; then
nimble install cligen nimcrypto norm fusion regex -y \
|| err "Installing dependencies failed"
fi
# Run tests if requested
if [ -n "$testProject" ]; then
setupPlatform
runTests "$testProject"
exit 0
fi
[ -z "$projects" ] && exit 0
setupPlatform
IFS=","
for v in $projects; do
echo "building $v"
case $v in
kpkg)
buildNim "$v" "$v.nim" "$prefix/$v" "on" "" "1" "1"
;;
chkupd)
buildNim "$v" "$v.nim" "$prefix/$v" "on" "-d:run3NoLibArchive" "" "1"
;;
jumpstart)
buildNim "jumpstart" "jumpstart.nim" "$prefix/jumpstart" "on" "--mm:refc" "1" ""
buildNim "jumpstart" "jumpctl.nim" "$prefix/jumpctl" "off" "" "1" ""
;;
run3tools)
buildNim "run3tools" "main.nim" "$prefix/run3tools" "off" "-d:run3Standalone" "1" ""
;;
kreastrap)
buildNim "kreastrap" "kreastrap.nim" "$srcdir/kreastrap/kreastrap" \
"on" "" "1" "1"
;;
kreaiso)
buildNim "kreaiso" "kreaiso.nim" "$srcdir/kreaiso/kreaiso" \
"on" "" "1" "1"
;;
install_klinstaller)
[ ! -d "$DESTDIR" ] && mkdir -p "$DESTDIR"
cp "$srcdir/installer/klinstaller" "$DESTDIR/bin/klinstaller"
chmod +x "$DESTDIR/bin/klinstaller"
;;
*)
echo "Unknown project: $v" >&2
;;
esac
done