mock知识点——SCM插件(mock编译git仓库的包)

0 前言

本文翻译自mock官方文档:https://rpm-software-management.github.io/mock/Plugin-Scm
其中实验环节内容为本地环境验证,实验环境:

CPU		:龙芯 3A5000
操作系统	:Loongnix Server 8.4
mock版本	:3.5(拉取上游源码编译)

SCM:Software configuration management(软件配置管理)。
通过安装mock-scm插件之后,可以使用mock直接编译存放到源上的软件包。

1 SCM插件

这个插件提供了与Scm系统(Git, Svn…)的集成。

这个模块没有使用Mock的插件基础设施,而是作为一个独立的包(mock-scm)提供,所以我们也把它称为插件。

1.1 配置

在你的配置文件中插入以下几行:

config_opts['scm'] = True
config_opts['scm_opts']['method'] = 'git'
config_opts['scm_opts']['cvs_get'] = 'cvs -d /srv/cvs co SCM_BRN SCM_PKG'
config_opts['scm_opts']['git_get'] = 'git clone --depth 1 SCM_BRN git://localhost/SCM_PKG.git SCM_PKG'
config_opts['scm_opts']['svn_get'] = 'svn co file:///srv/svn/SCM_PKG/SCM_BRN SCM_PKG'
config_opts['scm_opts']['distgit_get'] = 'rpkg clone -a --branch SCM_BRN SCM_PKG SCM_PKG'
config_opts['scm_opts']['distgit_src_get'] = 'rpkg sources'
config_opts['scm_opts']['spec'] = 'SCM_PKG.spec'
config_opts['scm_opts']['ext_src_dir'] = '/dev/null'
config_opts['scm_opts']['write_tar'] = True
config_opts['scm_opts']['git_timestamps'] = True
config_opts['scm_opts']['exclude_vcs'] = True
config_opts['scm_opts']['package'] = 'mypkg'
config_opts['scm_opts']['branch'] = 'master'

虽然你可以在配置文件中指定,但是这样做不太灵活。所以你可能宁愿使用命令行选项。例如,config_opts['scm_opts']['method'] = 'git'--scm-option method=git 等价,或者 config_opts['scm_opts']['branch'] = 'master' --scm-option branch=master 等价。

1.2 配置解析

1.2.1 Tar file

write_tar设置为True或者/var/lib/mock/root/builddir/build/SOURCES/包含`.write_tar`时。Mock将从整个SVN repo创建tar文件。这可能就是你想做的事,否则你必须手动创建tar文件,并在运行mock命令前把它放在那里。

扩展和压缩方法是根据你在spec文件中的Source行内容自动选择的。因此,如果有:

Source: http://foo.com/%{name}-%{version}.tar.xz

那么mock将创建以.tar.xz为扩展名并由xz压缩的tar文件。同样,如果你选择.tar.gz或.tar.bz2或任何其他已知的扩展名,mock也会按照对应规则去处理。

1.2.2 git_timestamps

git_timestamps 设置为 True 时,GIT 中每个文件的修改时间将更改为与该文件相关的最后一次提交的日期时间。这个选项只对Git方法有效,对其他方法无效。

1.2.3 exclude-vcs

exclude-vcs 设置为 True 时,--exclude-vcs 选项将传递给 tar 命令。

1.2.4 ext_src_dir

当你的源文件(或补丁文件)不在/var/lib/mock/<chroot>/root/builddir/build/SOURCES/目录中时,它会在 ext_src_dir中查找并复制到那里。

1.2.5 dist-git

从 1.3.4 版本开始,支持dist-git。 事实上它可以支持任何 DistSVN 或 DistCVS 方法。 您只需指定克隆仓库的命令 (distgit_get) 和检索仓库的命令 (distgit_src_get)。 然后 Mock-scm 将从这些spec文件和源码构建 SRPM。 不要忘记指定 config_opts['scm_opts']['method'] = 'distgit'

