patch.py: add checks for patch_path
PATCH v2 1/1 patch.py: add checks for patch_path
All URLs from SRC checked to be a patch.
In some rare cases, when we have "diff" or
"patch" into URL it is treated as a patch not
like proper resource (e.g. repository). This
happens in case of using mirrors. Without
pre-downloaded repository archive we have
directory into downloads and exit frompatch_path before checking for patch/diff.
Let's limit patch_path call for url's that
has "apply" parameter set or has original
extensions .diff or .patch.
Error example for this URL:git://github.com/pkg/diff;name=diff;\
destsuffix=build/vendor/src/github.com/pkg/diff;branch=main;protocol=https
ERROR: nativesdk-yq-4.30.8+gitdd6cf3df146f3e2c0f8c765a6ef9e35780ad8cc1-r0 do_patch: \
Importing patch 'github.com.pkg.diff' with striplevel '1' FileNotFoundError(2, 'No such file or directory')
--- meta/lib/oe/patch.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)
meta/lib/oe/patch.py +32 -3
@@ -884,6 +884,33 @@ class UserResolver(Resolver): finally: os.chdir(olddir) +def is_archive_extension(ext): + return ext in ('.gz', '.bz2', '.xz', '.Z') + +def is_patch_extension(ext): + return ext in ('.diff', '.patch') + +def could_be_patch(url): + """ + URI could be treated as patch if: + - any resource with parameter apply set to yes/true + - any resource without parameter apply explicitly set, but let's limit them to ones with + extension .patch or .diff + """ + (_, _, path, _, _, parm) = bb.fetch.decodeurl(url) + + if "apply" in parm: + apply = oe.types.boolean(parm["apply"]) + if apply: + return True + + base, ext = os.path.splitext(path) + if is_archive_extension(ext): + _, ext = os.path.splitext(base) + if is_patch_extension(ext): + return True + + return False def patch_path(url, fetch, unpackdir, expand=True): """Return the local path of a patch, or return nothing if this isn't a patch"""
@@ -892,7 +919,7 @@ def patch_path(url, fetch, unpackdir, expand=True): if os.path.isdir(local): return base, ext = os.path.splitext(os.path.basename(local)) - if ext in ('.gz', '.bz2', '.xz', '.Z'): + if is_archive_extension(ext): if expand: local = os.path.join(unpackdir, base) ext = os.path.splitext(base)[1]
@@ -902,7 +929,7 @@ def patch_path(url, fetch, unpackdir, expand=True): apply = oe.types.boolean(urldata.parm["apply"]) if not apply: return - elif ext not in (".diff", ".patch"): + elif not is_patch_extension(ext): return return local
@@ -913,7 +940,9 @@ def src_patches(d, all=False, expand=True): patches = [] sources = [] for url in fetch.urls: - local = patch_path(url, fetch, unpackdir, expand) + local = None + if could_be_patch(url): + local = patch_path(url, fetch, unpackdir, expand) if not local: if all: local = fetch.localpath(url)
Signature · 1 line
2.35.6
Quoted 17 lines · Oleksiy Obitotskyy via lists.openembedded.org
All URLs from SRC checked to be a patch.
In some rare cases, when we have "diff" or
"patch" into URL it is treated as a patch not
like proper resource (e.g. repository). This
happens in case of using mirrors. Without
pre-downloaded repository archive we have
directory into downloads and exit frompatch_pathbefore checking for patch/diff.Let's limit
patch_pathcall for url's that
has "apply" parameter set or has original
extensions .diff or .patch.Error example for this URL:
git://github.com/pkg/diff;name=diff;\
destsuffix=build/vendor/src/github.com/pkg/diff;branch=main;protocol=https
Quoted 5 lines
ERROR: nativesdk-yq-4.30.8+gitdd6cf3df146f3e2c0f8c765a6ef9e35780ad8cc1-r0
do_patch: \
Importing patch 'github.com.pkg.diff' with striplevel '1'FileNotFoundError(2, 'No such file or directory')Signed-off-by Oleksiy Obitotskyy <[email protected]>
You mention the apply parameter in your commit message. Can you just add ;apply=no to the relevant SRC_URI entry?
Best regards,
Signature · 1 line
Paul Barker