| --- | |
| paths: "code-generation/**,plc4net/tools/code-gen/**" | |
| applyTo: "code-generation/**,plc4net/tools/code-gen/**" | |
| --- | |
| <!-- GENERATED from .agents/rules/code-generation.md by .agents/sync-adapters.sh. Edit the source, then run it. --> | |
| <!-- | |
| Licensed to the Apache Software Foundation (ASF) under one | |
| or more contributor license agreements. See the NOTICE file | |
| distributed with this work for additional information | |
| regarding copyright ownership. The ASF licenses this file | |
| to you under the Apache License, Version 2.0 (the | |
| "License"); you may not use this file except in compliance | |
| with the License. You may obtain a copy of the License at | |
| https://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, | |
| software distributed under the License is distributed on an | |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| KIND, either express or implied. See the License for the | |
| specific language governing permissions and limitations | |
| under the License. | |
| --> | |
| # Code generation | |
| | Part | Generates | | |
| |-------------------------------------------------------|-------------------------------------------------------------| | |
| | `code-generation/protocol-base-mspec/` | the mspec grammar (ANTLR) and type model: every language | | |
| | `code-generation/language-base-freemarker/` | the FreeMarker base for the template languages | | |
| | `code-generation/language/java/` (Java generators) | `plc4j/drivers/*/src/main/generated/` | | |
| | `code-generation/language/go/` (`templates/go/`) | `plc4go/protocols/*/readwrite/` | | |
| | `code-generation/language/c/` (`templates/c/`) | `plc4c/generated-sources/` | | |
| | `code-generation/language/python/` (`templates/python/`) | `plc4py/plc4py/protocols/*/readwrite/` | | |
| | `plc4net/tools/code-gen/` (pure .NET, own mspec parser) | `plc4net/drivers/*/model/` | | |
| | `code-generation/language/cs/` (`templates/cs/`) | not used by `plc4net` (its generator replaced these) | | |
| The `plc4x-maven-plugin` that runs the generators, and its type API, come from `apache/plc4x-build-tools`, pinned | |
| by `plc4x-code-generation.version` in the root `pom.xml`. A change there needs a build-tools release (or a local | |
| `install` plus a bumped property) before this repository can use it. | |
| ## ⛔ A generator or template change regenerates every protocol of that language | |
| - **A template or Java generator change** affects every protocol the language generates: regenerate all of them | |
| (`regenerate-code` skill) and commit the whole diff. Review it: an unexpected change in another protocol is a | |
| bug in the template, not noise. | |
| - **A change to the mspec grammar or type model** (`protocol-base-mspec`) can change the output of every | |
| language, including `plc4net/tools/code-gen`, which has its own parser: keep both parsers accepting the same | |
| mspec. | |
| - **A new mspec feature** (field kind, attribute, expression function) works in every language that generates a | |
| protocol using it, or the PR says which languages reject it and how they fail. | |
| - Generated files keep the `Code generated ... DO NOT EDIT.` line and the Apache license header: the RAT check runs | |
| on them too. | |
| - `plc4net/tools/code-gen`: `python plc4net/tools/code-gen/generate_parsers.py --check` (its checked-in ANTLR | |
| parser is current) and `./mvnw -f plc4net/pom.xml -Pcheck-generated-code generate-sources` (models match) run in | |
| CI; run both after a change there. |