Dynamically load patch series from fetched repositories.
Hi everyone. I am looking for a way to use patches in recipes without adding them to layers and then mentioning directly in SRC_URI. An example workflow would be:
1. Fetch a repository that is added in SRC_URI, using either git or other available methods.
2. Check out the specific head in the repository (a branch or a commit).
3. Let do_fetch or do_patch search for either a "series" file or a list of patches in the repository.
4. Apply the patches.
The only problem I see in the proposed flow is the 3rd step. Some repositories may contain patches that could be applied to different tools or packages. And a recipe that is responsible for a package A can try to apply patches for a package B that is being stored in the same repository with patches. Hence, the 3rd step should be restricted somehow. An example could be a variable that will point out the place in the repository with patches where the recipe for package A should search patches. The variable can utilize overrides to customize patch queues further.
An example of the repository with patches can be found here: https://github.com/Dasharo/dasharo-pq/tree/flashrom-testing/flashrom . The idea here is not to copy and paste the huge amount of patches into different build systems, but to have a single place where all patches are added and maintained. Other pros for this solution:
* Clear separation of concerns: Build systems remain focused on configuration and integration logic, while patch content and maintenance are handled elsewhere. This keeps repositories smaller, cleaner, and easier to reason about.
* Single source of truth: A centralized patch repository establishes a clear, authoritative source for all modifications. This avoids ambiguity about which patch version is “correct” and prevents subtle divergences that can arise when the same patch is copied and slightly adjusted across multiple build systems.
* Simplified updates and backports: Bug fixes, improvements, or rebases of patches need to be done only once. Downstream users automatically benefit from updates without having to manually replicate changes or re-evaluate multiple patch copies.
* Reduced review and validation effort: Code review, testing, and validation can focus on a single patch location. This is especially valuable for large or security-sensitive patch sets, where duplicated reviews across repositories would waste time and increase the chance of missed issues.
* Improved traceability and auditing: A centralized repository provides a complete history of why and when patches were introduced, modified, or dropped. This is important for audits, compliance requirements, and post-mortem analyses, especially in firmware or low-level tooling contexts.
* Lower risk during upstream transitions: When patches are eventually upstreamed or dropped due to new upstream releases, central management ensures that all consumers transition in lockstep. This avoids situations where some build systems still rely on patches that are no longer needed, or worse: no longer compatible.
Let me know if you have a better proposition for the implementation flow I have presented, or if I have missed some already existing technology in the Yocto Project. Either my colleagues or I would be eager to contribute such a feature to the project.
Signature · 3 lines
Best regards, Daniil Klimuk. 3mdeb Zarhus Team Leader. https://3mdeb.com | @3mdeb_com
Quoted 4 lines · Danik via lists.yoctoproject.org
Let me know if you have a better proposition for the implementation flow I have presented, or if I have missed some already existing technology in the Yocto Project. Either my colleagues or I would be eager to contribute such a feature to the project.
I'd say any patch-related effort should encourage and support a strict 'upstream first' culture for making patches, and this feels like a step in the opposite direction, or at best, something that can be badly misused.
We've all seen the monstrous vendor kernels from hell, and other private vendor forks which are modified in ways that are poorly written, not documented and basically unsustainable. Even in the example above the patches contain basically no documentation or commit history of why any given patch was added (e.g. a link to an issue in a ticket system or even a commit message), whether it should be sent upstream or anything else that might help some poor developer (or consultant) to understand anything about it.
That said, you probably want a 'pragmatic', 'practical' answer :) If so, then one approach is to list both the original component and the repo with patches one after another in SRC_URI, so they're both unpacked into ${UNPACKDIR}. Then sandwich a bitbake task between patch and configure that can apply patch files from the second component into the first. Appending to SRC_URI and implementing the task can be done in a class, and parametrized as needed with variables. Then inherit the class and set the variables from a bbappend, or just write the recipe directly that way.
Alex
Quoted 11 lines · Danik via lists.yoctoproject.org
Hi everyone. I am looking for a way to use patches in recipes without adding them to layers and then mentioning directly in
SRC_URI. An example workflow would be:1. Fetch a repository that is added in
SRC_URI, using either git or other available methods.
2. Check out the specific head in the repository (a branch or a commit).
3. Letdo_fetchordo_patchsearch for either a "series" file or a list of patches in the repository.
4. Apply the patches.The only problem I see in the proposed flow is the 3rd step. Some repositories may contain patches that could be applied to different tools or packages. And a recipe that is responsible for a package A can try to apply patches for a package B that is being stored in the same repository with patches. Hence, the 3rd step should be restricted somehow. An example could be a variable that will point out the place in the repository with patches where the recipe for package A should search patches. The variable can utilize overrides to customize patch queues further.
An example of the repository with patches can be found here: https://github.com/Dasharo/dasharo-pq/tree/flashrom-testing/flashrom . The idea here is not to copy and paste the huge amount of patches into different build systems, but to have a single place where all patches are added and maintained. Other pros for this solution:
A repository that contains patches for itself is slightly unhinged (just make a new point release), but I do work with repositories that depend on and statically link to other projects so carry patches in-tree for them.
We’ve got a class that applies the in-tree patches in a task after do_patch: https://git.yoctoproject.org/meta-arm/tree/meta-arm/classes/apply_local_src_patches.bbclass. It’s not ideal, but it works.
Ross
Quoted 8 lines · Ross Burton
Quoted 7 lines · Danik via lists.yoctoproject.org
Hi everyone. I am looking for a way to use patches in recipes without adding them to layers and then mentioning directly in
SRC_URI. An example workflow would be:1. Fetch a repository that is added in
SRC_URI, using either git or other available methods.
2. Check out the specific head in the repository (a branch or a commit).
3. Letdo_fetchordo_patchsearch for either a "series" file or a list of patches in the repository.
4. Apply the patches.
Quoted 8 lines
Quoted 3 lines
The only problem I see in the proposed flow is the 3rd step. Some repositories may contain patches that could be applied to different tools or packages. And a recipe that is responsible for a package A can try to apply patches for a package B that is being stored in the same repository with patches. Hence, the 3rd step should be restricted somehow. An example could be a variable that will point out the place in the repository with patches where the recipe for package A should search patches. The variable can utilize overrides to customize patch queues further.
An example of the repository with patches can be found here: https://github.com/Dasharo/dasharo-pq/tree/flashrom-testing/flashrom . The idea here is not to copy and paste the huge amount of patches into different build systems, but to have a single place where all patches are added and maintained. Other pros for this solution:
A repository that contains patches for itself is slightly unhinged (just make a new point release), but I do work with repositories that depend on and statically link to other projects so carry patches in-tree for them.
We’ve got a class that applies the in-tree patches in a task after
do_patch: https://git.yoctoproject.org/meta-arm/tree/meta-arm/classes/apply_local_src_patches.bbclass. It’s not ideal, but it works.Ross
Thank you for all your suggestions.
Quoted 1 line
A repository that contains patches for itself is slightly unhinged (just make a new point release), but I do work with repositories that depend on and statically link to other projects so carry patches in-tree for them. I have another use-case. The repository https://github.com/Dasharo/dasharo-pq contains or will contain not patches for itself, but will gather all patches from Dasharo organization for different upstreams (in this example it is flashrom) in one place, which will simplify upstreaming and maintaining the patches.
Signature · 3 lines
Best regards, Daniil Klimuk. 3mdeb Zarhus Team Leader. https://3mdeb.com | @3mdeb_com