-
Notifications
You must be signed in to change notification settings - Fork 349
scripts: module: helper script to create a new module from template #10211
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: module: helper script to create a new module from template #10211
Conversation
|
This sounds like fun. Is it using module adapter API? |
It is fun :) Yes its copying the template_comp module files into a new directory, renaming them and renaming function calls to the new module name alongside Kconfig, Cmake and uuid generation. I'm missing 2 patches though, will attache them here soon. |
d9df40c to
d02a371
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.
Pull Request Overview
This PR adds a new Python script for creating SOF modules from a template and renames the existing "template_comp" module to "template" throughout the codebase for consistency.
- Adds
sdk-create-module.pyscript to automate new module creation from template - Renames
template_compmodule totemplateacross all files and references - Alphabetizes and reorganizes configuration entries in Kconfig and CMakeLists.txt files
Reviewed Changes
Copilot reviewed 18 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| uuid-registry.txt | Reorganizes UUID entries alphabetically, removes old template_comp entry and adds new template entry |
| tools/rimage/config/*.toml.h | Updates template module references from template_comp to template |
| src/audio/template/* | Renames module files and updates all internal references from template_comp to template |
| src/audio/Kconfig | Reorganizes rsource entries alphabetically and updates template module reference |
| src/audio/CMakeLists.txt | Reorganizes conditional compilation blocks alphabetically and updates template module reference |
| scripts/xtensa-build-zephyr.py | Adds new --zephyrsdk option for forcing Zephyr SDK usage |
| scripts/sdk-create-module.py | New script for creating modules from template with UUID generation |
| scripts/gen-uuid-reg.py | Adds debug print statement for UUID processing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if args.zephyrsdk: | ||
| print("Using Zephyr SDK for building") | ||
| xtensa_tools_root_dir = None |
Copilot
AI
Sep 9, 2025
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.
The xtensa_tools_root_dir variable assignment on line 846 is not properly indented and will only execute when args.zephyrsdk is False. The variable should be declared outside the conditional block or the indentation should be fixed.
| if args.zephyrsdk: | |
| print("Using Zephyr SDK for building") | |
| xtensa_tools_root_dir = None | |
| xtensa_tools_root_dir = None | |
| if args.zephyrsdk: | |
| print("Using Zephyr SDK for building") |
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.
False positive. the else: case catches this.
| all_uuids.add(uu) | ||
| all_syms.add(sym) | ||
| emit_uuid_rec(uu, sym) | ||
| print(f"Added UUID {uu} with symbol {sym}") |
Copilot
AI
Sep 9, 2025
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.
Debug print statements should not be left in production code. This print statement should be removed or wrapped in a debug flag check.
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.
Intentional to show module UUID is being compiled.
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.
This print statement adds unnecessary noise to the logs. If someone needs to inspect the UUIDs, they can easily find them in the uuid-registry.txt file, so logging each one during generation isn't really needed.
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.
The logging makes it more obvious to the module developer (most of whom will not know about UUIDs) which UUIDs are being added to the build. i.e. 3P developer can see their new module UUID is either in the build or not as they will see volume, mixin etc UUIDs and realize more quickly I need to add my UUID.
|
@dbaluta I've pushed more cleanup now - use case is that developer can run the script and get a new module that builds based on the template. e.g. like file -> new -> module |
d02a371 to
0b8ea68
Compare
0b8ea68 to
83d5cc5
Compare
Add a -z option that forces the script to use the Zephyr SDK even when proprietary compilers are installed. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Use alphabetical module entry for the registry and spell it out so its clear. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Put the Cmake and Kconfig module directories in alphabetical order to help convenience scripting insert new modules. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Make things a little easier to debug for UUID generation. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Make the template simpler by removing the "_comp" from filenames, API calls, Kconfig, CMakefile and macros. This simplifies usage as there was a mix of template and template_comp and makes it easier to use as a starting point for new modules. Signed-off-by: Liam Girdwood <liam.r.girdwood@intel.com>
Put in alphabetical order and add start/end markers. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add a convenience script that will generate new module sources, uuid, Kconfig and Cmake to speed up module development. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
83d5cc5 to
ae3c142
Compare
|
@lgirdwood looks good. I wonder if you can add some documentation about this in our docs repo. It looks very useful and would be easier to get start with some documentation. |
Let me add a ReadMe.md. I will also add a Vscode -> Run Task -> New Module menu. |
kv2019i
left a comment
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.
I think only big concern is that this would desperately need a test case in github workflows. I.e. using this script to add a template, build the resulting tree and ensure everything works. Otherwise I can see this breaking up very easily when people unaware of this script change the dependencies in source code.
| xtensa_tools_root_dir = None | ||
| else: | ||
| print("Using Xtensa tools for building") | ||
| xtensa_tools_root_dir = os.getenv("XTENSA_TOOLS_ROOT") |
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.
I just run this script with XTENSA_TOOLS_ROOT unset to get the same effect, but I guess this we can have an option as well.
| add_subdirectory(pcm_converter) | ||
| add_subdirectory(pipeline) | ||
|
|
||
| if(CONFIG_COMP_BASEFW_IPC4 AND NOT CONFIG_LIBRARY) |
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.
How is this before aria?
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.
So the alpha sorting logic is only sorting on and inserting on a add_subdirectory() clause, adding other clauses would get too complex.
| add_local_sources(sof | ||
| kpb.c | ||
| ) | ||
| endif() |
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.
And why these are here, shouldn't these be in above alphabetical listing?
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.
ditto - and these should really be in their own directories.
Rename the readme to a generic name and add context for more scripts. Add more markdown. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
That would be useful, but the script is not really that clever, its mostly a copy and string rename. Can followup in another PR. |
singalsu
left a comment
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.
Thanks, this is a good overall cleanup. The script to generate a new component worked for me.
As nit I noticed that there is in template a mention of s16 samples format in s32 processing function. It could be added to template fixes.
jsarha
left a comment
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.
| replace_text_in_file(original_filepath, old_text, new_text) | ||
| if filename.endswith(('.c', '.h', '.cpp', '.hpp', '.txt', '.toml', 'Kconfig')): | ||
| replace_text_in_file(original_filepath, old_text.upper(), new_text.upper()) | ||
| if filename.endswith(('.c', '.h', '.cpp', '.hpp', '.txt', '.toml', 'Kconfig')): |
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.
Why does process_directory() replace literal "template" with the new_text-variable? Why isn't replacing old_text-variable enough?
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.
The template module is the "template", i.e we copy, rename and search/replace "template", "TEMPLATE" with new module name in all files needed to make the new module. Intention is that next steps module developer will need to replace the process() and get/set_config() logic in the new module with their own logic.
This scripts creates a new module from template and renames files, code to the new module name alongside creating uuid and Cmake and Kconfig entries.