From 4bb0d6ecd15d4e0230b9c44281377cd9315b432d Mon Sep 17 00:00:00 2001 From: xiaozhou233 Date: Mon, 19 Oct 2026 13:21:09 +0800 Subject: [PATCH] Feat: add a Linux packaging script - script: add package.sh, packing injector/libloader.so/libagent.so into dist/JuiceAgent_vX.Y.Z_x64_linux.tar.gz - docs: record the Linux package output in AGENTS.md --- AGENTS.md | 11 +++++++-- script/package.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100755 script/package.sh diff --git a/AGENTS.md b/AGENTS.md index 6cc415d..952b8a3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,8 +77,15 @@ The runner compiles the modules, refreshes `tests/resources` from `build/bin` (`script/package.bat` wraps this but ends with `pause`.) -`tests/`, `build/`, `dist/` and `*.log` are gitignored; `dist/*.zip` is **not** -committed. + On Linux, `script/package.sh` packs `injector`, `libloader.so` and + `libagent.so` into `dist/JuiceAgent_vX.Y.Z_x64_linux.tar.gz`: + + ```bash + ./script/package.sh + ``` + +`tests/`, `build/`, `dist/` and `*.log` are gitignored; `dist/*.zip` and +`dist/*.tar.gz` are **not** committed. ## Hard rules (each of these was learned by breaking the build or a target JVM) diff --git a/script/package.sh b/script/package.sh new file mode 100755 index 0000000..7e775d3 --- /dev/null +++ b/script/package.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# +# Linux counterpart of script/package.bat. +# +# Packs the Linux build in build/bin into +# dist/JuiceAgent_v.._x64_linux.tar.gz +# +# Usage: ./script/package.sh +# +set -euo pipefail + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_DIR="$(cd -- "${SCRIPT_DIR}/.." && pwd)" + +VERSION_FILE="${PROJECT_DIR}/Version.txt" +BIN_DIR="${PROJECT_DIR}/build/bin" +OUTPUT_DIR="${PROJECT_DIR}/dist" + +# Read one "Key = value" entry from Version.txt. +read_version_key() { + local key="$1" + sed -n -E "s/^[[:space:]]*${key}[[:space:]]*=[[:space:]]*([0-9]+)[[:space:]]*$/\1/p" \ + "${VERSION_FILE}" | head -n 1 +} + +if [[ ! -f "${VERSION_FILE}" ]]; then + echo "[ERROR] Version.txt not found: ${VERSION_FILE}" >&2 + exit 1 +fi + +VERSION_MAJOR="$(read_version_key Major)" +VERSION_MINOR="$(read_version_key Minor)" +VERSION_PATCH="$(read_version_key Patch)" + +if [[ -z "${VERSION_MAJOR}" || -z "${VERSION_MINOR}" || -z "${VERSION_PATCH}" ]]; then + echo "[ERROR] Invalid Version.txt: Major, Minor and Patch are required" >&2 + exit 1 +fi + +# Linux build artifacts (there is no libinject on this platform). +PACKAGE_FILES=( + injector + libloader.so + libagent.so +) + +for file_name in "${PACKAGE_FILES[@]}"; do + if [[ ! -f "${BIN_DIR}/${file_name}" ]]; then + echo "[ERROR] Required file not found: ${BIN_DIR}/${file_name}" >&2 + echo " Build first: cmake --preset release && cmake --build build" >&2 + exit 1 + fi +done + +mkdir -p "${OUTPUT_DIR}" + +OUTPUT_FILE="${OUTPUT_DIR}/JuiceAgent_v${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}_x64_linux.tar.gz" + +rm -f "${OUTPUT_FILE}" + +tar -czf "${OUTPUT_FILE}" -C "${BIN_DIR}" "${PACKAGE_FILES[@]}" + +echo "[SUCCESS] Package created: ${OUTPUT_FILE}"