简体   繁体   English

应用基于openwrt package版本的补丁

[英]apply the patches based on openwrt package version

In openwrt, as we known, usually the patches for a certain package should be put in package/[pkg]/patches and it will be applied in Makefile via $(Build/Patch).我们知道,在openwrt中,通常某个package的补丁应该放在package/[pkg]/patches中,它会通过$(Build/Patch)应用到Makefile中。 Example:例子:

  • package/test/0001-1.0.1.8.fix-A.patch包/测试/0001-1.0.1.8.fix-A.patch

  • package/test/0002-1.0.1.8.fix-B.patch包/测试/0002-1.0.1.8.fix-B.patch

When the package update to a new version, the patches sometimes also need to be updated.当package更新到新版本时,补丁有时也需要更新。 Example:例子:

  • package/test/0001-1.0.1.9.fix-A.patch包/测试/0001-1.0.1.9.fix-A.patch
  • package/test/0002-1.0.1.9.fix-B.patch包/测试/0002-1.0.1.9.fix-B.patch

OR或者

  • package/test/0001-1.0.2.0.fix-A.patch包/测试/0001-1.0.2.0.fix-A.patch
  • package/test/0002-1.0.2.0.fix-B.patch包/测试/0002-1.0.2.0.fix-B.patch

For a single certain package version, this works well.对于单个某个 package 版本来说,这个效果很好。 The only thing is to update the package version and patches manually.唯一的事情是手动更新 package 版本和补丁。

For a certion reason the old patch can not be applied and submit to package source when pacakge upgrade.由于某种原因,旧补丁无法在升级包时应用并提交到 package 源。 So they have to be maintained via patches.所以它们必须通过补丁来维护。

What I am doing is that, if the Makefile could automatically find the right patches based on the package version.我正在做的是,如果 Makefile 可以根据 package 版本自动找到正确的补丁。 I choose to put all these patches in "package/test/file/patches/" directory base on package verion, such as:我选择将所有这些补丁放在 package 版本的“package/test/file/patches/”目录中,例如:

  • package/test/file/patches/1.0.1.8/0001-v1.0.1.8.fix-A.patch包/测试/文件/补丁/1.0.1.8/0001-v1.0.1.8.fix-A.patch
  • package/test/file/patches/1.0.1.8/0002-1.0.1.8.fix-B.patch包/测试/文件/补丁/1.0.1.8/0002-1.0.1.8.fix-B.patch
  • package/test/file/patches/1.0.1.9/0001-1.0.1.9.fix-A.patch包/测试/文件/补丁/1.0.1.9/0001-1.0.1.9.fix-A.patch
  • package/test/file/patches/1.0.1.9/0002-1.0.1.9.fix-B.patch包/测试/文件/补丁/1.0.1.9/0002-1.0.1.9.fix-B.patch
  • package/test/file/patches/1.0.2.0/0001-1.0.2.0.fix-A.patch包/测试/文件/补丁/1.0.2.0/0001-1.0.2.0.fix-A.patch
  • package/test/file/patches/1.0.2.0/0002-1.0.2.0.fix-B.patch包/测试/文件/补丁/1.0.2.0/0002-1.0.2.0.fix-B.patch

In the Makefile, the right patches should be copied to "package/test/patches/" directory first in "define Build/Prepare" section, before $(Build/Patch).在 Makefile 中,应首先在“define Build/Prepare”部分中将正确的补丁复制到“package/test/patches/”目录,然后再复制到 $(Build/Patch)。

Match rule: (I don't know how to insert a table here, I put an image instead...)匹配规则:(这里不知道怎么插入表格,我放了一张图片代替...)

match the latest version匹配最新版本

So, in this way, all the patches can be stored in the "pacakge/test" directory and they will be auto matched and applied when building.因此,通过这种方式,所有补丁都可以存储在“pacakge/test”目录中,并在构建时自动匹配和应用。

The question is, how can I achieve to find out the right match ?问题是,我怎样才能找到正确的匹配 Since it's a little complex to compare and match the version, especially in Makefile rather than in shell script.因为比较和匹配版本有点复杂,特别是在Makefile而不是 shell 脚本中。

Actually I found some interesting script to do part of this, such as:实际上我发现了一些有趣的脚本来做这部分,例如:

how-to-compare-two-strings-in-dot-separated-version-format-in-bash 如何在 bash 中比较两个字符串中的点分隔版本格式

While I don't exactly understand which version number you want to compare to which patch or the other way around, the following snippet will give you an idea how solve the task with GNUmake programming with the help of the GNUmake table toolkit which was designed for such problems:虽然我不完全了解您想要将哪个版本号与哪个补丁进行比较或相反,但下面的代码片段将让您了解如何借助GNUmake表工具包来解决该任务,该工具包是为此类问题:

include gmtt/gmtt.mk

# Helper function which converts a list of numbers into a decimal
# number with 3 digits per original version place:
vers-to-num = $(call lpad,$(word 1,$1),3,0)$(call lpad,$(word 3,$1),3,0)$(call lpad,$(word 5,$1),3,0)$(call lpad,$(word 7,$1),3,0)

VERSION := 1.1.1.4
VERS_LIST := $(call glob-match,$(word 1,$(VERSION)),*.*.*.*)
$(info VERS_LIST = $(VERS_LIST))

VERS_NUM := $(call vers-to-num,$(VERS_LIST))
$(info $(VERS_NUM))


PATCH := 1.0.2.0


# Patch to version relation:
# Table with 3 columns: patch-nr | first applicable version | last applicable version
# In case there is only one version it has to go into both columns (no empty cells!)
define PATCH_TO_VER :=
3
1.0.1.8   1.0.1.8   1.0.1.8
1.0.1.9   1.0.1.9   1.0.1.9
1.0.2.0   1.0.2.0   1.1.1.3
1.1.1.4   1.1.1.4   1.1.3.9
endef

VA_VB := $(call select,2 3,$(PATCH_TO_VER),$$(call str-eq,$(PATCH),$$1))
$(info VA_VB = $(VA_VB))

VA_LIST := $(call glob-match,$(word 1,$(VA_VB)),*.*.*.*)
VA_NUM := $(call vers-to-num,$(VA_LIST))
$(info $(VA_NUM))

VB_LIST := $(call glob-match,$(word 2,$(VA_VB)),*.*.*.*)
VB_NUM := $(call vers-to-num,$(VB_LIST))
$(info $(VB_NUM))

# Instead of comparing each version digit against upper and lower
# allowed value (the if-else tree for this gets hellish, try it
# yourself) we use gmtt's numeric range capability of at least 64
# digits to compare versions :
COMPARE_RESULT := $(if $(call int-ge,$(VERS_NUM),$(VA_NUM)),$(if $(call int-le,$(VERS_NUM),$(VB_NUM)),yes))

$(info patch version in range (empty=no): <$(COMPARE_RESULT)>)
                                                                                                                                                                                                                                             

Output: Output:

VERS_LIST =  1 . 1 . 1 . 4
001001001004
VA_VB = 1.0.2.0 1.1.1.3
001000002000
001001001003
patch version in range (empty=no): <>
make: *** No targets.  Stop.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM