field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

fixture_alias_tool.py (1360B)


      1 """Native alias fixture: exercise argv0 without an unrelated Python child."""
      2 
      3 from __future__ import annotations
      4 
      5 import json
      6 from pathlib import Path
      7 
      8 from fixture_tool_dispatch import CompilerCommand, FixtureDispatchError
      9 
     10 
     11 def compile_alias_dispatch(root: Path, compiler: str | None, environment: dict):
     12     if compiler is None:
     13         raise FixtureDispatchError("native alias fixture compiler unavailable")
     14     source = root / "alias-dispatch.c"
     15     binary = root / "alias-dispatch"
     16     source.write_text(
     17         "#include <stdio.h>\n#include <string.h>\n"
     18         "int main(int argc, char **argv) {\n"
     19         "    if (argc != 1 || argv[0] == NULL) return 64;\n"
     20         "    const char *name = strrchr(argv[0], '/');\n"
     21         "    return puts(name ? name + 1 : argv[0]) < 0 ? 74 : 0;\n"
     22         "}\n"
     23     )
     24     command = CompilerCommand(
     25         [compiler, "-Wall", "-Wextra", "-Werror", "-o", str(binary), str(source)],
     26         root,
     27         env=environment,
     28     )
     29     try:
     30         result = command.execute()
     31     finally:
     32         (root / "alias-compilation.json").write_text(json.dumps(command.record))
     33     if (
     34         result.returncode
     35         or not command.record["wait_reaped"]
     36         or not command.record["group_absent"]
     37     ):
     38         raise FixtureDispatchError("native alias fixture compilation failed")
     39     return binary, command.record