Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·339 lines (286 loc) · 10.7 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·339 lines (286 loc) · 10.7 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
#!/bin/bash
# This script is used to build the cores for RetroArch using EmulatorJS
# It will pull the cores.json file from the root of the repository and build the cores
# The cores.json file should contain an array of objects with the following properties:
# - name: the name of the core
# - repo: the repository of the core
# - branch: the branch of the core
# - license: the license file of the core
# - makeoptions: an object with the following properties:
# - buildpath: the path to the makefile
# - makescript: the make script to run
# - arguments: an array of arguments to pass to the make
# - custom: a boolean to indicate if the build command is custom
# - build_command: the custom build command
# - build_retroarch_command: the custom build retroarch command
# - options: an object with the following properties:
# - threads: a boolean to indicate if the core should be built with threads
# - legacy: a boolean to indicate if the core should be built with legacy
# - threads_legacy: a boolean to indicate if the core should be built with threads and legacy
# - makefile: the makefile to use
# - makefileArg: the argument to pass to the makefile
# The script will build the cores and create a data file for each core
# The data file will contain the core.json file, the license file and the build.json file
# The build.json file will contain the build start and end time and the options used to build the core
# The script will also create a report file for each core that was built
# The report file will contain the core name, the build start and end time and the options used to build the core
# The script will also create a log file for each core that was built
# The log file will contain the output of the build command
# argument defaults
coreToBuild=""
listAllCores=false
listCoreNames=false
# process arguments
for i in "$@"
do
case $i in
-c=*|--core=*)
# core to build
coreToBuild="${i#*=}"
shift
;;
-l|--list)
# list cores
listAllCores=true
;;
--core-names-only)
# list core names only
listCoreNames=true
;;
*)
# unknown option
;;
esac
done
# set up paths
initialPath="$PWD"
buildPath="$PWD/compile"
outputPath="$PWD/output"
buildReport="$outputPath/reports"
logPath="$outputPath/logs"
outPath="$buildPath/RetroArch/dist-scripts"
tempPath="RetroArch/dist-scripts/core-temp"
build() {
rm -f *.bc
emmake make -f "$makefileName" clean
emmake make -j$(nproc) -f "$makefileName" platform=emscripten $makefileArg || exit 1
linkerfilename=( *.bc )
mv $linkerfilename "$buildPath/$tempPath/normal/"
}
buildThreads() {
rm -f *.bc
emmake make -f "$makefileName" clean
emmake make -j$(nproc) -f "$makefileName" platform=emscripten EMULATORJS_THREADS=1 $makefileArg || exit 1
linkerfilename=( *.bc )
mv $linkerfilename "$buildPath/$tempPath/threads/"
}
buildLegacy() {
rm -f *.bc
emmake make -f "$makefileName" clean
emmake make -j$(nproc) -f "$makefileName" platform=emscripten EMULATORJS_LEGACY=1 $makefileArg || exit 1
linkerfilename=( *.bc )
mv $linkerfilename "$buildPath/$tempPath/legacy/"
}
buildThreadsLegacy() {
rm -f *.bc
emmake make -f "$makefileName" clean
emmake make -j$(nproc) -f "$makefileName" platform=emscripten EMULATORJS_THREADS=1 EMULATORJS_LEGACY=1 $makefileArg || exit 1
linkerfilename=( *.bc )
mv $linkerfilename "$buildPath/$tempPath/legacyThreads/"
}
# create compile directory
mkdir -p $buildPath
cd $buildPath
# create output path
mkdir -p $outputPath
cp $initialPath/cores.json $outputPath
mkdir -p $buildReport
mkdir -p $logPath
if [ "$listAllCores" = false ]; then
# start pulling sources and compile
if [ ! -d "RetroArch" ]; then
git clone --depth 1 "https://github.com/EmulatorJS/RetroArch.git" "RetroArch" || exit 1
fi
cd RetroArch
git pull
if [ ! -d "EmulatorJS" ]; then
git clone "https://github.com/EmulatorJS/EmulatorJS.git" "EmulatorJS" --depth 1 || exit 1
fi
cd EmulatorJS
git pull
cd "$outPath"
rm -f *.bc
fi
compileProject() {
name="$1"
repo="$2"
branch="$3"
makefilePath="$4"
makefileName="$5"
makefileArg="$6"
custom="$7"
build_command="$8"
if [ ! -d "$name" ]; then
git clone "$repo" "$name" --depth 1
cd "$name"
git submodule update --init --recursive
cd ../
fi
cd "$name"
if [ $branch != 'null' ]; then
echo "Checking out branch $branch"
git checkout "$branch"
fi
git pull
git submodule update --recursive
if [[ "$custom" = "true" ]]; then
eval "$build_command"
else
cd "$makefilePath"
build
buildThreads
buildLegacy
buildThreadsLegacy
fi
cd "$buildPath"
}
cd "$buildPath"
compileStartPath="$PWD"
for row in $(jq -r '.[] | @base64' ../cores.json); do
# function to decode base64 and parse JSON
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
# get core name
name=`echo $(_jq '.') | jq -r '.name'`
# check if we need to build this core, if coreToBuild is not set, build all cores
if [ ! -z "$coreToBuild" -a "$coreToBuild" != " " ]; then
if [ "$coreToBuild" != "$name" ]; then
continue
fi
fi
# get the core details
repo=`echo $(_jq '.') | jq -r '.repo'`
branch=`echo $(_jq '.') | jq -r '.branch'`
license=`echo $(_jq '.') | jq -r '.license'`
buildpath=`echo $(_jq '.') | jq -r '.makeoptions.buildpath'`
makescript=`echo $(_jq '.') | jq -r '.makeoptions.makescript'`
arguments=`echo $(_jq '.') | jq -r '.makeoptions.arguments[] | @base64'`
options=`echo $(_jq '.') | jq -r '.options'`
custom=`echo $(_jq '.') | jq -r '.makeoptions.custom'`
build_command=`echo $(_jq '.') | jq -r '.makeoptions.build_command'`
build_retroarch_command=`echo $(_jq '.') | jq -r '.makeoptions.build_retroarch_command'`
argumentstring=""
for rowarg in $(echo "${arguments}"); do
argumentstring="$argumentstring `echo $rowarg | base64 --decode`"
done
# display core details
if [ "$listCoreNames" = true ]; then
if [ "$listAllCores" = true ]; then
echo $name
fi
if [ "$listAllCores" = false ]; then
$listCoreNames=false
fi
fi
if [ "$listCoreNames" = false ]; then
echo "Core: $name"
echo "Repo: $repo"
echo "Branch: $branch"
echo "License: $license"
echo "Build path: $buildpath"
echo "Make script: $makescript"
echo "Arguments: $argumentstring"
echo "Options: $options"
echo "Custom: $custom"
echo "Build command: $build_command"
echo "Build RetroArch command: $build_retroarch_command"
echo "---------------------------------------"
fi
# build if listAllCores is set to false
if [ "$listAllCores" = false ]; then
echo "Building core $name"
# create temp directory for core
cd "$buildPath"
rm -fr $tempPath
mkdir -p $tempPath/
cd $tempPath
mkdir -p normal/
mkdir -p threads/
mkdir -p legacy/
mkdir -p legacyThreads/
cd "$buildPath"
# start compile
startTime=`date -u -Is`
cd $compileStartPath
echo "Working dir $PWD"
unset FROZEN_CACHE
compileProject "$name" "$repo.git" "$branch" "$buildpath" "$makescript" "$argumentstring" "$custom" "$build_command" >> "$logPath/$name-compile.log"
# write JSON stanza for this core to disk
echo ${row} | base64 --decode > "./core.json"
if [ ! -z "$license" -a "$license" != " " ]; then
# license file is provided - copy it
echo "License file: $name/$license"
cp $name/$license "./license.txt"
fi
echo "Building wasm's for core $name"
cd "$buildPath/RetroArch/dist-scripts"
if [[ "$custom" = "true" ]]; then
eval "$build_retroarch_command" >> "$logPath/$name-emake.log"
else
mv core-temp/normal/*.bc ./
emmake ./build-emulatorjs.sh --clean >> "$logPath/$name-emake.log"
rm -f *.bc
mv core-temp/threads/*.bc ./
emmake ./build-emulatorjs.sh --clean --threads >> "$logPath/$name-emake.log"
rm -f *.bc
mv core-temp/legacy/*.bc ./
emmake ./build-emulatorjs.sh --clean --legacy >> "$logPath/$name-emake.log"
rm -f *.bc
mv core-temp/legacyThreads/*.bc ./
emmake ./build-emulatorjs.sh --clean --threads --legacy >> "$logPath/$name-emake.log"
rm -f *.bc
rm -rf core-temp
fi
rm -f *.bc
echo "Packing core information for $name"
cd $compileStartPath
if [ -f "EmulatorJS/data/cores/$name-wasm.data" ]; then
7z a -t7z EmulatorJS/data/cores/$name-wasm.data ./core.json ./license.txt ../build.json
cp EmulatorJS/data/cores/$name-wasm.data $outputPath
fi
if [ -f "EmulatorJS/data/cores/$name-thread-wasm.data" ]; then
7z a -t7z EmulatorJS/data/cores/$name-thread-wasm.data ./core.json ./license.txt ../build.json
cp EmulatorJS/data/cores/$name-thread-wasm.data $outputPath
fi
if [ -f "EmulatorJS/data/cores/$name-legacy-wasm.data" ]; then
7z a -t7z EmulatorJS/data/cores/$name-legacy-wasm.data ./core.json ./license.txt ../build.json
cp EmulatorJS/data/cores/$name-legacy-wasm.data $outputPath
fi
if [ -f "EmulatorJS/data/cores/$name-thread-legacy-wasm.data" ]; then
7z a -t7z EmulatorJS/data/cores/$name-thread-legacy-wasm.data ./core.json ./license.txt ../build.json
cp EmulatorJS/data/cores/$name-thread-legacy-wasm.data $outputPath
fi
# create zip file containing the core data files
cd EmulatorJS/data/cores
zip $outputPath/$name.zip $name-wasm.data $name-thread-wasm.data $name-legacy-wasm.data $name-thread-legacy-wasm.data
cd $compileStartPath
# clean up to make sure the next build in the json gets the right license and core file
rm -f ./license.txt
rm -f ./core.json
# write report to report file
endTime=`date -u -Is`
reportString="{ \"core\": \"$name\", \"buildStart\": \"$startTime\", \"buildEnd\": \"$endTime\", \"options\": $options }"
buildReportFile="$buildReport/$name.json"
echo $reportString > $buildReportFile
fi
done
if [ "$listAllCores" = false ]; then
# delete all compile files
if [[ -z "$DEPLOY_ENV" ]]; then
echo "Not deleting build path"
else
rm -fR $buildPath
fi
fi
cd "$initialPath"