The Vivado install root differs per machine (C:\Xilinx here, D:\Xilinx on the box these skills were written on), so every hardcoded path was already wrong on this machine. - new fpga_flash/scripts/vivado_env.py: resolves --vivado-dir > env var > VIVADO_ROOT (falling back to VIVADO_PATH) from ~/skills_env.md - gen_mcs / program_flash / check_flash_csv: --vivado-dir now optional - fpga_update/gen_update_mcs.py: same precedence for --vivado - fpga_flash / smod_atsc_dev / vivado-prj-create SKILL.md: document the lookup instead of naming a drive letter - skills_env template: VIVADO_ROOT/VIVADO_PATH are now blanks to fill in, so a new machine can't inherit a wrong default Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Resolve the machine-local Vivado install path.
|
|
|
|
The install path differs per machine (C:\\Xilinx here, D:\\Xilinx elsewhere), so it
|
|
is never hardcoded in a skill. It lives in ~/skills_env.md, which stays out of git.
|
|
Precedence: explicit --vivado-dir > OS env var > ~/skills_env.md.
|
|
"""
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
|
|
def env_lookup(key, default=None):
|
|
"""Read KEY from the OS environment, else from a `KEY = value` line in
|
|
~/skills_env.md. Trailing `# comments` are stripped."""
|
|
v = os.environ.get(key)
|
|
if v:
|
|
return v
|
|
path = os.path.join(os.path.expanduser("~"), "skills_env.md")
|
|
try:
|
|
with open(path, encoding="utf-8") as f:
|
|
for line in f:
|
|
m = re.match(rf"\s*{re.escape(key)}\s*=\s*(.+?)\s*(?:#.*)?$", line)
|
|
if m:
|
|
val = m.group(1).strip()
|
|
# Placeholders like `<未安装>` mean "not configured on this machine".
|
|
if val and not val.startswith("<"):
|
|
return val
|
|
except OSError:
|
|
pass
|
|
return default
|
|
|
|
|
|
def resolve_vivado_dir(cli_value=None):
|
|
"""Vivado install ROOT (the dir containing bin/vivado.bat)."""
|
|
if cli_value:
|
|
return cli_value
|
|
root = env_lookup("VIVADO_ROOT")
|
|
if root:
|
|
return root
|
|
exe = env_lookup("VIVADO_PATH")
|
|
if exe:
|
|
# .../<root>/bin/vivado.bat -> <root>
|
|
return os.path.dirname(os.path.dirname(exe))
|
|
sys.exit(
|
|
"Vivado path not configured. Add `VIVADO_ROOT = <install root>` to "
|
|
"~/skills_env.md, set it as an env var, or pass --vivado-dir."
|
|
)
|
|
|
|
|
|
def resolve_vivado_exe(cli_value=None):
|
|
"""Full path to bin/vivado.bat."""
|
|
if cli_value:
|
|
return cli_value
|
|
exe = env_lookup("VIVADO_PATH")
|
|
if exe:
|
|
return exe
|
|
return os.path.join(resolve_vivado_dir(), "bin", "vivado.bat")
|