diff options
| author | ruki <[email protected]> | 2019-03-26 22:41:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-03-26 10:09:13 +0800 |
| commit | baa44e2c153a39558968740b5799b26ed7f546df (patch) | |
| tree | 490b9044bccec99d973fc806d8690214f88912b7 | |
| parent | 68c02694b246cd6e11e3d18e8cb4327877144c74 (diff) | |
uses git.apply to instead of patch
| -rw-r--r-- | xmake/actions/require/impl/action/patch.lua | 34 | ||||
| -rw-r--r-- | xmake/actions/require/impl/package.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/devel/git/apply.lua | 67 |
3 files changed, 81 insertions, 26 deletions
diff --git a/xmake/actions/require/impl/action/patch.lua b/xmake/actions/require/impl/action/patch.lua index da75ac521..796ebb0f6 100644 --- a/xmake/actions/require/impl/action/patch.lua +++ b/xmake/actions/require/impl/action/patch.lua @@ -23,13 +23,16 @@ -- -- imports -import("lib.detect.find_tool") import("core.base.option") import("net.http") +import("devel.git") --- download patch file -function _dowload_patch_file(package, patch_url, patch_hash) - +-- do patch +function _patch(package, patch_url, patch_hash) + + -- trace + vprint("patching %s to %s-%s ..", patch_url, package:name(), package:version_str()) + -- get the patch file local patch_file = path.join(os.tmpdir(), "patches", package:name(), package:version_str(), path.filename(patch_url)) @@ -65,25 +68,9 @@ function _dowload_patch_file(package, patch_url, patch_hash) raise("patch(%s): unmatched checksum!", patch_url) end end - return patch_file -end - --- apply patch file -function _apply_patch_file(package, patch, patch_file) - os.vrunv(patch.program, {"-p1", "-t", "-i", patch_file}) -end - --- do patch -function _patch(package, patch, patch_url, patch_hash) - - -- trace - vprint("patching %s to %s-%s ..", patch_url, package:name(), package:version_str()) - - -- download the patch file - local patch_file = _dowload_patch_file(package, patch_url, patch_hash) -- apply the patch file - _apply_patch_file(package, patch, patch_file) + git.apply(patch_file) end -- patch the given package @@ -95,11 +82,8 @@ function main(package) return end - -- find patch tool - local patch = assert(find_tool("patch"), "patch not found!") - -- do all patches for _, patchinfo in ipairs(patches) do - _patch(package, patch, patchinfo[1], patchinfo[2]) + _patch(package, patchinfo[1], patchinfo[2]) end end diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua index 6e2978a32..c59323b09 100644 --- a/xmake/actions/require/impl/package.lua +++ b/xmake/actions/require/impl/package.lua @@ -473,9 +473,12 @@ function _get_confirm(packages) return confirm end --- patch some dependent builtin packages +-- patch some builtin dependent packages function _patch_packages(packages_install, packages_download) + -- @NOTE use git.apply instead of patch + -- we can add some builtin packages like this + --[[ -- add package(patch) local patched_package = nil for _, package in ipairs(packages_install) do @@ -497,6 +500,7 @@ function _patch_packages(packages_install, packages_download) patched_package:deps_add(package) end end + ]] end -- install packages diff --git a/xmake/modules/devel/git/apply.lua b/xmake/modules/devel/git/apply.lua new file mode 100644 index 000000000..b5749b7cc --- /dev/null +++ b/xmake/modules/devel/git/apply.lua @@ -0,0 +1,67 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file apply.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") + +-- apply remote commits +-- +-- @param opt the argument options +-- +-- @code +-- +-- import("devel.git") +-- +-- git.apply("xxx.patch") +-- git.apply("xxx.diff") +-- +-- @endcode +-- +function main(patchfile, opt) + + -- find git + local git = find_tool("git") + if not git then + return + end + + -- init argv + opt = opt or {} + local argv = {"apply", "--reject", patchfile} + + -- enter repository directory + local oldir = nil + if opt.repodir then + oldir = os.cd(opt.repodir) + end + + -- apply it + os.vrunv(git.program, argv) + + -- leave repository directory + if oldir then + os.cd(oldir) + end +end |
