Skip to content

Decouple input parsing from XML generation - #151

Open
Igor Opaniuk (igoropaniuk) wants to merge 3 commits into
qualcomm-linux:mainfrom
igoropaniuk:feat/loaders-package
Open

Decouple input parsing from XML generation#151
Igor Opaniuk (igoropaniuk) wants to merge 3 commits into
qualcomm-linux:mainfrom
igoropaniuk:feat/loaders-package

Conversation

@igoropaniuk

Copy link
Copy Markdown
Contributor

This is the first, purely mechanical step of the partition-source rework discussed in [1]: it separates reading a partition spec from emitting XML, without changing a single generated byte.

Today gen_partition.py is a script rather than a library: parsing, validation, and XML emission run as top-level statements at import time, and every detail of the .conf line format is hard-wired into the emission flow. That has three practical costs:

  1. The parser cannot be tested - the module exits or opens files the moment you import it, so the only safety net we have is comparing generated artifacts after the fact.
  2. Any new source format (the structured YAML proposed in [1], or anything else) would have to duplicate the whole script flow or thread format checks through every helper.
  3. Unrelated features keep landing in the same tangled spot - for example, new named partition options have to be woven into the same code that writes XML, which makes such PRs harder to review and rebase than they should be.

The script tail moves into a main(), the .conf parser moves into a loaders/ package, and a small internal representation (LoadedSpec) becomes the contract between any loader and the emitter. A new pytest suite pins the parser's exact behavior -size-string parsing, attribute-bit decoding, LUN grouping, the -m image-map override - so that contract is now enforced by tests rather than by habit. Adding a source format becomes "drop a module into loaders/ and register its suffix"; nothing else changes.

Follow-up PRs (from [2]) will build on this: the YAML loader with schema validation, the multi-storage board model with composition, and the first board migration (Glymur-CRD) - split out per reviewer request so each part can be reviewed on its own terms.

[1] #124
[2] #134

The module ran argv parsing and XML emission as top-level statements at
import time, so it could not be imported by pytest or any library
caller. This blocks the follow-up work: unit-testing the parser and
splitting it into a loaders package.

Wrap the flow in main(argv=None) -> int gated by __name__ ==
"__main__", move the module-level accumulators into locals, and return
status codes instead of sys.exit(). The runpy dispatcher in cli.py is
unaffected because it sets __name__ to "__main__".

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
The .conf format was hard-coded into gen_partition.py, with no boundary
between where data comes from and how partition XML is emitted. Adding
another format (YAML) would mean duplicating main() or scattering
format branches through every helper.

Add qcom_ptool/spec.py for the canonical internal shape (DiskParams,
PartitionEntry, PartitionsByLun, LoadedSpec) and qcom_ptool/loaders/
with a load(path, image_map) dispatcher keyed on file extension: a new
format becomes a new module plus a suffix registration.

Move the conf parser into loaders/conf.py and apply the image-map override
in one post-load pass, removing the last shared-global coupling.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
make integration only checks that referenced files exist; it does not
cover size parsing, attribute-bit decoding, LUN grouping or the
image-map override -- the contract any future loader must reproduce.

Add tests/unit/ pinning those cases against conf.load() and the loaders
dispatcher. Wire it in with a make unit-test target, add it to make
check, install python3-pytest in CI, and keep pytest config in
pyproject.toml so pytest runs from the repo root.

Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants