根据openwrt软件包版本应用补丁 [英] apply the patches based on openwrt package version

查看:104
本文介绍了根据openwrt软件包版本应用补丁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,在openwrt中,特定软件包的补丁通常应放在package/[pkg]/patches中它将通过$(Build/Patch)在Makefile中应用.示例:

  • package/test/0001-1.0.1.8.fix-A.patch

  • package/test/0002-1.0.1.8.fix-B.patch

当软件包更新到新版本时,有时还需要更新补丁.示例:

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

OR

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

对于单个特定的软件包版本,此方法效果很好.唯一的事情就是手动更新软件包的版本和补丁.

出于某种原因,升级pacakge时无法应用旧补丁并将其提交到软件包源.因此必须通过补丁对其进行维护.

我正在做的是,如果Makefile可以根据软件包版本自动找到正确的补丁程序.我选择将所有这些补丁放入"package/test/file/patches/"基于软件包版本的目录,例如:

  • package/test/file/patches/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
  • package/test/file/patches/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
  • package/test/file/patches/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

在Makefile中,应将正确的补丁复制到"package/test/patches/"文件中.首先在定义构建/准备"目录中找到该目录.部分,位于$(Build/Patch)之前.

匹配规则:(我不知道如何在此处插入表格,而是放置图片...)

匹配最新版本

因此,以这种方式,所有补丁都可以存储在"pacakge/test"文件中.目录,它们将在构建时自动匹配并应用.

问题是,如何实现找到正确的比赛?由于比较和匹配版本有点复杂,尤其是在 Makefile 中而不是在shell脚本中.

实际上,我找到了一些有趣的脚本来完成其中的一部分,例如:

如何进行比较点中的两个字符串在点分隔的版本格式中

解决方案

虽然我不确定您要与哪个版本号比较哪个补丁,反之亦然,但以下代码段将为您提供解决方法的思路在 GNUmake表工具包的帮助下,通过 GNUmake 编程进行的任务为此类问题设计的:

  include gmtt/gmtt.mk#Helper函数可将数字列表转换为小数#每个原始版本位置的3位数字:vers-to-num = $(调用lpad,$(word 1,$ 1),3,0)$(调用lpad,$(word 3,$ 1),3,0)$(调用lpad,$(word 5,$ 1),3,0)$(调用lpad,$(word 7,$ 1),3,0)版本:= 1.1.1.4VERS_LIST:= $(调用全局匹配,$(word 1,$(VERSION)),*.*.*.*)$(信息VERS_LIST = $(VERS_LIST))VERS_NUM:= $(调用vers-to-num,$(VERS_LIST))$(信息$(VERS_NUM))补丁:= 1.0.2.0#补丁与版本的关系:#3列的表格:patch-nr |第一个适用版本|最后适用版本#如果只有一个版本,则必须将其同时放入两列(无空单元格!)定义PATCH_TO_VER:=31.0.1.8 1.0.1.8 1.0.1.81.0.1.9 1.0.1.9 1.0.1.91.0.2.0 1.0.2.0 1.1.1.31.1.1.4 1.1.1.4 1.1.3.9恩迪夫VA_VB:= $(呼叫选择,2 3,$(PATCH_TO_VER),$$(呼叫str-eq,$(PATCH),$$ 1))$(信息VA_VB = $(VA_VB))VA_LIST:= $(调用全局匹配,$(单词1,$(VA_VB)),*.*.*.*)VA_NUM:= $(调用num,$(VA_LIST))$(信息$(VA_NUM))VB_LIST:= $(调用全局匹配,$(单词2,$(VA_VB)),*.*.*.*)VB_NUM:= $(调用vers-to-num,$(VB_LIST))$(信息$(VB_NUM))#而不是将每个版本数字与上下数字进行比较#允许的值(如果这样做,if-else树会变得地狱,请尝试一下#您自己),我们使用的gmtt的数字范围功能至少为64#个数字比较版本:COMPARE_RESULT:= $(如果$(调用int-ge,$(VERS_NUM),$(VA_NUM)),$(如果$(调用int-le,$(VERS_NUM),$(VB_NUM)),是))$(范围内的信息补丁版本(empty = no):< $(COMPARE_RESULT)>) 

输出:

  VERS_LIST = 1.1.1.4001001001004VA_VB = 1.0.2.0 1.1.1.3001000002000001001001003范围内的补丁程序版本(空=否):<>使:***无目标.停止. 

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). Example:

  • package/test/0001-1.0.1.8.fix-A.patch

  • package/test/0002-1.0.1.8.fix-B.patch

When the package update to a new version, the patches sometimes also need to be updated. Example:

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

OR

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

For a single certain package version, this works well. The only thing is to update the package version and patches manually.

For a certion reason the old patch can not be applied and submit to package source when pacakge upgrade. 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. I choose to put all these patches in "package/test/file/patches/" directory base on package verion, such as:

  • package/test/file/patches/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
  • package/test/file/patches/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
  • package/test/file/patches/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

In the Makefile, the right patches should be copied to "package/test/patches/" directory first in "define Build/Prepare" section, before $(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.

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.

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

解决方案

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:

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:

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.

这篇关于根据openwrt软件包版本应用补丁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