Skip to content

Commit

Permalink
setup: Improve detect_version()
Browse files Browse the repository at this point in the history
- Look for releng locally first, and in MESON_SOURCE_ROOT if set.
- If releng cannot be found, return "0.0.0".
  • Loading branch information
oleavr committed Apr 23, 2024
1 parent 3758894 commit 1f3ae46
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import subprocess
import sys
from typing import Iterator

from setuptools import setup
from setuptools.command.build_ext import build_ext
Expand All @@ -13,20 +14,40 @@
PACKAGE_DIR = Path(__file__).resolve().parent


def detect_version():
def detect_version() -> str:
pkg_info = PACKAGE_DIR / "PKG-INFO"
in_source_package = pkg_info.exists()
if in_source_package:
version_line = [line for line in pkg_info.read_text(encoding="utf-8").split("\n")
if line.startswith("Version: ")][0].strip()
version = version_line[9:]
else:
sys.path.insert(0, os.environ.get("MESON_SOURCE_ROOT", str(PACKAGE_DIR)))
from releng.frida_version import detect
version = detect(PACKAGE_DIR).name.replace("-dev.", ".dev")
releng_location = next(enumerate_releng_locations(), None)
if releng_location is not None:
sys.path.insert(0, str(releng_location.parent))
from releng.frida_version import detect
version = detect(PACKAGE_DIR).name.replace("-dev.", ".dev")
else:
version = "0.0.0"
return version


def enumerate_releng_locations() -> Iterator[Path]:
local_releng = PACKAGE_DIR / "releng"
if releng_location_exists(local_releng):
yield local_releng

source_root = os.environ.get("MESON_SOURCE_ROOT")
if source_root is not None:
parent_releng = Path(source_root) / "releng"
if releng_location_exists(parent_releng):
yield parent_releng


def releng_location_exists(location: Path) -> bool:
return (location / "frida_version.py").exists()


class FridaPrebuiltExt(build_ext):
def build_extension(self, ext):
target = self.get_ext_fullpath(ext.name)
Expand Down

0 comments on commit 1f3ae46

Please sign in to comment.