refactor(plantuml): replace linker with idmap-based cross-diagram linking#290
refactor(plantuml): replace linker with idmap-based cross-diagram linking#290AAmbuj wants to merge 7 commits into
Conversation
dbb35d4 to
6b7cf91
Compare
6b7cf91 to
024b9b9
Compare
hoe-jo
left a comment
There was a problem hiding this comment.
Thanks for the PR, looks promising, some minor topics:
- Remove basename collision fallback; make source-path matching exact
Problem: extension joins idmap source (workspace short path from --source-name) to the Sphinx plantuml node path; when they differ under Bazel it falls back to idmap_by_basename with first-seen-wins, so two proxy.puml in different packages silently mislink.
Define one canonical key = workspace-relative POSIX path; normalize idmap source and node filename into it. Determine the staging→workspace offset once in on_builder_inited from app.srcdir.
Delete idmap_by_basename, _resolve_idmap fallback, and _ENV_IDMAP_BY_BASENAME.
If two idmaps share a key, raise build error (not warning). If a node can't map to a key, skip + warn.
Acceptance: two same-basename diagrams in different dirs each link only to their own definer; duplicate keys fail the build.
-
Fix proximity tiebreak path namespace
Problem: _proximity_tiebreak/_common_prefix_length may compare a staging source key against workspace-relative candidates. Once P0-1 lands, all are canonical keys — verify and add an assertion. Acceptance: tiebreak only on canonical keys; tie still → no link + warning. -
rust_test for puml_idmap
Add #[cfg(test)] + rust_test in BUILD. Cover: component children/none, class members, sequence participants, Empty, alias fallback, deterministic sort. -
pytest for clickable_plantuml
New tests/ + py_test. Cover: index build, FQN-before-alias, self-link skip, single vs tie, svg_obj vs svg URL, percent-encode, anchor.
5: _escape_plantuml_url — # in _SAFE can break [[ ]]; verify one-URL-per-alias dedup matches old contract.
6: confirm DefaultInfo idmap leak into consumer srcs intended; else split provider.
7: README invariant: --source-name must equal srcdir-relative path; unique basenames.
7662a39 to
2ee3857
Compare
19a3445 to
8cae034
Compare
|
What changed
Why
|
|
Test: Unit tests (Python):
Unit tests (Rust):
Bazel targets validated:
|
There was a problem hiding this comment.
Change the per-node "no resolvable source path" logger.warning to logger.debug. Diagrams that aren't idmap-backed are a normal case, not an error.
Optionally add one aggregated logger.info at end of build: "N plantuml nodes had no idmap (not linkable)".
Test: add a case with a plantuml node absent from source_keys and assert no WARNING record is emitted (via caplog).
There was a problem hiding this comment.
Revert to symlink for all files and instead make _node_source_key robust to symlinks by using os.path.realpath on both the node path and workspace_offset before prefix-matching. normpath doesn't resolve symlinks, which is the actual reason real files were needed — fixing it in Python removes the need to copy anything.
| let output_path = output_dir.join(format!("{file_stem}.idmap.json")); | ||
|
|
||
| let json = serde_json::to_string_pretty(&idmap) | ||
| .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; |
There was a problem hiding this comment.
make staging identity-preserving:
Stage .puml/.idmap.json at srcdir/<short_path> (i.e. source_prefix="", no strip_prefix for these), so staged-relative == short_path == idmap source.
Then keep symlinks, drop the sed rewrite, and drop execroot surgery
a707cb0 to
5b7aa6a
Compare
5b7aa6a to
91d64c7
Compare
The linker binary parsed FlatBuffers output to produce plantuml_links.json. It is superseded by the idmap-based approach where each diagram emits its own .idmap.json sidecar, making a separate link-resolution step unnecessary.
Replace all references to plantuml_links.json / standalone linker with the idmap sidecar flow. tooling_chain.puml updated to reflect the new pipeline.
Emits a per-source .idmap.json with defines[] / references[] entries used by the clickable_plantuml Sphinx extension to resolve cross-diagram links. Supports Component, Class, Sequence, Activity (empty), and FTA diagrams.
Calls write_idmap_to_file() for every resolved diagram. Passes short_path as source_name so both idmap and lobster outputs use the stable workspace-relative path rather than the sandbox-local filesystem path.
- _load_idmap_files() indexes all .idmap.json sidecars at build-finished time - _resolve_definer() uses FQN-first + proximity tiebreak to find the defining source - _node_source_key() maps each plantuml node back to its idmap source key - Removed: _load_link_mappings(), _collect_link_data() (linker-era code)
- architectural_design.bzl, unit_design.bzl: _run_puml_parser now returns (fbs, lobster, idmap); all callers updated - fmea.bzl: idmap sidecars collected from root_causes; add duplicate-basename guard (fail-fast with actionable error message) - sphinx_module.bzl: identity-preserving symlink staging for .puml and .idmap.json so source keys remain stable under any strip_prefix config
Covers: _load_idmap_files (index building, key conflicts), _node_source_key (symlink resolution, suffix matching, tie-breaking), _resolve_definer (FQN priority, alias fallback, self-link skip, warning on tie), _build_target_url, _escape_plantuml_url, _inject_links, and on_doctree_resolved end-to-end integration.
91d64c7 to
8f4f83b
Compare
Replace the separate linker tool with idmap sidecar files emitted directly by the parser.
Key changes: