42 lines
1.4 KiB
Python
Executable File
42 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Patch generated Picker Makefiles so CMake can be steered to Python 3.11.
|
|
|
|
Picker templates do not expose CMake cache arguments for the generated wrapper;
|
|
on macOS with multiple Homebrew Pythons, CMake otherwise picks python@3.14 and
|
|
produces a module that cannot be imported by Python 3.11. This patch is
|
|
idempotent and only touches generated files under the target DUT directory.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
|
|
def patch_file(path: Path) -> None:
|
|
text = path.read_text(encoding='utf-8')
|
|
original = text
|
|
text = text.replace(
|
|
'cmake . -Bbuild -DSIMULATOR=$(SIMULATOR) -DTRACE=$(TRACE) -DPROJECT=$(PROJECT) -DCMAKE_BUILD_PARALLEL=$(NPROC) -DRW_TYPE=$(RW_TYPE)',
|
|
'cmake . -Bbuild -DSIMULATOR=$(SIMULATOR) -DTRACE=$(TRACE) -DPROJECT=$(PROJECT) -DCMAKE_BUILD_PARALLEL=$(NPROC) -DRW_TYPE=$(RW_TYPE) $(CMAKE_ARGS)',
|
|
)
|
|
text = text.replace('cmake . -Bbuild\n', 'cmake . -Bbuild $(CMAKE_ARGS)\n')
|
|
if text != original:
|
|
path.write_text(text, encoding='utf-8')
|
|
print(f'patched {path}')
|
|
|
|
|
|
def main() -> int:
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument('target_dir', nargs='?', default='Cache')
|
|
args = ap.parse_args()
|
|
root = Path(args.target_dir)
|
|
for rel in ['Makefile', 'python/Makefile']:
|
|
p = root / rel
|
|
if p.exists():
|
|
patch_file(p)
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main())
|