[topgen] Fail more understandably if we start in an unexpected place
This should fix issue #24595. The problem that caused the issue is that we compute paths to the various IP blocks that should be included by following relative paths from the -t argument. This doesn't work very well if the top_earlgrey.hjson file moves around!
A sensible design would probably point more explicitly at where to find IPs, but this should hopefully be a little easier to debug.
I believe topgen has a option to point to places where to look for hjson files (--hjson-path), the doc says:
If defined, topgen uses supplied path to search for ip hjson. This applies only to ip's with the
reggen_onlyattribute. If an hjson is located both in the conventional path and the alternate path, the alternate path has priority.
Yep, you're right. The issue that prompted the change is triggered by a block that isn't marked reggen_only. The code (before this change) is:
if reggen_only and args.hjson_path:
ip_hjson = Path(args.hjson_path) / f"{ip}.hjson"
else:
ip_hjson = hjson_dir.parent / f"ip/{ip}/data/{ip}.hjson"
where hjson_dir is derived from the -t argument.
This change is basically just adding a somewhat helpful error message earlier if the derived directory is wrong.
I've come back to this and it sees lots of merge conflicts. And I wasn't completely convinced it was a change worth doing! Let's worry about it some other time :-)