summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-02-29 23:49:37 +0800
committerruki <[email protected]>2024-02-29 23:49:37 +0800
commitbde783984522a9e239e890f3cc1a1efef3a3efb3 (patch)
treee5fe5994d3c6a4a5ebd5d98b93ac34bd15e8a770
parent7659e6d4def6efba849594e1ca45e4c6a78282c8 (diff)
improve add_patches to support archive file
-rw-r--r--xmake/modules/private/action/require/impl/actions/patch_sources.lua28
1 files changed, 26 insertions, 2 deletions
diff --git a/xmake/modules/private/action/require/impl/actions/patch_sources.lua b/xmake/modules/private/action/require/impl/actions/patch_sources.lua
index afa0336d7..b5203471f 100644
--- a/xmake/modules/private/action/require/impl/actions/patch_sources.lua
+++ b/xmake/modules/private/action/require/impl/actions/patch_sources.lua
@@ -24,6 +24,7 @@ import("core.base.global")
import("net.http")
import("net.proxy")
import("devel.git")
+import("utils.archive")
-- check sha256
function _check_sha256(patch_hash, patch_file)
@@ -97,8 +98,31 @@ function _patch(package, patch_url, patch_hash)
end
end
- -- apply the patch file
- git.apply(patch_file)
+ -- is archive file? we need extract it first
+ local extension = archive.extension(patch_file)
+ if extension and #extension > 0 then
+ local patchdir = patch_file .. ".dir"
+ local patchdir_tmp = patchdir .. ".tmp"
+ os.tryrm(patchdir_tmp)
+ if archive.extract(patch_file, patchdir_tmp) then
+ os.tryrm(patchdir)
+ os.mv(patchdir_tmp, patchdir)
+ else
+ os.tryrm(patchdir_tmp)
+ os.tryrm(patchdir)
+ raise("cannot extract %s", patch_file)
+ end
+
+ -- apply patch files
+ for _, file in ipairs(os.files(path.join(patchdir, "**"))) do
+ vprint("applying patch %s", file)
+ git.apply(file)
+ end
+ else
+ -- apply single plain patch file
+ vprint("applying patch %s", patch_file)
+ git.apply(patch_file)
+ end
end
-- patch the given package