Skip to content

Conversation

nashif
Copy link
Member

@nashif nashif commented Oct 14, 2025

To be used out of tree to amend and replace sources that are implemented
in Zephyr, for example drivers:

zephyr_library_amend()
zephyr_library_sources_amend(source.c)

If source.c was already added in the library being amended, it will be replaced
with the one in the west project/module.

This is useful when maintaining own version of a driver that is also upstream
in the Zephyr tree without having to add new configs to control compilation.

Signed-off-by: Anas Nashif [email protected]

To be used out of tree to amend and replace sources that are implemented
in Zephyr, for example drivers:

 zephyr_library_amend() zephyr_library_sources_amend(source.c)

If source.c was already added in the library being amended, it will be
replaced with the one in the west project/module.

This is useful when maintaining own version of a driver that is also
upstream in the Zephyr tree without having to add new configs to control
compilation.

Signed-off-by: Anas Nashif <[email protected]>
@nashif nashif force-pushed the topic/zephyr_library_sources_amend branch from 452247b to 08639ea Compare October 14, 2025 13:42
Comment on lines 544 to 547
function(zephyr_library_sources_amend source)
get_target_property(CURRENT_SOURCES ${ZEPHYR_CURRENT_LIBRARY} SOURCES)
get_filename_component(sourcex ${source} NAME)
list(FIND CURRENT_SOURCES ${sourcex} _index)
Copy link
Contributor

Choose a reason for hiding this comment

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

Depending on how these source files are added to the target, they can be absolute.

Also consider some existing library

zephyr_library_sources(
  subdir/sensor_x.c
)

You can't amend your own sensor_x.c as it won't match with any entry in the sources list.

Copy link
Member Author

Choose a reason for hiding this comment

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

Depending on how these source files are added to the target, they can be absolute.

thats why I compare with the file name component, not the full path.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant for CURRENT_SOURCES.

Copy link
Member Author

Choose a reason for hiding this comment

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

i see what you mean

Fix style issues with space after if.

Signed-off-by: Anas Nashif <[email protected]>
@nashif nashif force-pushed the topic/zephyr_library_sources_amend branch from cc20022 to 71b85aa Compare October 14, 2025 13:51
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants