|
| 1 | +# The `.matter` IDL file format |
| 2 | + |
| 3 | +The matter IDL file format is designed to be a human-readable representation of |
| 4 | +data structures, cluster definitions and endpoint composition. |
| 5 | + |
| 6 | +Since it is designed to be easy for both machine and humans to read, it is the |
| 7 | +basis of some tools to make validating zap-based cluster definitions easier. |
| 8 | + |
| 9 | +More details on the format in |
| 10 | +[matter_idl/README.md](../../scripts/py_matter_idl/matter_idl/README.md). |
| 11 | + |
| 12 | +## Parsing CSA XML Data definitions |
| 13 | + |
| 14 | +The SDK contains a copy of CSA XML data definitions in `data_model/clusters`. |
| 15 | + |
| 16 | +The files there are updated by running a scraper against the official matter |
| 17 | +specification and are a good source of truth for actual definitions. Update |
| 18 | +information available in [data_model/README.md](../../data_model/README.md). |
| 19 | + |
| 20 | +NOTE: scraper is a work in progress, XML data may be incomplete or have errors |
| 21 | +still. |
| 22 | + |
| 23 | +The script `./scripts/py_matter_idl/matter_idl/data_model_xml_parser.py` has the |
| 24 | +ability to parse one or more CSA data model XML files and output their content |
| 25 | +in `.matter` format. For example: |
| 26 | + |
| 27 | +```sh |
| 28 | +./scripts/py_matter_idl/matter_idl/data_model_xml_parser.py data_model/clusters/BooleanState.xml |
| 29 | +``` |
| 30 | + |
| 31 | +The tool supports several options that are useful for development: |
| 32 | + |
| 33 | +| Argument(s) | Description | |
| 34 | +| ----------------------- | ----------------------------------------------------------------------------------- | |
| 35 | +| `-o/--output PATH` | Output the matter file into a path instead of STDOUT. | |
| 36 | +| `--compare PATH` | Also read another `.matter` file for compare. MUST be used with `--compare-output`. | |
| 37 | +| `--compare-output PATH` | Output the subset of `--compare` clusters that matches XML into PATH. | |
| 38 | + |
| 39 | +Using `--compare` AND `--compare-output` produce output that is easier to |
| 40 | +compare as opposed to using existing zap-generated matter files because it |
| 41 | +strips out comments and it also alpha-sorts elements so that diffs are |
| 42 | +human-readable. |
| 43 | + |
| 44 | +### Comparing a `.matter` file against the spec |
| 45 | + |
| 46 | +Combining arguments to the tool allows getting a diff between SDK and |
| 47 | +specification: |
| 48 | + |
| 49 | +- `data_model/clusters/*.xml` are assumed to be the official specification |
| 50 | + definitions |
| 51 | +- `src/controller/data_model/controller-clusters.matter` contains _all_ |
| 52 | + clusters defined in the SDK |
| 53 | + |
| 54 | +As such one can run compares such as: |
| 55 | + |
| 56 | +```sh |
| 57 | +./scripts/py_matter_idl/matter_idl/data_model_xml_parser.py \ |
| 58 | + -o out/spec.matter \ |
| 59 | + --compare-output out/sdk.matter \ |
| 60 | + --compare src/controller/data_model/controller-clusters.matter \ |
| 61 | + data_model/clusters/DoorLock.xml \ |
| 62 | + && diff out/{spec,sdk}.matter |
| 63 | +``` |
| 64 | + |
| 65 | +NOTE: due to specification data scraper still being in development, the diff |
| 66 | +should be human-validated (e.g. for tool errors or Zigbee-only markers in the |
| 67 | +spec). |
| 68 | + |
| 69 | +## Linting `.matter` files for devices |
| 70 | + |
| 71 | +For device validation, `./scripts/idl_lint.py` provides the ability to validate |
| 72 | +a matter file for some basic conformance logic. These rules are expressed in |
| 73 | +`scripts/rules.matterlint`. |
| 74 | + |
| 75 | +The rules generally are: |
| 76 | + |
| 77 | +- pre-loaded from silabs XML files (validates that mandatory attributes are |
| 78 | + present) |
| 79 | +- Hard-coded rules (e.g. mandatory clusters and attributes on specific |
| 80 | + endpoints) |
| 81 | + |
| 82 | +Usage: |
| 83 | + |
| 84 | +```sh |
| 85 | +./scripts/idl_lint.py ./examples/window-app/common/window-app.matter |
| 86 | +``` |
0 commit comments