diff options
author | WlodekM <[email protected]> | 2024-06-16 10:35:45 +0300 |
---|---|---|
committer | WlodekM <[email protected]> | 2024-06-16 10:35:45 +0300 |
commit | abef6da56913f1c55528103e60a50451a39628b1 (patch) | |
tree | b3c8092471ecbb73e568cd0d336efa0e7871ee8d /misc/build_scripts |
initial commit
Diffstat (limited to 'misc/build_scripts')
-rw-r--r-- | misc/build_scripts/build_server.py | 64 | ||||
-rw-r--r-- | misc/build_scripts/buildbot_plugin.sh | 65 | ||||
-rw-r--r-- | misc/build_scripts/buildtestplugin.sh | 4 | ||||
-rw-r--r-- | misc/build_scripts/makerelease.sh | 60 | ||||
-rw-r--r-- | misc/build_scripts/notify.py | 34 | ||||
-rw-r--r-- | misc/build_scripts/readme.md | 9 | ||||
-rw-r--r-- | misc/build_scripts/upload_build.sh | 13 |
7 files changed, 249 insertions, 0 deletions
diff --git a/misc/build_scripts/build_server.py b/misc/build_scripts/build_server.py new file mode 100644 index 0000000..d3ea564 --- /dev/null +++ b/misc/build_scripts/build_server.py @@ -0,0 +1,64 @@ +from http.server import HTTPServer, SimpleHTTPRequestHandler +import os +import subprocess + +build_files = { + '/ClassiCube.exe' : 'cc-w32-d3d.exe', '/ClassiCube.opengl.exe' : 'cc-w32-ogl.exe', + '/ClassiCube.64.exe' : 'cc-w64-d3d.exe', '/ClassiCube.64-opengl.exe' : 'cc-w64-ogl.exe', + '/ClassiCube.32' : 'cc-nix32', '/ClassiCube' : 'cc-nix64', + '/ClassiCube.osx' : 'cc-osx32', '/ClassiCube.64.osx' : 'cc-osx64', + '/ClassiCube.js' : 'cc.js', '/ClassiCube.apk' : 'cc.apk', + '/ClassiCube.rpi' : 'cc-rpi', + '/cc-nix32-gl2' : 'cc-nix32-gl2', '/cc-nix64-gl2' : 'cc-nix64-gl2', + '/cc-osx32-gl2' : 'cc-osx32-gl2', '/cc-osx64-gl2' : 'cc-osx64-gl2', +} + +release_files = { + '/win32' : 'win32/ClassiCube.exe', '/win64' : 'win64/ClassiCube.exe', + '/osx32' : 'osx32/ClassiCube.tar.gz', '/osx64' : 'osx64/ClassiCube.tar.gz', + '/mac32' : 'mac32/ClassiCube.tar.gz', '/mac64' : 'mac64/ClassiCube.tar.gz', + '/nix32' : 'nix32/ClassiCube.tar.gz', '/nix64' : 'nix64/ClassiCube.tar.gz', + '/rpi32' : 'rpi32/ClassiCube.tar.gz', +} + +def run_script(file): + args = ["sh", file] + su = subprocess.Popen(args) + return su.wait() + +class Handler(SimpleHTTPRequestHandler): + + def serve_script(self, file, msg): + ret = run_script(file) + self.send_response(200) + self.end_headers() + self.wfile.write(msg % ret) + + def do_GET(self): + if self.path in build_files: + self.serve_exe('client/src/' + build_files[self.path]) + elif self.path in release_files: + self.serve_exe('client/release/' + release_files[self.path]) + elif self.path == '/rebuild': + self.serve_script('build.sh', 'Rebuild client (%s)') + elif self.path == '/release': + self.serve_script('build_release.sh', 'Package release (%s)') + else: + self.send_error(404, "Unknown action") + return + + def serve_exe(self, path): + try: + f = open(path, 'rb') + fs = os.fstat(f.fileno()) + self.send_response(200) + self.send_header("Content-type", "application/octet-stream") + self.send_header("Content-Length", str(fs[6])) + self.end_headers() + self.copyfile(f, self.wfile) + f.close() + except IOError: + self.send_error(404, "File not found") + +httpd = HTTPServer(('', 80), Handler) +httpd.serve_forever() diff --git a/misc/build_scripts/buildbot_plugin.sh b/misc/build_scripts/buildbot_plugin.sh new file mode 100644 index 0000000..8ddd47a --- /dev/null +++ b/misc/build_scripts/buildbot_plugin.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# This is similar to buildbot.sh but builds plugins for the game instead +# Some variables must be set before invoking this script. See buildtestplugin.sh +cd $ROOT +echo $(pwd) +FILES=$(find . -type f -name "*.c" | tr '\n' ' ') +FLAGS="-shared -fPIC -O1 -s -std=c99" +echo $FILES + +# ----------------------------- compile linux +NIX32_CC="gcc -m32" +NIX64_CC="gcc -m64" +NIX_FLAGS="-nostartfiles -Wl,--entry=0" + +echo "Compiling linux32.." +$NIX32_CC $FILES -I ~/client/src/ -I ./src/ -o ${PLUGIN}_nix32.so $FLAGS $NIX_FLAGS + +echo "Compiling linux64.." +$NIX64_CC $FILES -I ~/client/src/ -I ./src/ -o ${PLUGIN}_nix64.so $FLAGS $NIX_FLAGS + +# ----------------------------- compile macOS +MAC32_CC=~/osx/target/bin/o32-clang +MAC64_CC=~/osx/target/bin/o64-clang +MAC_FLAGS="-undefined dynamic_lookup" + +echo "Compiling mac32.." +$MAC32_CC $FILES -I ~/client/src/ -I ./src/ -o ${PLUGIN}_mac32.dylib $FLAGS $MAC_FLAGS + +echo "Compiling mac64.." +$MAC64_CC $FILES -I ~/client/src/ -I ./src/ -o ${PLUGIN}_mac64.dylib $FLAGS $MAC_FLAGS + +# ----------------------------- compile Windows +WIN32_CC=i686-w64-mingw32-gcc +WIN64_CC=x86_64-w64-mingw32-gcc +# TODO: Figure out why we sometimes need this with mingw +# If we don't include nostart files for some plugins, get a +# ertr000001.o:(.rdata+0x0): undefined reference to `_pei386_runtime_relocator' +# Seems to happen if you use exported variables from the game +if [ -z "$LITE_MODE" ]; then + WIN_FLAGS="" +else + WIN_FLAGS="-nostartfiles -Wl,--entry=0" +fi +# NOTE: You also need to install 'mingw-w64-tools' package for gendef + +echo "Compiling win32" +rm ClassiCube.exe ClassiCube.def +cp ~/client/src/cc-w32-d3d.exe ClassiCube.exe +gendef ClassiCube.exe +i686-w64-mingw32-dlltool -d ClassiCube.def -l libClassiCube.a -D ClassiCube.exe +$WIN32_CC $FILES -I ~/client/src/ -I ./src/ -o ${PLUGIN}_win32.dll $FLAGS $WIN_FLAGS -L . -lClassiCube + +echo "Compiling win64" +rm ClassiCube.exe ClassiCube.def +cp ~/client/src/cc-w64-d3d.exe ClassiCube.exe +gendef ClassiCube.exe +x86_64-w64-mingw32-dlltool -d ClassiCube.def -l libClassiCube.a -D ClassiCube.exe +$WIN64_CC $FILES -I ~/client/src/ -I ./src/ -o ${PLUGIN}_win64.dll $FLAGS $WIN_FLAGS -L . -lClassiCube + +# ----------------------------- compile raspberry pi +RPI_CC=~/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc-4.8.3 +RPI_FLAGS="-nostartfiles -Wl,--entry=0" + +echo "Compiling rpi" +$RPI_CC $FILES -I ~/client/src/ -I ./src/ -o ${PLUGIN}_rpi.so $FLAGS $RPI_FLAGS \ No newline at end of file diff --git a/misc/build_scripts/buildtestplugin.sh b/misc/build_scripts/buildtestplugin.sh new file mode 100644 index 0000000..096b372 --- /dev/null +++ b/misc/build_scripts/buildtestplugin.sh @@ -0,0 +1,4 @@ +#!/bin/bash +ROOT=~/plugins/test/ +PLUGIN=test +source ./buildbot_plugin.sh \ No newline at end of file diff --git a/misc/build_scripts/makerelease.sh b/misc/build_scripts/makerelease.sh new file mode 100644 index 0000000..0c51535 --- /dev/null +++ b/misc/build_scripts/makerelease.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# paths, change these as needed +SOURCE_DIR=~/client/src +MISC_DIR=~/client/misc +BUILDS_DIR=~/client/release + +# ./ClassiCube +make_nix_tar() { + cp $SOURCE_DIR/$1 ClassiCube + chmod +x ClassiCube + tar -zcvf ClassiCube.tar.gz ClassiCube + rm ClassiCube +} + +# ./ClassiCube.app/Info.plist +# ./ClassiCube.app/Contents/MacOS/ClassiCube +# ./ClassiCube.app/Resources/ClassiCube.icns +make_mac_tar() { + mkdir ClassiCube.app + mkdir ClassiCube.app/Contents + mkdir ClassiCube.app/Contents/MacOS + mkdir ClassiCube.app/Contents/Resources + + cp $SOURCE_DIR/$1 ClassiCube.app/Contents/MacOS/ClassiCube + chmod +x ClassiCube.app/Contents/MacOS/ClassiCube + + cp $MISC_DIR/info.plist ClassiCube.app/Contents/Info.plist + cp $MISC_DIR/CCIcon.icns ClassiCube.app/Contents/Resources/ClassiCube.icns + tar -zcvf ClassiCube.tar.gz ClassiCube.app + rm -rf ClassiCube.app +} + + +mkdir -p $BUILDS_DIR +mkdir -p $BUILDS_DIR/win32 $BUILDS_DIR/win64 $BUILDS_DIR/osx32 $BUILDS_DIR/osx64 +mkdir -p $BUILDS_DIR/nix32 $BUILDS_DIR/nix64 $BUILDS_DIR/mac32 $BUILDS_DIR/mac64 +mkdir -p $BUILDS_DIR/rpi32 + +# edge doesn't respect download attribute, and having ClassiCube.64.exe breaks plugins +cp $SOURCE_DIR/cc-w32-d3d.exe $BUILDS_DIR/win32/ClassiCube.exe +cp $SOURCE_DIR/cc-w64-d3d.exe $BUILDS_DIR/win64/ClassiCube.exe + +# use tar to preserve chmod +x, so users don't have to manually do it +cd $BUILDS_DIR/osx32/ +make_nix_tar cc-osx32 +cd $BUILDS_DIR/osx64/ +make_nix_tar cc-osx64 +cd $BUILDS_DIR/nix32/ +make_nix_tar cc-nix32 +cd $BUILDS_DIR/nix64/ +make_nix_tar cc-nix64 +cd $BUILDS_DIR/rpi32/ +make_nix_tar cc-rpi + +# generate ClassiCube.app for mac users +cd $BUILDS_DIR/mac32/ +make_mac_tar cc-osx32 +cd $BUILDS_DIR/mac64/ +make_mac_tar cc-osx64 diff --git a/misc/build_scripts/notify.py b/misc/build_scripts/notify.py new file mode 100644 index 0000000..94e659a --- /dev/null +++ b/misc/build_scripts/notify.py @@ -0,0 +1,34 @@ +import requests, re, datetime, json, time, os +# Any resemblence to any discord bots written by 123DMWM is purely coincidental. I swear. + +# The URL of the discord channel webhook to notify +# You can generate a webhook by right clicking channel -> Edit Channel -> Webhooks +WEBHOOK_URL = '' +# The ID of the user you want to ping on a build failure +# You can get this by right clicking user -> Copy ID +# You may have to go to settings -> Appearance -> Check Developer Mode to see this option +TARGET_USER = '' + +def notify_webhook(body): + try: + webhook_data = { + "username": "CC BuildBot", + "avatar_url": "https://static.classicube.net/img/cc-cube-small.png", + "content" : body + } + + r = requests.post(WEBHOOK_URL, json=webhook_data) + print("BuildNotify response: " + r.text) + except Exception as e: + print("BuildNotify failed: %s" % (e)) + +cc_errors = None +try: + with open(sys.argv[1], 'r') as file: + cc_errors = file.read() +except FileNotFoundError: + # nothing to as no compile errors + pass + +if cc_errors: + notify_webhook('**Houston, we have a problem** <@%s>\n\n%s' % (TARGET_USER, cc_errors)) \ No newline at end of file diff --git a/misc/build_scripts/readme.md b/misc/build_scripts/readme.md new file mode 100644 index 0000000..0ff1d43 --- /dev/null +++ b/misc/build_scripts/readme.md @@ -0,0 +1,9 @@ +This folder contains build scripts for automatically compiling ClassiCube + +|File|Description| +|--------|-------| +|buildbot.sh | Compiles the game to optimised executables (with icons) | +|buildbot_plugin.sh | Compiles specified plugin for various platforms | +|buildtestplugin.sh | Example script for how to use buildbot_plugin.sh | +|makerelease.sh | Packages the executables to produce files for a release | +|notify.py | Notifies a user on Discord if buildbot fails | \ No newline at end of file diff --git a/misc/build_scripts/upload_build.sh b/misc/build_scripts/upload_build.sh new file mode 100644 index 0000000..a3960d3 --- /dev/null +++ b/misc/build_scripts/upload_build.sh @@ -0,0 +1,13 @@ +# upload_build.sh [TARGET NAME] [SOURCE FILE] +# e.g. ~/upload_build.sh latest/ClassiCube.ipa cc.ipa +API_URL= +API_KEY= + +if [ -s $2 ]; then + curl $API_URL \ + --header "X-Build-Key:$API_KEY" \ + --header "X-Build-Name:$1" \ + --data-binary @$2 +else + echo "Missing or empty file: $2" +fi |