pdksetup 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pdksetup/__init__.py +0 -0
- pdksetup/cli.py +684 -0
- pdksetup/config.py +80 -0
- pdksetup/installers/__init__.py +0 -0
- pdksetup/installers/base.py +101 -0
- pdksetup/installers/custom.py +45 -0
- pdksetup/installers/iic.py +375 -0
- pdksetup/installers/volare.py +33 -0
- pdksetup/registry.py +319 -0
- pdksetup/state.py +69 -0
- pdksetup/updater.py +115 -0
- pdksetup-0.3.0.dist-info/METADATA +402 -0
- pdksetup-0.3.0.dist-info/RECORD +17 -0
- pdksetup-0.3.0.dist-info/WHEEL +5 -0
- pdksetup-0.3.0.dist-info/entry_points.txt +2 -0
- pdksetup-0.3.0.dist-info/licenses/LICENSE +201 -0
- pdksetup-0.3.0.dist-info/top_level.txt +1 -0
pdksetup/__init__.py
ADDED
|
File without changes
|
pdksetup/cli.py
ADDED
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import click
|
|
10
|
+
from rich.console import Console
|
|
11
|
+
from rich.table import Table
|
|
12
|
+
|
|
13
|
+
from pdksetup.config import CONFIG_PATH, Config
|
|
14
|
+
from pdksetup.installers.base import (
|
|
15
|
+
INSTALL_DEPS,
|
|
16
|
+
RUNTIME_TOOL_HINTS,
|
|
17
|
+
check_deps,
|
|
18
|
+
check_runtime_tools,
|
|
19
|
+
tool_major_version,
|
|
20
|
+
)
|
|
21
|
+
from pdksetup.installers.custom import CustomInstaller
|
|
22
|
+
from pdksetup.installers.iic import IICRecipeInstaller
|
|
23
|
+
from pdksetup.installers.volare import VolareInstaller
|
|
24
|
+
from pdksetup.registry import REGISTRY, REGISTRY_BY_NAME, PDKEntry
|
|
25
|
+
from pdksetup.state import State
|
|
26
|
+
from pdksetup.updater import Updater
|
|
27
|
+
|
|
28
|
+
# On a real terminal, let Rich auto-fit. When stdout is piped or captured
|
|
29
|
+
# (CI, CliRunner, redirected output) Rich would otherwise default to 80
|
|
30
|
+
# columns and truncate PDK names mid-string with an ellipsis, so we widen.
|
|
31
|
+
console = Console(width=None if sys.stdout.isatty() else 200)
|
|
32
|
+
|
|
33
|
+
_PDK_ROOT_OPTION = click.option(
|
|
34
|
+
"--pdk-root",
|
|
35
|
+
type=click.Path(),
|
|
36
|
+
default=None,
|
|
37
|
+
help="Override PDK_ROOT for this invocation.",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
_CONFIG_OPTION = click.option(
|
|
41
|
+
"--config",
|
|
42
|
+
"config_path",
|
|
43
|
+
type=click.Path(),
|
|
44
|
+
default=None,
|
|
45
|
+
help="Use a different config.toml instead of ~/.config/pdksetup/config.toml.",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
_HERE_OPTION = click.option(
|
|
49
|
+
"--here",
|
|
50
|
+
is_flag=True,
|
|
51
|
+
default=False,
|
|
52
|
+
help="Use the current working directory as pdk_root (shorthand for --pdk-root $PWD).",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _resolve_pdk_root(
|
|
57
|
+
ctx: click.Context, pdk_root: str | None, here: bool = False
|
|
58
|
+
) -> str | None:
|
|
59
|
+
"""Resolution order: --here > --pdk-root (subcommand) > --pdk-root (group)."""
|
|
60
|
+
if here:
|
|
61
|
+
return os.getcwd()
|
|
62
|
+
return pdk_root if pdk_root is not None else ctx.obj.get("pdk_root_flag")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _resolve_config_path(ctx: click.Context, config_path: str | None) -> Path | None:
|
|
66
|
+
"""Subcommand --config wins over group --config. Returns Path or None."""
|
|
67
|
+
chosen = config_path if config_path is not None else ctx.obj.get("config_path")
|
|
68
|
+
return Path(chosen) if chosen is not None else None
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _ensure_post_install_links(pdk: PDKEntry, pdk_root: Path) -> None:
|
|
72
|
+
"""Create or repair the registry-declared symlinks under pdk_root.
|
|
73
|
+
|
|
74
|
+
A correct link is left alone; a wrong or dangling symlink is replaced.
|
|
75
|
+
Anything that isn't a symlink is never clobbered — warn and move on.
|
|
76
|
+
"""
|
|
77
|
+
for link_name, target in pdk.post_install_links:
|
|
78
|
+
link = pdk_root / link_name
|
|
79
|
+
if link.is_symlink():
|
|
80
|
+
if os.readlink(link) == target:
|
|
81
|
+
continue
|
|
82
|
+
link.unlink()
|
|
83
|
+
elif link.exists():
|
|
84
|
+
console.print(
|
|
85
|
+
f"[yellow]Warning:[/yellow] {link} exists but is not a symlink "
|
|
86
|
+
f"(expected a link to {target}); leaving it untouched. Upstream "
|
|
87
|
+
f"tooling may not resolve $PDK_ROOT/{link_name} correctly."
|
|
88
|
+
)
|
|
89
|
+
continue
|
|
90
|
+
os.symlink(target, link)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _post_install_links_ok(pdk: PDKEntry, pdk_root: Path) -> bool:
|
|
94
|
+
"""True when every declared link exists, points as declared, and resolves."""
|
|
95
|
+
for link_name, target in pdk.post_install_links:
|
|
96
|
+
link = pdk_root / link_name
|
|
97
|
+
if not (link.is_symlink() and os.readlink(link) == target and link.exists()):
|
|
98
|
+
return False
|
|
99
|
+
return True
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _missing_post_install_artifacts(pdk: PDKEntry, dest: Path) -> list[str]:
|
|
103
|
+
"""Relative paths from post_install_artifacts that don't exist under dest."""
|
|
104
|
+
return [a for a in pdk.post_install_artifacts if not (dest / a).exists()]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _post_install_label(pdk: PDKEntry) -> str:
|
|
108
|
+
return pdk.post_install_label or "post-install artifacts"
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _find_build_tool(pdk: PDKEntry) -> str | None:
|
|
112
|
+
"""First tool from post_install_build_requires found on PATH, if any."""
|
|
113
|
+
return next(
|
|
114
|
+
(t for t in pdk.post_install_build_requires if shutil.which(t)), None
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _run_post_install_build(pdk: PDKEntry, dest: Path) -> None:
|
|
119
|
+
"""Build the PDK's post-install artifacts if a required tool is on PATH.
|
|
120
|
+
|
|
121
|
+
Silently skips when no tool from post_install_build_requires is found
|
|
122
|
+
(the post-install note then guides the user). Build failures warn but
|
|
123
|
+
never block the install — success is judged afterwards by re-checking
|
|
124
|
+
the artifacts, not by trusting the exit code alone.
|
|
125
|
+
"""
|
|
126
|
+
tool = _find_build_tool(pdk)
|
|
127
|
+
if pdk.post_install_build_requires and tool is None:
|
|
128
|
+
return
|
|
129
|
+
label = _post_install_label(pdk)
|
|
130
|
+
console.print(f"Compiling {label}" + (f" (using {tool})..." if tool else "..."))
|
|
131
|
+
cwd = dest / pdk.post_install_build_cwd if pdk.post_install_build_cwd else dest
|
|
132
|
+
try:
|
|
133
|
+
proc = subprocess.run(list(pdk.post_install_build_cmd), cwd=cwd)
|
|
134
|
+
except OSError as exc:
|
|
135
|
+
console.print(
|
|
136
|
+
f"[yellow]Warning:[/yellow] could not run the {label} build "
|
|
137
|
+
f"({exc}); follow the manual steps below."
|
|
138
|
+
)
|
|
139
|
+
return
|
|
140
|
+
if proc.returncode != 0:
|
|
141
|
+
console.print(
|
|
142
|
+
f"[yellow]Warning:[/yellow] {label} build exited with code "
|
|
143
|
+
f"{proc.returncode}; follow the manual steps below."
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _pdk_flags(pdk: PDKEntry, *, installed: bool, pdk_root: Path) -> str:
|
|
148
|
+
"""Flags-column text shared by `status` and `check-updates`."""
|
|
149
|
+
parts = []
|
|
150
|
+
if pdk.experimental:
|
|
151
|
+
parts.append("EXPERIMENTAL")
|
|
152
|
+
if not pdk.fabricatable:
|
|
153
|
+
parts.append("SIMULATION")
|
|
154
|
+
if installed and pdk.post_install_artifacts:
|
|
155
|
+
label = _post_install_label(pdk)
|
|
156
|
+
dest = pdk_root / pdk.name
|
|
157
|
+
if _missing_post_install_artifacts(pdk, dest):
|
|
158
|
+
parts.append(f"[yellow]{label}: MISSING[/yellow]")
|
|
159
|
+
elif _post_install_artifacts_stale(pdk, dest):
|
|
160
|
+
parts.append(f"[yellow]{label}: STALE[/yellow]")
|
|
161
|
+
else:
|
|
162
|
+
parts.append(f"{label}: compiled")
|
|
163
|
+
if installed and pdk.post_install_links and not _post_install_links_ok(pdk, pdk_root):
|
|
164
|
+
for link_name, _ in pdk.post_install_links:
|
|
165
|
+
parts.append(
|
|
166
|
+
f"[yellow]{link_name} link: MISSING (reinstall to fix)[/yellow]"
|
|
167
|
+
)
|
|
168
|
+
return " ".join(parts)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _post_install_artifacts_stale(pdk: PDKEntry, dest: Path) -> bool:
|
|
172
|
+
"""True when any source file is newer than the oldest artifact.
|
|
173
|
+
|
|
174
|
+
Call only when no artifacts are missing. Sources that don't exist on disk
|
|
175
|
+
contribute nothing, so an absent source tree never reports stale.
|
|
176
|
+
"""
|
|
177
|
+
if not pdk.post_install_sources or not pdk.post_install_artifacts:
|
|
178
|
+
return False
|
|
179
|
+
source_mtimes = []
|
|
180
|
+
for src in pdk.post_install_sources:
|
|
181
|
+
path = dest / src
|
|
182
|
+
if path.is_file():
|
|
183
|
+
source_mtimes.append(path.stat().st_mtime)
|
|
184
|
+
elif path.is_dir():
|
|
185
|
+
source_mtimes.extend(
|
|
186
|
+
f.stat().st_mtime for f in path.rglob("*") if f.is_file()
|
|
187
|
+
)
|
|
188
|
+
if not source_mtimes:
|
|
189
|
+
return False
|
|
190
|
+
oldest_artifact = min((dest / a).stat().st_mtime for a in pdk.post_install_artifacts)
|
|
191
|
+
return max(source_mtimes) > oldest_artifact
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _print_runtime_tools(pdk: PDKEntry) -> None:
|
|
195
|
+
"""Render the runtime-tools availability block printed after install."""
|
|
196
|
+
if not pdk.runtime_tools:
|
|
197
|
+
return
|
|
198
|
+
console.print("")
|
|
199
|
+
console.print("Runtime tools for this PDK:")
|
|
200
|
+
missing: list[str] = []
|
|
201
|
+
minimums = {tool: (major, why) for tool, major, why in pdk.runtime_tool_min_versions}
|
|
202
|
+
for name, path in check_runtime_tools(pdk.runtime_tools):
|
|
203
|
+
if path and name in minimums:
|
|
204
|
+
major, why = minimums[name]
|
|
205
|
+
found = tool_major_version(name, path)
|
|
206
|
+
if found is not None and found < major:
|
|
207
|
+
console.print(
|
|
208
|
+
f" [red]✗[/red] {name} ({path} is {name}-{found}; "
|
|
209
|
+
f"needs ≥ {major} for {why}; distro packages are often older — "
|
|
210
|
+
f"see the README's \"Getting a newer {name}\")"
|
|
211
|
+
)
|
|
212
|
+
missing.append(name)
|
|
213
|
+
continue
|
|
214
|
+
label = f"{path}, {name}-{found}" if found is not None else path
|
|
215
|
+
console.print(f" [green]✓[/green] {name} [dim]({label})[/dim]")
|
|
216
|
+
elif path:
|
|
217
|
+
console.print(f" [green]✓[/green] {name} [dim]({path})[/dim]")
|
|
218
|
+
else:
|
|
219
|
+
hint = RUNTIME_TOOL_HINTS.get(name)
|
|
220
|
+
suffix = f" — {hint}" if hint else ""
|
|
221
|
+
console.print(f" [red]✗[/red] {name} (not found{suffix})")
|
|
222
|
+
missing.append(name)
|
|
223
|
+
if missing:
|
|
224
|
+
console.print(
|
|
225
|
+
"[dim]Missing tools don't block the install; they only limit "
|
|
226
|
+
"what you can do with this PDK. See IIC-OSIC-TOOLS for a "
|
|
227
|
+
"container with the full stack.[/dim]"
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _install_and_record(
|
|
232
|
+
pdk: PDKEntry, *, config: Config, state: State, version: str | None
|
|
233
|
+
) -> str:
|
|
234
|
+
"""Install a single PDK, record state, print runtime-tools info, return version."""
|
|
235
|
+
if pdk.install_strategy == "volare":
|
|
236
|
+
installer = VolareInstaller()
|
|
237
|
+
installed_version = installer.install(
|
|
238
|
+
pdk.name, pdk_root=config.pdk_root, version=version
|
|
239
|
+
)
|
|
240
|
+
state.record(pdk.name, version=installed_version)
|
|
241
|
+
elif pdk.install_strategy == "custom":
|
|
242
|
+
# Pick the ref strategy that matches what Updater will compare against.
|
|
243
|
+
# Mismatches caused check-updates to perpetually report "update available".
|
|
244
|
+
ref_strategy = "commit" if pdk.version_source == "github_commit" else "tag"
|
|
245
|
+
installer = CustomInstaller()
|
|
246
|
+
installed_ref = installer.install(
|
|
247
|
+
pdk.name,
|
|
248
|
+
source_url=pdk.source_url,
|
|
249
|
+
pdk_root=config.pdk_root,
|
|
250
|
+
ref_strategy=ref_strategy,
|
|
251
|
+
)
|
|
252
|
+
if pdk.version_source == "github_commit":
|
|
253
|
+
state.record(pdk.name, version=None, commit=installed_ref)
|
|
254
|
+
else:
|
|
255
|
+
state.record(pdk.name, version=installed_ref)
|
|
256
|
+
installed_version = installed_ref
|
|
257
|
+
elif pdk.install_strategy == "iic_recipe":
|
|
258
|
+
installed_ref, fingerprint = IICRecipeInstaller().install(
|
|
259
|
+
pdk.name,
|
|
260
|
+
recipe=pdk.iic_recipe,
|
|
261
|
+
pdk_root=config.pdk_root,
|
|
262
|
+
artifacts=pdk.post_install_artifacts,
|
|
263
|
+
version=version,
|
|
264
|
+
)
|
|
265
|
+
state.record(pdk.name, version=None, commit=installed_ref, fingerprint=fingerprint)
|
|
266
|
+
installed_version = installed_ref
|
|
267
|
+
else:
|
|
268
|
+
raise ValueError(f"Unknown install_strategy {pdk.install_strategy!r}")
|
|
269
|
+
|
|
270
|
+
console.print(f"[green]✓ {pdk.display_name} installed.[/green]")
|
|
271
|
+
_ensure_post_install_links(pdk, Path(config.pdk_root))
|
|
272
|
+
_print_runtime_tools(pdk)
|
|
273
|
+
if pdk.post_install_note:
|
|
274
|
+
dest = Path(config.pdk_root) / pdk.name
|
|
275
|
+
|
|
276
|
+
def _artifact_state() -> tuple[bool, bool]:
|
|
277
|
+
# No declared artifacts means we can't verify — treat as missing
|
|
278
|
+
# so the note is always shown.
|
|
279
|
+
m = not pdk.post_install_artifacts or bool(
|
|
280
|
+
_missing_post_install_artifacts(pdk, dest)
|
|
281
|
+
)
|
|
282
|
+
return m, (not m and _post_install_artifacts_stale(pdk, dest))
|
|
283
|
+
|
|
284
|
+
missing, stale = _artifact_state()
|
|
285
|
+
if (missing or stale) and pdk.post_install_build_cmd:
|
|
286
|
+
_run_post_install_build(pdk, dest)
|
|
287
|
+
missing, stale = _artifact_state()
|
|
288
|
+
note = pdk.post_install_note.format(dest=dest, root=Path(config.pdk_root))
|
|
289
|
+
if missing or stale:
|
|
290
|
+
console.print("")
|
|
291
|
+
if stale:
|
|
292
|
+
console.print(
|
|
293
|
+
f"[yellow]Note:[/yellow] The compiled {_post_install_label(pdk)} "
|
|
294
|
+
"are older than the sources they were built from (likely a "
|
|
295
|
+
"PDK update) — rebuild them:"
|
|
296
|
+
)
|
|
297
|
+
console.print(note)
|
|
298
|
+
else:
|
|
299
|
+
console.print(f"[yellow]Note:[/yellow] {note}")
|
|
300
|
+
else:
|
|
301
|
+
if pdk.post_install_label:
|
|
302
|
+
console.print(
|
|
303
|
+
f" [green]✓[/green] {pdk.post_install_label}: compiled"
|
|
304
|
+
)
|
|
305
|
+
if pdk.post_install_ready_note:
|
|
306
|
+
console.print(
|
|
307
|
+
pdk.post_install_ready_note.format(
|
|
308
|
+
dest=dest, root=Path(config.pdk_root)
|
|
309
|
+
)
|
|
310
|
+
)
|
|
311
|
+
return installed_version
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
@click.group()
|
|
315
|
+
@click.option("--pdk-root", type=click.Path(), default=None, help="Override PDK_ROOT.")
|
|
316
|
+
@click.option(
|
|
317
|
+
"--config",
|
|
318
|
+
"config_path",
|
|
319
|
+
type=click.Path(),
|
|
320
|
+
default=None,
|
|
321
|
+
help="Use a different config.toml instead of ~/.config/pdksetup/config.toml.",
|
|
322
|
+
)
|
|
323
|
+
@click.pass_context
|
|
324
|
+
def main(ctx: click.Context, pdk_root: str | None, config_path: str | None) -> None:
|
|
325
|
+
"""pdksetup — install and manage open-source PDKs."""
|
|
326
|
+
ctx.ensure_object(dict)
|
|
327
|
+
ctx.obj["pdk_root_flag"] = pdk_root
|
|
328
|
+
ctx.obj["config_path"] = config_path
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
@main.command()
|
|
332
|
+
@click.argument("pdk_name", required=False)
|
|
333
|
+
@click.option("--all", "install_all", is_flag=True, help="Install every fabricatable PDK in the registry.")
|
|
334
|
+
@click.option("--skip-experimental", is_flag=True, help="Skip experimental PDKs when using --all.")
|
|
335
|
+
@click.option(
|
|
336
|
+
"--include-simulation",
|
|
337
|
+
is_flag=True,
|
|
338
|
+
help="Include simulation-only PDKs (ASAP7, ASAP5, FreePDK45) when using --all.",
|
|
339
|
+
)
|
|
340
|
+
@click.option(
|
|
341
|
+
"--version",
|
|
342
|
+
default=None,
|
|
343
|
+
help="Version to install: a volare version (sky130, gf180mcu) or an "
|
|
344
|
+
"IIC-OSIC-TOOLS commit/branch (asap7).",
|
|
345
|
+
)
|
|
346
|
+
@_PDK_ROOT_OPTION
|
|
347
|
+
@_HERE_OPTION
|
|
348
|
+
@_CONFIG_OPTION
|
|
349
|
+
@click.pass_context
|
|
350
|
+
def install(
|
|
351
|
+
ctx: click.Context,
|
|
352
|
+
pdk_name: str | None,
|
|
353
|
+
install_all: bool,
|
|
354
|
+
skip_experimental: bool,
|
|
355
|
+
include_simulation: bool,
|
|
356
|
+
version: str | None,
|
|
357
|
+
pdk_root: str | None,
|
|
358
|
+
here: bool,
|
|
359
|
+
config_path: str | None,
|
|
360
|
+
) -> None:
|
|
361
|
+
"""Install a PDK (or all PDKs with --all)."""
|
|
362
|
+
cfg = Config.load(
|
|
363
|
+
pdk_root_flag=_resolve_pdk_root(ctx, pdk_root, here=here),
|
|
364
|
+
config_path=_resolve_config_path(ctx, config_path),
|
|
365
|
+
)
|
|
366
|
+
state = State(cfg.pdk_root)
|
|
367
|
+
|
|
368
|
+
dep = check_deps(INSTALL_DEPS, [])
|
|
369
|
+
if not dep.ok:
|
|
370
|
+
raise click.ClickException(
|
|
371
|
+
f"Missing required dependencies: {', '.join(dep.missing_required)}"
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
if install_all:
|
|
375
|
+
targets = [
|
|
376
|
+
p for p in REGISTRY
|
|
377
|
+
if not (skip_experimental and p.experimental)
|
|
378
|
+
and (include_simulation or p.fabricatable)
|
|
379
|
+
]
|
|
380
|
+
else:
|
|
381
|
+
if not pdk_name:
|
|
382
|
+
raise click.ClickException("Provide a PDK name or use --all.")
|
|
383
|
+
pdk = REGISTRY_BY_NAME.get(pdk_name)
|
|
384
|
+
if pdk is None:
|
|
385
|
+
raise click.ClickException(
|
|
386
|
+
f"Unknown PDK: {pdk_name!r}. Run `pdk status` to list available PDKs."
|
|
387
|
+
)
|
|
388
|
+
targets = [pdk]
|
|
389
|
+
|
|
390
|
+
if version is not None and any(
|
|
391
|
+
p.install_strategy not in ("volare", "iic_recipe") for p in targets
|
|
392
|
+
):
|
|
393
|
+
raise click.UsageError(
|
|
394
|
+
"--version only supported for volare-installed PDKs (sky130, gf180mcu) "
|
|
395
|
+
"and asap7 (an IIC-OSIC-TOOLS commit or branch)"
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
failures: list[tuple[PDKEntry, Exception]] = []
|
|
399
|
+
for pdk in targets:
|
|
400
|
+
console.print(f"[bold]Installing {pdk.name}[/bold] ({pdk.display_name})...")
|
|
401
|
+
try:
|
|
402
|
+
_install_and_record(pdk, config=cfg, state=state, version=version)
|
|
403
|
+
except Exception as exc: # noqa: BLE001 - surface every failure
|
|
404
|
+
failures.append((pdk, exc))
|
|
405
|
+
console.print(
|
|
406
|
+
f"[red]✗ {pdk.display_name} failed:[/red] "
|
|
407
|
+
f"{type(exc).__name__}: {exc}"
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
if failures:
|
|
411
|
+
summary = ", ".join(
|
|
412
|
+
f"{pdk.name} ({type(exc).__name__}: {exc})" for pdk, exc in failures
|
|
413
|
+
)
|
|
414
|
+
raise click.ClickException(f"{len(failures)} install(s) failed: {summary}")
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
@main.command()
|
|
418
|
+
@click.argument("pdk_name")
|
|
419
|
+
@click.option("--yes", is_flag=True, default=False, help="Skip the confirmation prompt.")
|
|
420
|
+
@_PDK_ROOT_OPTION
|
|
421
|
+
@_HERE_OPTION
|
|
422
|
+
@_CONFIG_OPTION
|
|
423
|
+
@click.pass_context
|
|
424
|
+
def uninstall(
|
|
425
|
+
ctx: click.Context,
|
|
426
|
+
pdk_name: str,
|
|
427
|
+
yes: bool,
|
|
428
|
+
pdk_root: str | None,
|
|
429
|
+
here: bool,
|
|
430
|
+
config_path: str | None,
|
|
431
|
+
) -> None:
|
|
432
|
+
"""Remove an installed PDK: its directory, maintained symlinks, and state."""
|
|
433
|
+
cfg = Config.load(
|
|
434
|
+
pdk_root_flag=_resolve_pdk_root(ctx, pdk_root, here=here),
|
|
435
|
+
config_path=_resolve_config_path(ctx, config_path),
|
|
436
|
+
)
|
|
437
|
+
state = State(cfg.pdk_root)
|
|
438
|
+
|
|
439
|
+
pdk = REGISTRY_BY_NAME.get(pdk_name)
|
|
440
|
+
if pdk is None:
|
|
441
|
+
raise click.ClickException(
|
|
442
|
+
f"Unknown PDK: {pdk_name!r}. Run `pdk status` to list available PDKs."
|
|
443
|
+
)
|
|
444
|
+
if pdk.install_strategy == "volare":
|
|
445
|
+
raise click.ClickException(
|
|
446
|
+
f"{pdk.name} is managed by volare, which owns its files under "
|
|
447
|
+
f"{cfg.volare_root} — remove it with `volare rm` instead."
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
dest = Path(cfg.pdk_root) / pdk.name
|
|
451
|
+
if not state.is_installed(pdk.name) and not dest.exists():
|
|
452
|
+
console.print(f"{pdk.name} is not installed at {cfg.pdk_root}; nothing to do.")
|
|
453
|
+
return
|
|
454
|
+
|
|
455
|
+
if not yes:
|
|
456
|
+
click.confirm(
|
|
457
|
+
f"Remove {dest}, its maintained symlinks, and its state entry?",
|
|
458
|
+
abort=True,
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
if dest.exists():
|
|
462
|
+
shutil.rmtree(dest)
|
|
463
|
+
for link_name, target in pdk.post_install_links:
|
|
464
|
+
link = Path(cfg.pdk_root) / link_name
|
|
465
|
+
# Only remove symlinks we maintain — never a real file or directory.
|
|
466
|
+
if link.is_symlink() and os.readlink(link) == target:
|
|
467
|
+
link.unlink()
|
|
468
|
+
state.remove(pdk.name)
|
|
469
|
+
console.print(f"[green]✓ {pdk.display_name} removed.[/green]")
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
@main.command()
|
|
473
|
+
@click.argument("pdk_name", required=False)
|
|
474
|
+
@_PDK_ROOT_OPTION
|
|
475
|
+
@_HERE_OPTION
|
|
476
|
+
@_CONFIG_OPTION
|
|
477
|
+
@click.pass_context
|
|
478
|
+
def status(
|
|
479
|
+
ctx: click.Context,
|
|
480
|
+
pdk_name: str | None,
|
|
481
|
+
pdk_root: str | None,
|
|
482
|
+
here: bool,
|
|
483
|
+
config_path: str | None,
|
|
484
|
+
) -> None:
|
|
485
|
+
"""Show installed status for every known PDK (or a single PDK)."""
|
|
486
|
+
cfg = Config.load(
|
|
487
|
+
pdk_root_flag=_resolve_pdk_root(ctx, pdk_root, here=here),
|
|
488
|
+
config_path=_resolve_config_path(ctx, config_path),
|
|
489
|
+
)
|
|
490
|
+
state = State(cfg.pdk_root)
|
|
491
|
+
|
|
492
|
+
if pdk_name:
|
|
493
|
+
pdk = REGISTRY_BY_NAME.get(pdk_name)
|
|
494
|
+
if pdk is None:
|
|
495
|
+
raise click.ClickException(
|
|
496
|
+
f"Unknown PDK: {pdk_name!r}. Run `pdk status` to list available PDKs."
|
|
497
|
+
)
|
|
498
|
+
targets = [pdk]
|
|
499
|
+
else:
|
|
500
|
+
targets = list(REGISTRY)
|
|
501
|
+
|
|
502
|
+
console.print(f"[dim]Scanning:[/dim] {cfg.pdk_root}")
|
|
503
|
+
|
|
504
|
+
table = Table(title="PDK Status")
|
|
505
|
+
table.add_column("PDK")
|
|
506
|
+
table.add_column("Display Name")
|
|
507
|
+
table.add_column("Node")
|
|
508
|
+
table.add_column("Installed")
|
|
509
|
+
table.add_column("Version")
|
|
510
|
+
table.add_column("Flags", overflow="fold", no_wrap=False)
|
|
511
|
+
|
|
512
|
+
for pdk in targets:
|
|
513
|
+
installed = state.is_installed(pdk.name)
|
|
514
|
+
version = state.get_version(pdk.name) or state.get_commit(pdk.name) or "-"
|
|
515
|
+
flags = _pdk_flags(pdk, installed=installed, pdk_root=Path(cfg.pdk_root))
|
|
516
|
+
table.add_row(
|
|
517
|
+
pdk.name,
|
|
518
|
+
pdk.display_name,
|
|
519
|
+
pdk.node,
|
|
520
|
+
"yes" if installed else "no",
|
|
521
|
+
version if installed else "-",
|
|
522
|
+
flags,
|
|
523
|
+
)
|
|
524
|
+
|
|
525
|
+
console.print(table)
|
|
526
|
+
|
|
527
|
+
if not any(state.is_installed(p.name) for p in targets):
|
|
528
|
+
console.print(
|
|
529
|
+
"[dim]No installs recorded at this root. If you installed elsewhere, "
|
|
530
|
+
"point at it with one of:[/dim]\n"
|
|
531
|
+
" [dim]pdk status --pdk-root /path/to/root[/dim]\n"
|
|
532
|
+
" [dim]PDK_ROOT=/path/to/root pdk status[/dim]\n"
|
|
533
|
+
" [dim]pdk config set pdk_root /path/to/root[/dim]"
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
@main.command("check-updates")
|
|
538
|
+
@click.argument("pdk_name", required=False)
|
|
539
|
+
@_PDK_ROOT_OPTION
|
|
540
|
+
@_HERE_OPTION
|
|
541
|
+
@_CONFIG_OPTION
|
|
542
|
+
@click.pass_context
|
|
543
|
+
def check_updates(
|
|
544
|
+
ctx: click.Context,
|
|
545
|
+
pdk_name: str | None,
|
|
546
|
+
pdk_root: str | None,
|
|
547
|
+
here: bool,
|
|
548
|
+
config_path: str | None,
|
|
549
|
+
) -> None:
|
|
550
|
+
"""Check for available updates for installed PDKs."""
|
|
551
|
+
cfg = Config.load(
|
|
552
|
+
pdk_root_flag=_resolve_pdk_root(ctx, pdk_root, here=here),
|
|
553
|
+
config_path=_resolve_config_path(ctx, config_path),
|
|
554
|
+
)
|
|
555
|
+
state = State(cfg.pdk_root)
|
|
556
|
+
updater = Updater()
|
|
557
|
+
|
|
558
|
+
if pdk_name:
|
|
559
|
+
pdk = REGISTRY_BY_NAME.get(pdk_name)
|
|
560
|
+
if pdk is None:
|
|
561
|
+
raise click.ClickException(f"Unknown PDK: {pdk_name!r}.")
|
|
562
|
+
targets = [pdk]
|
|
563
|
+
else:
|
|
564
|
+
installed_names = set(state.list_installed())
|
|
565
|
+
targets = [p for p in REGISTRY if p.name in installed_names]
|
|
566
|
+
|
|
567
|
+
console.print(f"[dim]Scanning:[/dim] {cfg.pdk_root}")
|
|
568
|
+
|
|
569
|
+
if not targets:
|
|
570
|
+
console.print(
|
|
571
|
+
"No PDKs installed at this root. Run `pdk install <name>` first, "
|
|
572
|
+
"or point at a different root with `--pdk-root /path`."
|
|
573
|
+
)
|
|
574
|
+
return
|
|
575
|
+
|
|
576
|
+
table = Table(title="Update Check")
|
|
577
|
+
table.add_column("PDK")
|
|
578
|
+
table.add_column("Installed")
|
|
579
|
+
table.add_column("Latest")
|
|
580
|
+
table.add_column("Status")
|
|
581
|
+
table.add_column("Flags", overflow="fold", no_wrap=False)
|
|
582
|
+
|
|
583
|
+
recompile_after_update: list[PDKEntry] = []
|
|
584
|
+
recipe_updates: list[PDKEntry] = []
|
|
585
|
+
for pdk in targets:
|
|
586
|
+
installed = state.is_installed(pdk.name)
|
|
587
|
+
flag = _pdk_flags(pdk, installed=installed, pdk_root=Path(cfg.pdk_root))
|
|
588
|
+
if not installed:
|
|
589
|
+
table.add_row(pdk.name, "-", "-", "not installed", flag)
|
|
590
|
+
continue
|
|
591
|
+
result = updater.check(pdk, state=state)
|
|
592
|
+
if result.update_available:
|
|
593
|
+
status_text = "[yellow]update available[/yellow]"
|
|
594
|
+
dest = Path(cfg.pdk_root) / pdk.name
|
|
595
|
+
if pdk.install_strategy == "iic_recipe":
|
|
596
|
+
# A reinstall rebuilds everything, so no recompile hint.
|
|
597
|
+
recipe_updates.append(pdk)
|
|
598
|
+
elif pdk.post_install_artifacts and not _missing_post_install_artifacts(
|
|
599
|
+
pdk, dest
|
|
600
|
+
):
|
|
601
|
+
recompile_after_update.append(pdk)
|
|
602
|
+
elif result.latest is None:
|
|
603
|
+
status_text = "unknown"
|
|
604
|
+
else:
|
|
605
|
+
status_text = "up to date"
|
|
606
|
+
table.add_row(
|
|
607
|
+
pdk.name,
|
|
608
|
+
result.installed or "-",
|
|
609
|
+
result.latest or "-",
|
|
610
|
+
status_text,
|
|
611
|
+
flag,
|
|
612
|
+
)
|
|
613
|
+
|
|
614
|
+
console.print(table)
|
|
615
|
+
|
|
616
|
+
for pdk in recipe_updates:
|
|
617
|
+
recipe = pdk.iic_recipe
|
|
618
|
+
verified = (recipe.pin or "")[:8]
|
|
619
|
+
console.print(
|
|
620
|
+
f"[dim]{pdk.name}: the IIC-OSIC-TOOLS recipe on {recipe.branch} has "
|
|
621
|
+
f"changed since your install. `pdk install {pdk.name}` installs the "
|
|
622
|
+
f"commit this pdksetup verified ({verified}); to take the newer recipe, "
|
|
623
|
+
f"run `pdk install {pdk.name} --version {recipe.branch}` (not yet "
|
|
624
|
+
f"verified by pdksetup).[/dim]"
|
|
625
|
+
)
|
|
626
|
+
|
|
627
|
+
for pdk in recompile_after_update:
|
|
628
|
+
console.print(
|
|
629
|
+
f"[dim]Updating {pdk.name} may change the sources its "
|
|
630
|
+
f"{_post_install_label(pdk)} were built from. After updating, run "
|
|
631
|
+
f"`pdk status {pdk.name}` and recompile if they show as STALE.[/dim]"
|
|
632
|
+
)
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
@main.group()
|
|
636
|
+
def config() -> None:
|
|
637
|
+
"""Show or modify pdksetup configuration."""
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
@config.command("show")
|
|
641
|
+
@_PDK_ROOT_OPTION
|
|
642
|
+
@_CONFIG_OPTION
|
|
643
|
+
@click.pass_context
|
|
644
|
+
def config_show(
|
|
645
|
+
ctx: click.Context,
|
|
646
|
+
pdk_root: str | None,
|
|
647
|
+
config_path: str | None,
|
|
648
|
+
) -> None:
|
|
649
|
+
"""Print the current resolved configuration."""
|
|
650
|
+
resolved_path = _resolve_config_path(ctx, config_path)
|
|
651
|
+
cfg = Config.load(
|
|
652
|
+
pdk_root_flag=_resolve_pdk_root(ctx, pdk_root),
|
|
653
|
+
config_path=resolved_path,
|
|
654
|
+
)
|
|
655
|
+
console.print(f"config file = {resolved_path or CONFIG_PATH}")
|
|
656
|
+
console.print(f"pdk_root = {cfg.pdk_root}")
|
|
657
|
+
console.print(f"volare_root = {cfg.volare_root}")
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
@config.command("set")
|
|
661
|
+
@click.argument("key")
|
|
662
|
+
@click.argument("value")
|
|
663
|
+
@_CONFIG_OPTION
|
|
664
|
+
@click.pass_context
|
|
665
|
+
def config_set(
|
|
666
|
+
ctx: click.Context,
|
|
667
|
+
key: str,
|
|
668
|
+
value: str,
|
|
669
|
+
config_path: str | None,
|
|
670
|
+
) -> None:
|
|
671
|
+
"""Persist KEY=VALUE to the config file."""
|
|
672
|
+
resolved_path = _resolve_config_path(ctx, config_path)
|
|
673
|
+
try:
|
|
674
|
+
Config.set(key, value, config_path=resolved_path)
|
|
675
|
+
except ValueError as exc:
|
|
676
|
+
raise click.ClickException(str(exc))
|
|
677
|
+
console.print(
|
|
678
|
+
f"[green]✓[/green] Set {key} = {value} "
|
|
679
|
+
f"(written to {resolved_path or CONFIG_PATH})"
|
|
680
|
+
)
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
if __name__ == "__main__":
|
|
684
|
+
main()
|