Skip to content

Commit

Permalink
apply reversed patches for package
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Feb 29, 2024
1 parent 9502945 commit 9b8384f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 10 additions & 2 deletions xmake/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,12 @@ function _instance:fetch_librarydeps()
end

-- get the patches of the current version
--
-- @code
-- add_patches("6.7.6", "https://cdn.kernel.org/pub/linux/kernel/v6.x/patch-6.7.6.xz",
-- "a394326aa325f8a930a4ce33c69ba7b8b454aef1107a4d3c2a8ae12908615fc4", {reverse = true})
-- @endcode
--
function _instance:patches()
local patches = self._PATCHES
if patches == nil then
Expand All @@ -2009,7 +2015,8 @@ function _instance:patches()
patches = {}
patchinfo = table.wrap(patchinfo)
for idx = 1, #patchinfo, 2 do
table.insert(patches , {url = patchinfo[idx], sha256 = patchinfo[idx + 1]})
local extra = self:extraconf("patches." .. version_str, patchinfo[idx])
table.insert(patches , {url = patchinfo[idx], sha256 = patchinfo[idx + 1], extra = extra})
end
else
-- match semver, e.g add_patches(">=1.0.0", url, sha256)
Expand All @@ -2018,7 +2025,8 @@ function _instance:patches()
patches = patches or {}
patchinfo = table.wrap(patchinfo)
for idx = 1, #patchinfo, 2 do
table.insert(patches , {url = patchinfo[idx], sha256 = patchinfo[idx + 1]})
local extra = self:extraconf("patches." .. range, patchinfo[idx])
table.insert(patches , {url = patchinfo[idx], sha256 = patchinfo[idx + 1], extra = extra})
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ function _check_sha256(patch_hash, patch_file)
end

-- do patch
function _patch(package, patch_url, patch_hash)
function _patch(package, patchinfo)
local patch_url = patchinfo.url
local patch_hash = patchinfo.hash
local patch_extra = patchinfo.extra or {}

-- trace
patch_url = proxy.mirror(patch_url) or patch_url
Expand Down Expand Up @@ -116,12 +119,12 @@ function _patch(package, patch_url, patch_hash)
-- apply patch files
for _, file in ipairs(os.files(path.join(patchdir, "**"))) do
vprint("applying patch %s", file)
git.apply(file)
git.apply(file, {reverse = patch_extra.reverse})
end
else
-- apply single plain patch file
vprint("applying patch %s", patch_file)
git.apply(patch_file)
git.apply(patch_file, {reverse = patch_extra.reverse})
end
end

Expand All @@ -141,6 +144,6 @@ function main(package)

-- do all patches
for _, patchinfo in ipairs(patches) do
_patch(package, patchinfo.url, patchinfo.sha256)
_patch(package, patchinfo)
end
end

0 comments on commit 9b8384f

Please sign in to comment.