Skip to content

Conversation

@lgirdwood
Copy link
Member

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.

@dbaluta
Copy link
Collaborator

dbaluta commented Sep 2, 2025

This sounds like fun. Is it using module adapter API?

@lgirdwood
Copy link
Member Author

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.

@lgirdwood lgirdwood force-pushed the lrg/topic/module-script branch 2 times, most recently from d9df40c to d02a371 Compare September 9, 2025 11:51
@lgirdwood lgirdwood marked this pull request as ready for review September 9, 2025 12:17
Copilot AI review requested due to automatic review settings September 9, 2025 12:17
Copy link

Copilot AI left a 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.py script to automate new module creation from template
  • Renames template_comp module to template across 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.

Comment on lines +841 to +843
if args.zephyrsdk:
print("Using Zephyr SDK for building")
xtensa_tools_root_dir = None
Copy link

Copilot AI Sep 9, 2025

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.

Suggested change
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")

Copilot uses AI. Check for mistakes.
Copy link
Member Author

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}")
Copy link

Copilot AI Sep 9, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

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.

Copy link
Collaborator

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.

Copy link
Member Author

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.

@lgirdwood
Copy link
Member Author

@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

@lgirdwood lgirdwood force-pushed the lrg/topic/module-script branch from d02a371 to 0b8ea68 Compare September 9, 2025 13:37
@lgirdwood lgirdwood requested a review from ranj063 as a code owner September 9, 2025 13:37
@lgirdwood lgirdwood force-pushed the lrg/topic/module-script branch from 0b8ea68 to 83d5cc5 Compare September 9, 2025 15:42
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>
@lgirdwood lgirdwood force-pushed the lrg/topic/module-script branch from 83d5cc5 to ae3c142 Compare September 10, 2025 13:02
@lgirdwood lgirdwood changed the title WIP scripts: module: helper script to create a new module from template scripts: module: helper script to create a new module from template Sep 10, 2025
@dbaluta
Copy link
Collaborator

dbaluta commented Sep 10, 2025

@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.

@lgirdwood
Copy link
Member Author

@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.

Copy link
Collaborator

@kv2019i kv2019i left a 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")
Copy link
Collaborator

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)
Copy link
Collaborator

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?

Copy link
Member Author

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()
Copy link
Collaborator

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?

Copy link
Member Author

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>
@lgirdwood
Copy link
Member Author

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.

That would be useful, but the script is not really that clever, its mostly a copy and string rename. Can followup in another PR.

Copy link
Collaborator

@singalsu singalsu left a 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.

@lgirdwood lgirdwood merged commit 1c4bf62 into thesofproject:main Sep 22, 2025
37 of 47 checks passed
@lgirdwood lgirdwood deleted the lrg/topic/module-script branch September 22, 2025 13:29
Copy link
Contributor

@jsarha jsarha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lrgirdwo Just one quiestion in addition to @kv2019i concerns ... Sorry could not finnish this big PR in time.

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')):
Copy link
Contributor

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?

Copy link
Member Author

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.

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.

7 participants