Skip to content

Commit

Permalink
meson: Wire up project version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Apr 24, 2024
1 parent fd72a88 commit deab91a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions compat/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def call_internal_meson(argv, *args, **kwargs):
source_paths: set[Path] = set()
options: Optional[Sequence[str]] = None
build_env = scrub_environment(os.environ)
build_env["FRIDA_RELENG"] = str(releng_location)
for key, outputs in state.outputs.items():
if key == "bundle":
for o in outputs:
Expand Down
4 changes: 3 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
project('frida-core', 'vala', 'c', 'cpp',
version: '0.0.0',
version: run_command(find_program('python3'), files('tools' / 'detect-version.py'),
capture: true,
check: true).stdout().strip(),
meson_version: '>=1.1.0',
default_options: ['c_std=gnu99,c99', 'cpp_std=c++17'],
)
Expand Down
44 changes: 44 additions & 0 deletions tools/detect-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
from pathlib import Path
import sys
from typing import Iterator


REPO_DIR = Path(__file__).resolve().parent.parent


def detect_version() -> str:
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(REPO_DIR).name
else:
version = "0.0.0"
return version


def enumerate_releng_locations() -> Iterator[Path]:
val = os.environ.get("FRIDA_RELENG")
if val is not None:
custom_releng = Path(val)
if releng_location_exists(custom_releng):
yield custom_releng

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

local_releng = REPO_DIR / "releng"
if releng_location_exists(local_releng):
yield local_releng


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


if __name__ == "__main__":
print(detect_version())

0 comments on commit deab91a

Please sign in to comment.