日常开发中经常会遇到打补丁及生成补丁的问题,如果版本管理工具使用git,那么可以使用git format-patch n 为近期的n次提交生成patch。当然也可以使用diff 生成某一个文件的patch。
本文主要是使用quilt来解决没有使用git管理的场景中如何生成多个文件的patch。
问题场景
工作中不可避免的需要使用开源的一些库,由于开发环境或者需求特殊性,我们需要去修改源代码。为了后期版本的可追溯及版本的一致性,一般会将某一个版本的修改最终生成一个patch,在每次编译的时候将patch 打入即可。
quilt 安装
ubuntu20.04默认是没有安装quilt,需要自行安装
sudo apt-get install quilt
quilt help 产看支持的功能
quilt --help
Usage: quilt [--trace[=verbose]] [--quiltrc=XX] command [-h] ...
quilt --version
Commands are:
add fold mail refresh snapshot
annotate fork new remove top
applied graph next rename unapplied
delete grep patches revert upgrade
diff header pop series
edit import previous setup
files init push shell
Global options:
--trace
Runs the command in bash trace mode (-x). For internal debugging.
--quiltrc file
Use the specified configuration file instead of ~/.quiltrc (or
/etc/quilt.quiltrc if ~/.quiltrc does not exist). See the pdf
documentation for details about its possible contents. The
special value "-" causes quilt not to read any configuration
file.
--version
Print the version number and exit immediately.
quilt 创建一个patch的步骤
例如r329_tina/package/libs/libgpg-error在ubunut18.04编译没有问题,但是在ubuntu20.04中编译中会报错如下,下面以ubuntu20.04生成libgpg-error的patch解决编译的问题。
gawk: ./mkerrcodes.awk:88: warning: regexp escape sequence `\#' is not a known regexp operator
rm _mkerrcodes.h
cc -I. -I. -o mkerrcodes ./mkerrcodes.c
./mkerrcodes | gawk -f ./mkerrcodes2.awk >code-from-errno.h
gawk: ./mkerrcodes2.awk:94: warning: regexp escape sequence `\#' is not a known regexp operator
gawk -f ./mkstrtable.awk -v textidx=2 -v nogettext=1 \
./err-sources.h.in >err-sources-sym.h
gawk: ./mkstrtable.awk:113: warning: regexp escape sequence `\#' is not a known regexp operator
gawk -f ./mkstrtable.awk -v textidx=2 -v nogettext=1 \
./err-codes.h.in >err-codes-sym.h
gawk: ./mkstrtable.awk:113: warning: regexp escape sequence `\#' is not a known regexp operator
gawk -f ./mkstrtable.awk -v textidx=2 -v nogettext=1 \
-v prefix=GPG_ERR_ -v namespace=errnos_ \
./errnos.in >errnos-sym.h
gawk: fatal: cannot use gawk builtin `namespace' as variable name
step1
quilt new 0001-libgpg-error-fix-gawk.patch #create the patch
step2
quilt add $FILE_NAME #add files to be patched
#-- add the file before changing it
Step 3:
Edit files
Step 4:
quilt refresh #update the patch
最终将生成的patch文件拷贝保存patchs 的目录即可。这样就生成了libgpg-error 这个开源包基于ubuntu20.04编译的补丁包,以上只是简单介绍了解决问题的过程。
参考资源:
Quilt Patching Tips | Quilt Linux | Why Patch Open Source Packages