mirror of
https://github.com/okhsunrog/vpnhide.git
synced 2026-05-03 00:52:41 +00:00
fix(build): port build scripts to Python to allow Windows contributors to build subprojects (#83)
* Rewrite build-version and all build-zip bash scripts to python * Add executable permissions to python build scripts * Use python build script for kmod in CI * Fix * Enhance kmod build script, add/fix docs, CI edits * Delete remaining build-zip bash scripts * Delete remaining build-zip bash scripts
This commit is contained in:
parent
4ad2ba8c2d
commit
cf4e72fa01
20 changed files with 490 additions and 206 deletions
24
scripts/build-version.py
Executable file
24
scripts/build-version.py
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Print the effective build version for vpnhide artifacts.
|
||||
|
||||
Used by every packaging step (module.prop, APK versionName, CI
|
||||
artifact names) so dev builds are unambiguously identifiable at a
|
||||
glance. Called from `app/build.gradle.kts` on every Gradle build, so
|
||||
stays on stdlib only — Gradle shouldn't need `uv` / external deps to
|
||||
assemble the APK.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
from build_lib import get_build_version
|
||||
|
||||
|
||||
def main() -> int:
|
||||
print(get_build_version())
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# Print the effective build version for vpnhide artifacts.
|
||||
#
|
||||
# - HEAD on a tag vX.Y.Z -> "X.Y.Z" (release build)
|
||||
# - N commits after tag vX.Y.Z -> "X.Y.Z-N-gSHA" (dev build)
|
||||
# - working tree dirty -> additional "-dirty" suffix
|
||||
# - no git / no matching tag -> falls back to VERSION file
|
||||
#
|
||||
# Used by every packaging step (module.prop, APK versionName, CI artifact
|
||||
# names) so dev builds are unambiguously identifiable at a glance.
|
||||
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
if git rev-parse --git-dir >/dev/null 2>&1 \
|
||||
&& raw=$(git describe --tags --match 'v*' --dirty 2>/dev/null); then
|
||||
echo "${raw#v}"
|
||||
else
|
||||
cat VERSION
|
||||
fi
|
||||
50
scripts/build_lib.py
Normal file
50
scripts/build_lib.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
"""Shared helpers for build scripts.
|
||||
|
||||
Used by kmod/build-zip.py, portshide/build-zip.py, and zygisk/build-zip.py.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def get_python_exe() -> str:
|
||||
"""Return 'python' on Windows, 'python3' elsewhere."""
|
||||
return "python" if os.name == "nt" else "python3"
|
||||
|
||||
|
||||
def make_zip(source_dir: Path, output_zip: Path) -> None:
|
||||
"""Create a zip archive from source_dir contents."""
|
||||
with zipfile.ZipFile(output_zip, "w", zipfile.ZIP_DEFLATED) as zf:
|
||||
for file_path in source_dir.rglob("*"):
|
||||
if file_path.is_file():
|
||||
arcname = file_path.relative_to(source_dir)
|
||||
zf.write(file_path, arcname)
|
||||
|
||||
|
||||
def get_build_version(repo_root: Path | None = None) -> str:
|
||||
"""Get the effective build version for vpnhide artifacts.
|
||||
|
||||
- HEAD on a tag vX.Y.Z -> "X.Y.Z" (release build)
|
||||
- N commits after tag vX.Y.Z -> "X.Y.Z-N-gSHA" (dev build)
|
||||
- working tree dirty -> additional "-dirty" suffix
|
||||
- no git / no matching tag -> falls back to VERSION file
|
||||
"""
|
||||
import subprocess
|
||||
|
||||
if repo_root is None:
|
||||
repo_root = Path(__file__).resolve().parent.parent
|
||||
|
||||
result = subprocess.run(
|
||||
["git", "describe", "--tags", "--match", "v*", "--dirty"],
|
||||
cwd=repo_root,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if result.returncode == 0 and result.stdout.strip():
|
||||
return result.stdout.strip().removeprefix("v")
|
||||
|
||||
version_file = repo_root / "VERSION"
|
||||
return version_file.read_text(encoding="utf-8").strip()
|
||||
Loading…
Add table
Add a link
Reference in a new issue