您的位置:首页 > 产品设计 > UI/UE

git生成patch,应用到rpmbuild 打补丁

2017-08-09 10:30 465 查看
git diff > test.patch

git format-patch

不要再用diff命令 对比生成patch了,太土

原来的rpm制作,打patch方法(土):

http://blog.csdn.net/qq_26437925/article/details/73864258

centos下 rpm制作

运行环境

[root@localhost myrpm_build]# uname -a
Linux localhost 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux


不同的运行环境需要调整自己的spec文件

[root@localhost myrpm_build]# tree helloworld-0.1
helloworld-0.1
├── configure
├── helloworld.c
└── readme

0 directories, 3 files
[root@localhost myrpm_build]#


configure

#!/bin/sh
cat >Makefile  << EOF
all:helloworld
helloworld.o:helloworld.c
gcc -c helloworld.c
helloworld:helloworld.o
gcc helloworld.o -o helloworld
fresh:
rm -f Makefile
clean:
rm -f helloworld helloworld.o
install:
cp helloworld /usr/bin
uninstall:
rm -f /usr/bin/helloworld
EOF


helloword.c

#include <stdio.h>

int main()
{
printf("Hello World!\n");
return 0;
}


helloworld.spec

Summary:the first rpm
Name:helloworld
Version:0.1
Release:1%{?dist}
Vendor:john
License:Share
Group:Applications/Text
Source0:%{name}-%{version}.tar.gz

# add patch

%description
helloworld.rpm build test

%prep
export RPM_SOURCES_DIR=/root/rpmbuild/SOURCES
export RPM_BUILD_DIR=/root/rpmbuild/BUILD
tar -xzvf $RPM_SOURCES_DIR/%{name}-%{version}.tar.gz

%build
cd $RPM_BUILD_DIR/%{name}-%{version}
./configure
make

%install
cd $RPM_BUILD_DIR/%{name}-%{version}
make install
mkdir -p /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/
cp $RPM_BUILD_DIR/%{name}-%{version}/%{name} /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/

%clean
rm -rf $RPM_BUILD_DIR/%{name}-%{version}

%files
%defattr(-,root,root)
/usr/bin/%{name}

%doc $RPM_BUILD_DIR/%{name}-%{version}/readme


如下两句是由于rpmbuild -ba helloworld.spec报错,根据报错信息添加的,可能不同的平台不同,也可能不需要

mkdir -p /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/

cp $RPM_BUILD_DIR/%{name}-%{version}/%{name} /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/


文件全部完成后,tar,并rpmbuild检查结果

tar -czvf helloworld-0.1.tar.gz helloworld-0.1/

cp helloworld-0.1.tar.gz /root/rpmbuild/SOURCES

rpmbuild -ba helloworld.spec


git patch应用到rpmbuild

主要是git库可以方便的管理文件,并生成patch文件(这里都是本地操作,所以git push这种命令是没有的,用户配置也不需要,你只需要一个高版本的git)







修改helloworld.c后并提交



生成patch

确定git版本是支持 git format-patch命令的,下面是我用windows的实验(我的虚拟机centos没装好高版本的git)

仍然是两个提交日志



生成最近的两个patch文件

git format-patch -2




可以直接查看patch文件,linux下可以直接vim打开



如下把 0002-fix-bug.patch 打上,重新生成rpm

1 先把 0002-fix-bug.patch 文件复制到/root/rpmbuild/SOURCES下面,与原来的helloworld-0.1.tar.gz一起

2 修改helloworld.spec文件,修改后的文件如下

注意打patch的位置

Summary:the first rpm
Name:helloworld
Version:0.1
Release:1%{?dist}
Vendor:john
License:Share
Group:Applications/Text
Source0:%{name}-%{version}.tar.gz

# add patch
Patch1:0002-fix-bug.patch

%description
helloworld.rpm build test

%prep
export RPM_SOURCES_DIR=/root/rpmbuild/SOURCES
export RPM_BUILD_DIR=/root/rpmbuild/BUILD
tar -xzvf $RPM_SOURCES_DIR/%{name}-%{version}.tar.gz

%setup
%patch1 -p1

%build
cd $RPM_BUILD_DIR/%{name}-%{version}
./configure
make

%install
cd $RPM_BUILD_DIR/%{name}-%{version}
make install
mkdir -p /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/
cp $RPM_BUILD_DIR/%{name}-%{version}/%{name} /root/rpmbuild/BUILDROOT/%{name}-%{version}-1.el6.x86_64/usr/bin/

%clean
rm -rf $RPM_BUILD_DIR/%{name}-%{version}

%files
%defattr(-,root,root)
/usr/bin/%{name}

%doc $RPM_BUILD_DIR/%{name}-%{version}/readme


3 rpmbuild -ba helloworld.spec ,并验证

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: