-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scripts: inline code generation with cogeno (and edts) #10885
Conversation
This comment has been minimized.
This comment has been minimized.
f80d1b5
to
d51ad45
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK from a doc point of view, a couple of comments
The codegen parts that are independent from Zephyr got their own repository https://gitlab.com/b0661/cogeno. The inline code generation tool had to be renamed to cogeno because the name codegen is in use by several open source projects. Cogeno is on PyPi now. You can install it by The Zephyr related documentation of cogeno is within the subsystems´s folder. Also the Zephyr specific Python modules and code generation templates are in Zephyr This is a big step to fulfill the requirements given in #10904 for code generation:
This is Zephyr specific. The related modules and templates are in Zephyr´s
Cogeno scripts are in standard script languages. IDEs should easily identify complete script files. For inline code this will be different.
Cogeno is as versatile as Python/ Jinja2. The solution for Zephyr can be implemented using Zephyr specific templates and modules.
Constraints are part of the Zephyr specfic templates.
Zephyr specifc stuff is in Zephyr. Generic code aka. cogeno is maintained and improved outside of Zephyr with the potential effect of contributions from other projects too.
Cogeno´s documentation is available online on Read the Docs. Zephyr specific documentation is in the Zephyr doc tree. There is still room to improve the documentation, but it already contains most of the basics.
The edtlib.py Python library is include in cogeno. After installation of cogeno it can also be used standalone as a command
Zephyr specifc design rules for drivers.
Cogeno integration in Zephyr is done by the codegen macros.
Cogeno can
Cogeno takes the
The cogeno CMake macros and the device declare templates are within Zephyr. Thanks Edit: codegen -> cogeno |
c166b28
to
e800b6b
Compare
This comment has been minimized.
This comment has been minimized.
Integrate code generation by cogeno into Zephyr build system. If a source file is added by zephyr_sources_cogeno(..) or zephyr_sources_cogeno_ifdef(..) cogeno will be executed and the generated file stored to the build directory. Compilation will run on the generated file only. Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Document inline code generation with cogeno. Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #10885 +/- ##
==========================================
- Coverage 52.55% 48.38% -4.18%
==========================================
Files 340 265 -75
Lines 49341 42193 -7148
Branches 11463 10137 -1326
==========================================
- Hits 25929 20413 -5516
+ Misses 18152 17703 -449
+ Partials 5260 4077 -1183
Continue to review full report at Codecov.
|
Cogeno does not need to be part of Zephyr anymore. Inline code generation with Cogeno is now available as a Zephyr module.
For integration into the Zephyr build system see https://cogeno.readthedocs.io/en/latest/cogeno/build.html#build-with-zephyr-and-cogeno. |
Overview
Extend Zephyr build system by inline code generation (cogeno) with Python snippets in source files. As most information for drivers is taken from the device tree an extended device tree database (edts) is added to allow easy retrieval with Python.
The PR is the sucessor to PR #6762. It includes all of #6762 and the relevant commits from #9876.
The PR is completely self contained. Besides the changes to the CMake build system to allow cogeno to be used as a script there are no other changes to the current code base.
Motivation for or Use Case
The prime motivation is to be able to configure drivers on build time by the information from the device tree in a standardized way. Therefor there must be means to easily generate structured data from device tree information at build time.
The EDTS database directly extracts the device tree information from the compiled DTS data. Inline code generation with Python snippets by cogeno is used to get this information and generate structured data to be compiled.
Design Details
Python snippets that are inlined in a source file are used as generators. The tool to scan the source file for the Python snippets and process them is cogeno. Cogeno is itself written in Python. Cogeno used Cog as it's starting point and has extended and rewritten it to provide specific generator functions.
The processing of source files is controlled by two CMake extension functions: zephyr_sources_cogeno(..) and zephyr_sources_cogeno_ifdef(..). During CMake configuration the source files are processed by cogeno and the generated source files are written to the CMake binary directory. The generated source files are added to the Zephyr sources.
The inlined Python snippets can contain any Python code, they are regular Python scripts. All Python snippets in a source file and all Python snippets of included template files are treated as a python script with a common set of global Python variables. Global data created in one snippet can be used in another snippet that is processed later on. This feature is e.g. used to customize included template files.
An inlined Python snippet can always access the cogeno module. The cogeno module encapsulates and provides all the functions to retrieve information (options, device tree properties, CMake variables, config properties) and to put out the generated code.
Test Strategy
A working proof of concept for driver instantiation is #10888 (Edit: Has to be updated).
For the EDTS database the sanity check script from #9876 is used with some adaptations.
PR History
This PR is the sucessor of several PRs:
Signed-off-by: Bobby Noelte b0661n0e17e@gmail.com