mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 20:58:07 +03:00
tools/docker: use Python entrypoints
This commit is contained in:
parent
afb312d8f5
commit
0bfa2bb84b
8 changed files with 116 additions and 41 deletions
|
@ -149,4 +149,5 @@ COPY --from=libav /ext/ /ext/
|
|||
COPY --from=sdl /ext/ /ext/
|
||||
COPY --from=backtrace /ext/ /ext/
|
||||
|
||||
ENV PYTHONPATH=/app/tools/
|
||||
ENTRYPOINT ["/app/tools/docker/game-linux/entrypoint.sh"]
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
#!/bin/sh
|
||||
set -x
|
||||
set -e
|
||||
#!/usr/bin/env python3
|
||||
from pathlib import Path
|
||||
|
||||
EXE_FILE=TR1X
|
||||
from shared.docker import BaseGameEntrypoint
|
||||
|
||||
if [ ! -f /app/build/linux/build.ninja ]; then
|
||||
meson --buildtype "$TARGET" /app/build/linux/ --pkg-config-path=$PKG_CONFIG_PATH
|
||||
fi
|
||||
|
||||
cd /app/build/linux
|
||||
meson compile
|
||||
class LinuxEntrypoint(BaseGameEntrypoint):
|
||||
BUILD_ROOT = Path("/app/build/linux/")
|
||||
COMPILE_ARGS = []
|
||||
|
||||
if [ "$TARGET" = release ]; then
|
||||
if ! upx -t "$EXE_FILE"; then
|
||||
strip "$EXE_FILE"
|
||||
upx "$EXE_FILE"
|
||||
fi
|
||||
fi
|
||||
def post_compile(self) -> None:
|
||||
if self.target == "release":
|
||||
self.compress_exe(self.BUILD_ROOT / "TR1X")
|
||||
|
||||
if __name__ == "__main__":
|
||||
LinuxEntrypoint().run()
|
||||
|
|
|
@ -150,4 +150,5 @@ RUN apt-get install -y \
|
|||
meson \
|
||||
ninja
|
||||
|
||||
ENV PYTHONPATH=/app/tools/
|
||||
ENTRYPOINT ["/app/tools/docker/game-win/entrypoint.sh"]
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
#!/bin/sh
|
||||
set -x
|
||||
set -e
|
||||
#!/usr/bin/env python3
|
||||
from pathlib import Path
|
||||
|
||||
if [ ! -f /app/build/win/build.ninja ]; then
|
||||
meson --buildtype "$TARGET" /app/build/win/ --cross /app/tools/docker/game-win/meson_linux_mingw32.txt --pkg-config-path=$PKG_CONFIG_PATH
|
||||
fi
|
||||
from shared.docker import BaseGameEntrypoint
|
||||
|
||||
cd /app/build/win; meson compile
|
||||
|
||||
if [ "$TARGET" = release ]; then
|
||||
for file in *.exe; do
|
||||
upx -t "$file" || ( i686-w64-mingw32-strip "$file" && upx "$file" )
|
||||
done
|
||||
fi
|
||||
class WindowsEntrypoint(BaseGameEntrypoint):
|
||||
BUILD_ROOT = Path("/app/build/win/")
|
||||
COMPILE_ARGS = [
|
||||
"--cross",
|
||||
"/app/tools/docker/game-win/meson_linux_mingw32.txt",
|
||||
]
|
||||
|
||||
def post_compile(self) -> None:
|
||||
if self.target == "release":
|
||||
for path in self.BUILD_ROOT.glob("*.exe"):
|
||||
self.compress_exe(path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
WindowsEntrypoint().run()
|
||||
|
|
|
@ -3,6 +3,8 @@ import argparse
|
|||
from pathlib import Path
|
||||
from subprocess import run
|
||||
|
||||
from shared.versioning import generate_version
|
||||
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser()
|
||||
|
@ -10,20 +12,6 @@ def parse_args() -> argparse.Namespace:
|
|||
return parser.parse_args()
|
||||
|
||||
|
||||
def generate_version() -> str:
|
||||
cmd = [
|
||||
"git",
|
||||
"describe",
|
||||
"--always",
|
||||
"--abbrev=7",
|
||||
"--tags",
|
||||
"--exclude",
|
||||
"latest",
|
||||
]
|
||||
version = run(cmd, capture_output=True, text=True).stdout.strip()
|
||||
return f'TR1X {version or "?"}'
|
||||
|
||||
|
||||
def main() -> None:
|
||||
args = parse_args()
|
||||
version = generate_version()
|
||||
|
|
0
tools/shared/__init__.py
Normal file
0
tools/shared/__init__.py
Normal file
67
tools/shared/docker.py
Normal file
67
tools/shared/docker.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
from subprocess import check_call, check_output, run
|
||||
|
||||
|
||||
class BaseGameEntrypoint:
|
||||
BUILD_ROOT: Path = ...
|
||||
COMPILE_ARGS: list[str] = ...
|
||||
STRIP_TOOL = "strip"
|
||||
UPX_TOOL = "upx"
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.target = os.environ.get("TARGET", "debug")
|
||||
|
||||
def run(self) -> None:
|
||||
args = self.parse_args()
|
||||
args.func(args)
|
||||
|
||||
def parse_args(self) -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(description="Docker entrypoint")
|
||||
subparsers = parser.add_subparsers(dest="action", help="Subcommands")
|
||||
|
||||
compile_parser = subparsers.add_parser(
|
||||
"compile", help="Compile action"
|
||||
)
|
||||
compile_parser.set_defaults(func=self.compile)
|
||||
|
||||
package_parser = subparsers.add_parser(
|
||||
"package", help="Package action"
|
||||
)
|
||||
package_parser.add_argument("-o", "--output", type=Path)
|
||||
package_parser.set_defaults(func=self.package)
|
||||
|
||||
args = parser.parse_args()
|
||||
if not hasattr(args, "func"):
|
||||
args.action = "compile"
|
||||
args.func = self.compile
|
||||
return args
|
||||
|
||||
def compile(self, args: argparse.Namespace) -> None:
|
||||
pkg_config_path = os.environ["PKG_CONFIG_PATH"]
|
||||
|
||||
if not Path("/app/build/linux/build.jinja").exists():
|
||||
check_call(
|
||||
[
|
||||
"meson",
|
||||
"--buildtype",
|
||||
self.target,
|
||||
*self.COMPILE_ARGS,
|
||||
self.BUILD_ROOT,
|
||||
"--pkg-config-path",
|
||||
pkg_config_path,
|
||||
]
|
||||
)
|
||||
|
||||
check_call(["meson", "compile"], cwd=self.BUILD_ROOT)
|
||||
|
||||
self.post_compile()
|
||||
|
||||
def post_compile(self) -> None:
|
||||
pass
|
||||
|
||||
def compress_exe(self, path: Path) -> None:
|
||||
if run([self.UPX_TOOL, "-t", str(path)]).returncode != 0:
|
||||
check_call([self.STRIP_TOOL, str(path)])
|
||||
check_call([self.UPX_TOOL, str(path)])
|
15
tools/shared/versioning.py
Normal file
15
tools/shared/versioning.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from subprocess import run
|
||||
|
||||
|
||||
def generate_version() -> str:
|
||||
cmd = [
|
||||
"git",
|
||||
"describe",
|
||||
"--always",
|
||||
"--abbrev=7",
|
||||
"--tags",
|
||||
"--exclude",
|
||||
"latest",
|
||||
]
|
||||
version = run(cmd, capture_output=True, text=True).stdout.strip()
|
||||
return f'TR1X {version or "?"}'
|
Loading…
Add table
Add a link
Reference in a new issue