1.3 示例验证

在这个例子中,mock将克隆github.com/xsuchy/rpmconf.gitmaster分支,并使用该目录下的./rpmconf.spec来构建rpm包(原文内容)。

实际上的做这个实验时遇到了两个问题,1)github遇到了墙,所以我把这个克隆了一份到gitee仓库;2)目前上游的默认主分支名称为main。当然我是给loongnix编译软件包,所以使用的chroot配置文件为loongnix-8-loongarch6。所以最后使用的命令与原文稍微有一点点出入,如下所示:

[huangyang@bogon ~]$ mock -r loongnix-8-loongarch64 \
					--scm-enable  \
				    --scm-option method=git \
				    --scm-option package=rpmconf \
				    --scm-option spec=rpmconf.spec \
				    --scm-option branch=main \
				    --scm-option write_tar=True \
				    --scm-option git_get='git clone https://gitee.com/streamlet_hy/rpmconf.git'

INFO: mock.py version 2.9 starting (python version = 3.6.8, NVR = mock-2.9-1.lns8)...
Start(bootstrap): init plugins
INFO: selinux disabled
Finish(bootstrap): init plugins
Start: init plugins
INFO: selinux disabled
Finish: init plugins
INFO: Signal handler active
Start: run
INFO: Start(/tmp/tmpnh5t7851.mock-scm.rpmconf/rpmconf/rpmconf.spec)  Config(loongnix-8-loongarch64)
Start: clean chroot
......
Processing files: rpmconf-base-1.1.8-1.lns8.noarch
Provides: rpmconf-base = 1.1.8-1.lns8
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /builddir/build/BUILDROOT/rpmconf-1.1.8-1.lns8.loongarch64
Wrote: /builddir/build/RPMS/rpmconf-1.1.8-1.lns8.noarch.rpm
Wrote: /builddir/build/RPMS/python3-rpmconf-1.1.8-1.lns8.noarch.rpm
Wrote: /builddir/build/RPMS/python3-rpmconf-doc-1.1.8-1.lns8.noarch.rpm
Wrote: /builddir/build/RPMS/rpmconf-base-1.1.8-1.lns8.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.Dr6RPf
+ umask 022
+ cd /builddir/build/BUILD
+ cd rpmconf-1.1.8
+ /usr/bin/rm -rf /builddir/build/BUILDROOT/rpmconf-1.1.8-1.lns8.loongarch64
+ exit 0
Finish: rpmbuild rpmconf-1.1.8-1.lns8.src.rpm
Finish: build phase for rpmconf-1.1.8-1.lns8.src.rpm
INFO: Done(/var/lib/mock/loongnix-8-loongarch64/result/rpmconf-1.1.8-1.lns8.src.rpm) Config(loongnix-8-loongarch64) 0 minutes 33 seconds
INFO: Results and/or logs in: /var/lib/mock/loongnix-8-loongarch64/result
Finish: run
[huangyang@bogon ~]$

或者也可以这样做:

[huangyang@bogon ~]$ sudo cp /etc/mock/loongnix-8-loongarch64.cfg ./my-config.cfg
vi ./my-config.cfg

然后添加下面这些内容:

config_opts['scm'] = True
config_opts['scm_opts']['method'] = 'git'
config_opts['scm_opts']['git_get'] = 'git clone https://gitee.com/streamlet_hy/rpmconf.git'
config_opts['scm_opts']['spec'] = 'rpmconf.spec'
config_opts['scm_opts']['write_tar'] = True
config_opts['scm_opts']['package'] = 'rpmconf'
config_opts['scm_opts']['branch'] = 'main'

然后就可以这样执行mock命令:

[huangyang@bogon ~]$ mock -r ./my-config.cfg
posted @ 2023-02-13 17:33  streamlet_hy  阅读(83)  评论(0编辑  收藏  举报  来源