Difference between revisions of "VCS package guidelines (简体中文)"

From ArchWiki
Jump to: navigation, search
m (update category.)
(20 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{i18n_links_start}}
+
[[Category:Package development (简体中文)]]
{{i18n_entry|English|Arch CVS & SVN & GIT PKGBUILD guidelines}}
+
[[en:VCS PKGBUILD Guidelines]]
{{i18n_entry|繁體中文|Arch CVS & SVN & GIT PKGBUILD 編寫指南}}
+
[[it:VCS PKGBUILD Guidelines]]
{{i18n_entry|间体中文|Arch CVS & SVN & GIT PKGBUILD 编写指南}}
+
[[zh-TW:VCS PKGBUILD Guidelines]]
{{i18n_links_end}}
+
{{Package Guidelines}}
 +
{{Translateme (简体中文)}}
 +
[[Wikipedia:Revision_control|Version control systems]] can be used for retrieval of source code for both usual statically versioned packages and latest (trunk) version of packages. This article covers both cases.
  
[[Category:Package Management]]
+
== Prototypes ==
==用 makepkg 打包 CVS, SVN & GIT 文件==
+
  
事实上,这个工作非常简单,您不需要什么特殊的知识。不管怎么样,您对CVS和SVN的知识懂得越多越好。很多人在 PKGBUILD 文件里面引入了不必要(译注:这个词是译者加的,在尽量不影响理解的前提下,译者可能会不自觉的使用自己的语言,后面不再声明)的自定义变量,这样会使工作变得复杂。这些看起来很复杂的语句并不是''必须的'',但是对于使语法结构清洗,是很有帮助的。
+
The [[ABS]] package provides prototypes for [[cvs]], [[svn]], [[git]], [[mercurial]], and [[Wikipedia:darcs|darcs]] [[PKGBUILD]]s. When {{Pkg|abs}} is installed, you can find them in {{ic|/usr/share/pacman}}. Latest versions can be found in the [https://projects.archlinux.org/abs.git/tree/prototypes prototypes directory in the ABS Git repository].
  
===一些小提示===
+
== Guidelines ==
  
* 给 <code>pkgname</code> 加上 <code>-cvs</code> 或者 <code>-svn</code> 或者 <code>-git</code> 这样的后缀 (where applicable, 这个不知道怎么翻译) - 这样可以防止和非devel版本的包名混淆,比如 fluxbox-svn , fvwm-cvs 对 fluxbox , fvwm.
+
* Suffix {{Ic|pkgname}} with {{Ic|-cvs}}, {{Ic|-svn}}, {{Ic|-hg}}, {{Ic|-darcs}}, {{Ic|-bzr}}, {{Ic|-git}} etc. unless the package fetches a specific release.
* 您还必须小心处理 pacman 的冲突(依赖关系冲突)。比如 fluxbox-svn will 与 fluxbox 冲突。这样您就需要使用 <tt>conflicts=</tt> 字段(field)
+
conflicts=('fluxbox')
+
: 您还应该使用 <tt>provides=</tt> 字段,以便让需要 fluxbox (作者这里用fluxbox来举例)的包知道 fluxbox-svn 就是 fluxbox
+
provides=('fluxbox')
+
: 您最好不要使用(your should avoid using) <tt>replaces=</tt> ,它可能会产生不必要的麻烦
+
*When using/defining the cvsroot use anonymous<b>:</b>@ rather than anonymous@ to avoid having to press enter to give blank password ''OR'' anonymous<b>:password</b>@ - if a password is required.
+
* cvs and svn PKGBUILDs may not require a source or md5sum array but these fields '''must''' be included in the PKGBUILD if you wish to submit it to the AUR, otherwise the pkg will be rejected.  They may be left blank though.
+
<pre>source=()
+
md5sums=()</pre>
+
* 使用 CVS/SVN/GIT 的时候,我们极少用到 pkgrel 字段,因为源文件时有改动,所以我们通常用 pkgver 来标记改动(假定我们用 pkgver 来保存日期)(英文原文:It is rarely necessary to use the pkgrel field when building CVS/SVN/GIT pkgs - any changes to the pkg will often be on another day and so are usually accounted for by a change in pkgver (assuming pkgver is used to hold a date format),英语不到家,有人会翻译的mail:fluke at sfcube.net)
+
* 不要忘记把 svn 或者 cvs 包含在 <code>makedepends=</code> 里面,如果必须的话(译注:如果你要从 svn 来 checkout 源码包,自然要要保证你有 svn 客户端)
+
* 为了保证 check out(译注:cvs和svn的术语,就不翻译了) 下来的 code 的完整性,我们建立一个独立的 build 目录,比如你已经在 $startdir 把代码 ckeck out 到了 src/$_cvsmod 目录你可以:
+
<pre>  mkdir src/$_cvsmod-build
+
  
  cd src/$_cvsmod-build
+
* If the resulting package is different after changing the dependencies, URL, sources, etc. increasing the {{Ic|pkgrel}} is mandatory. Touching the {{ic|pkgver}} isn't.
  ../$_cvsmod/configure</pre>
+
''万一'' 这种方法失败了,你可以尝试:
+
<pre>  cp -r src/$_cvsmod src/$_cvsmod-build
+
  cd src/$_cvsmod-build</pre>
+
  
* AUR的介绍中说最重要的是不要使用 backtick 扩展去创建 pkg 变量(With the introduction of the AUR it is most important to avoid using backtick execution to create pkg variables)
+
* {{Ic|--holdver}} can be used to prevent [[makepkg]] from updating the {{ic|pkgver}} (see: [https://www.archlinux.org/pacman/makepkg.8.html makepkg(8)])
** 对于 cvs 包 您应该避免 <code>pkgver=`date +%y%m%d`</code> - (译注:this also inteferes with the functionality of the AUR.,这句话不好翻译,我不知道inteferes什么意思) 作为替代的方案,还可以用日期格式的 $pkgver 变量,并且使用 cvs -D 去获取从那个日期起的代码 (看下面)
+
** 对于 svn 您可以使用修正号(revision number)。下面是一种简易的获取修正号的方法:
+
svn log $_svntrunk --limit 1 | grep -m 1 -o "r.*" | cut -d \| -f 1 | sed s@r@@g
+
这条命令从 svn repo (译注:就是 svn 的源)最近额记录里面取得修正号--修正号的前面带有''r''字母。下面的来自于 fluxbox 的 svn 记录,修正号就在左上角,r4084。
+
<pre>
+
------------------------------------------------------------------------
+
r4084 | mathias | 2005-07-20 19:29:01 +0100 (Wed, 20 Jul 2005) | 16 lines
+
  
Changed some *Focus options, just to make some things a bit more clear.
+
* Include what the package conflicts with and provides (e.g. for {{AUR|fluxbox-git}}: {{Ic|1=conflicts=('fluxbox')}} and {{Ic|1=provides=('fluxbox')}}).
the "Sloppy" was always a bit .. unprecise.
+
</pre>
+
  
===CVS PKGBUILD 样例===
+
* {{Ic|1=replaces=()}} generally causes unnecessary problems and should be avoided.
  
这里用一个 bmp-cvs 的 PKGBUILD 来说明上面的一些技巧(一些小提示)
+
* When using the cvsroot, use {{Ic|anonymous:@}} rather than {{Ic|anonymous@}} to avoid having to enter a blank password or {{Ic|anonymous:password@}}, if one is required.
  
<pre># Contributor:  Lukas Sabota <punkrockguy318@comcast.net>
+
* Include the appropriate VCS tool in {{Ic|1=makedepends}} ({{pkg|cvs}}, {{pkg|subversion}}, {{pkg|git}}, ...).
# Contributor: dibblethewrecker dibblethewrecker.at.jiwe.dot.org
+
pkgname=bmp-cvs
+
pkgver=20050728
+
pkgrel=1
+
pkgdesc="BeepMP is a multimedia player that uses the WinAmp 2.x UI, GTK2, and is based on XMMS. This will checkout and package the latest CVS version."
+
url="http://beepmp.sourceforge.net/"
+
license=
+
depends=('gtk2' 'libvorbis' 'alsa-lib' 'audiofile' 'libglade' 'id3lib' 'x-server')
+
provides=('bmp')
+
conflicts=('bmp')
+
makedepends=('cvs')
+
install=$pkgname.install
+
  
_cvsroot=":pserver:anonymous:@cvs.sourceforge.net:/cvsroot/beepmp"
+
=== VCS sources ===
_cvsmod="bmp"
+
{{Note|Pacman 4.1 supports the following VCS sources: {{ic|bzr}}, {{ic|git}}, {{ic|hg}} and {{ic|svn}}. See the {{ic|fragment}} section of {{ic|man PKGBUILD}} or [https://www.archlinux.org/pacman/PKGBUILD.5.html PKGBUILD(5)] for a list of supported VCS.}}
  
build() {
+
Starting with {{Pkg|pacman}} 4.1, the VCS sources should be specified in the {{ic|1=source=()}} array and will be treated like any other source. {{ic|makepkg}} will clone/checkout/branch the repo into {{ic|$SRCDEST}} (same as {{ic|$startdir}} if not set in [https://www.archlinux.org/pacman/makepkg.conf.5.html makepkg.conf(5)]) and copy it to {{ic|$srcdir}} (in a specific way to each VCS). The local repo is left untouched, thus invalidating the need for a {{ic|-build}} directory.
  cd $startdir/src
+
  msg "Connecting to $_cvsmod.sourceforge.net CVS server...."
+
  cvs -z3 -d $_cvsroot co -D $pkgver -f $_cvsmod
+
  cd $_cvsmod
+
  ./autogen.sh
+
  
  msg "CVS checkout done or server timeout"
+
The general format of a VCS {{ic|1=source=()}} array is:
  msg "Starting make..."
+
source=('[folder::][vcs+]url[#fragment]')
  
  cp -r ../$_cvsmod ../$_cvsmod-build
+
* {{ic|folder}} (optional) is used to change the default repo name to something more relevant (e.g. than {{ic|trunk}}) or to preserve the previous sources
  cd ../$_cvsmod-build
+
* {{ic|vcs+}} is needed for URLs that do not reflect the VCS type, e.g. {{ic|git+http://some_repo}}.
 +
* {{ic|url}} is the URL to the distant or local repo
 +
* {{ic|#fragment}} (optional) is needed to pull a specific branch or commit
  
  ./configure --prefix=/usr
+
An example Git source array:
  make || return 1
+
source=('project_name::git+http://project_url#branch=project_branch')
  make DESTDIR=$startdir/pkg install || return 1
+
  
  mkdir -p $startdir/pkg/usr/share/xmms/Skins
+
=== The pkgver() function ===
  mv $startdir/pkg/usr/share/bmp/Skins/* $startdir/pkg/usr/share/xmms/Skins
+
The {{ic|pkgver}} autobump is now achieved via a dedicated {{ic|pkgver()}} function. This allows for better control over the {{ic|pkgver}}, and maintainers should favor a {{ic|pkgver}} that makes sense. Following are some examples for several VCS.
  rmdir $startdir/pkg/usr/share/bmp/Skins
+
  
  rm -r $startdir/src/$_cvsmod-build
+
==== Git ====
}
+
With tags:
# vim:syntax=sh
+
</pre>
+
  
===SVN PKGBUILD 样例===
+
pkgver() {
 +
  cd "$srcdir"/local_repo
 +
  git describe --always | sed 's|-|.|g'
 +
}
  
假如您第一次对 PKGBUILD 使用 <tt>source</tt> 命令,它会填充(store) _svntrunk 和 _svnmod 变量。所以如果您运行:
+
Without tags:
source PKGBUILD
+
svn log $_svntrunk --limit 1 | grep -m 1 -o "r.*" | cut -d \| -f 1 | sed s@r@@g
+
你可以得到用于 pkgver 的修正号
+
  
<pre>
+
  pkgver() {
# Contributor: Lukas Sabota <punkrockguy318@comcast.net>
+
  cd "$srcdir"/local_repo
# Contributor: dibblethewrecker dibblethewrecker.at.jiwe.dot.org
+
  echo "0.$(git rev-list --count HEAD).$(git describe --always)"
pkgname=fluxbox-svn
+
}
pkgver=4084
+
pkgrel=1
+
pkgdesc="Fluxbox-svn is the bleeding edge version of a lightweight yet \
+
customizable windowmanager for X. This will checkout and package the latest SVN version."
+
url="http://www.fluxbox.org"
+
depends=('bash' 'x-server')
+
makedepends=('subversion')
+
conflicts=('blackbox' 'fluxbox' 'fluxbox-devel' 'fluxbox-cvs')
+
replaces=('fluxbox-cvs')
+
provides=('fluxbox')
+
  
_svntrunk=svn://svn.berlios.de/fluxbox/trunk
+
Using the last commit date:
_svnmod=fluxbox
+
  
build() {
+
pkgver() {
  cd $startdir/src
+
  cd "$srcdir"/local_repo
 +
  git log -1 --format="%cd" --date=short | sed 's|-||g'
 +
}
  
  svn co $_svntrunk --config-dir ./ -r $pkgver $_svnmod
+
==== Subversion ====
  cd $_svnmod
+
pkgver() {
  ./autogen.sh
+
  cd "$SRCDEST"/local_repo
 +
  svnversion |tr -d [A-z]
 +
}
  
  msg "SVN checkout done or server timeout"
+
{{Note|The copy inside {{ic|$srcdir}} is made using {{ic|svn export}} which does not create working copies. Any {{ic|svn}} related command has to be used in the local repo, hence {{ic|$SRCDEST}}.}}
  msg "Starting make..."
+
  
  mkdir ../$_svnmod-build
+
==== Mercurial ====
  cd ../$_svnmod-build
+
pkgver() {
 +
  cd "$srcdir"/local_repo
 +
  hg identify -ni | awk 'BEGIN{OFS=".";} {print $2,$1}'
 +
}
  
  # fix for crap fb issue
+
==== Bazaar ====
  mkdir data
+
pkgver() {
  cp ../$_svnmod/data/keys data/
+
  cd "$srcdir"/local_repo
 +
  bzr revno
 +
}
  
  ../$_svnmod/configure --prefix=/usr --enable-xinerama --enable-imlib2 --enable-debug
+
==== Fallback ====
  #./configure --prefix=/usr --enable-xinerama --enable-imlib2 --enable-debug
+
The following can be used in case no satisfactory {{ic|pkgver}} can be extracted from the repo:
  make || return 1
+
  make DESTDIR=$startdir/pkg/ install
+
  
  rm -r $startdir/src/$_svnmod-build
+
pkgver() {
}
+
  date +"%Y%m%d"
# vim:syntax=sh</pre>
+
}
  
===GIT PKGBUILD 样例===
+
== Tips ==
  
<pre>
+
=== A sample Git PKGBUILD for pacman 4.1 ===
pkgname=compiz-git
+
# Maintainer: Dave Reisner <d@falconindy.com>  
pkgver=20060707
+
# Contributor: William Giokas (KaiSforza) <1007380@gmail.com>
pkgrel=1
+
pkgdesc="Composite and window manager for Xgl"
+
pkgname=expac-git
url="http://en.opensuse.org/Compiz"
+
_gitname=expac
license=""
+
pkgver=0.0.0
depends=('xgl-cvs' 'mesa-xgl-cvs' 'cairo-devel' 'libxevie' \
+
pkgrel=1
        'startup-notification' 'libpng'  'libxdamage' \
+
pkgdesc="Pacman database extraction utility"
        'libxrandr' 'libwnck-compiz' 'gnome-desktop' 'control-center' \
+
arch=('i686' 'x86_64')
         'libsvg-cairo' 'libxcomposite')
+
url="https://github.com/falconindy/expac"
makedepends=('git')
+
license=('MIT')
conflicts=()
+
depends=('pacman')
replaces=()
+
makedepends=('git' 'perl')
backup=()
+
conflicts=('expac')
install=compiz.install
+
  provides=('expac')
source=(compiz-intel-copy-pixel-issue-workaround-1.diff)
+
# Here is the fun bit. Makepkg knows it's a git repo because the URL starts with 'git'
md5sums=('10a157b86d528bca2be6731c5eaff7b3')
+
# it then knows to checkout the branch 'pacman41' upon cloning, expediating versioning:
 +
#source=('git+https://github.com/falconindy/expac.git'
 +
source=('git://github.com/falconindy/expac.git'
 +
         'expac_icon.png')
 +
# Because the sources are not static, skip Git checksum:
 +
md5sums=('SKIP'
 +
          '020c36e38466b68cbc7b3f93e2044b49')
 +
 +
pkgver() {
 +
  cd "$srcdir/$_gitname"
 +
  git describe --always | sed 's|-|.|g'
 +
  # To give the total count of commits and the hash of the last one
 +
  # (useful if you're making a repository with git packages so that they can have
 +
  # sequential version numbers, else a "pacman -Syu" may not update the package):
 +
  #echo "0.$(git rev-list --count $branch).$(git describe --always)"
 +
  # Using the last commit date:
 +
  #git log -1 --format="%cd" --date=short | sed 's|-||g'
 +
}
 +
 +
build() {
 +
  cd "$srcdir/$_gitname"
 +
  make
 +
}
 +
 +
package() {
 +
  cd "$srcdir/$_gitname"
 +
  make PREFIX=/usr DESTDIR="$pkgdir" install
 +
  install -Dm644 "$srcdir/expac_icon.png" "$pkgdir/usr/share/pixmaps/expac.png"
 +
}
  
_gitroot="git://anongit.freedesktop.org/git/xorg/app/compiz"
+
=== Removing VCS leftovers ===
_gitname="compiz"
+
To make sure that there are no VCS leftovers use the following at the end of the {{ic|package()}} function (replacing {{ic|'''.git'''}} with {{ic|.svn}}, {{ic|.hg}}, etc.):
build() {
+
find "$pkgdir" -type d -name "'''.git'''" -exec rm -r '{}' +
export CFLAGS="$CFLAGS -I/opt/mesa-xgl-cvs/include"
+
  cd $startdir/src
+
  msg "Connecting to git.freedesktop.org GIT server...."
+
  
  if [ -d $startdir/src/$_gitname ] ; then
+
=== SVN packages that try to get their revision number ===
  cd $_gitname && git-pull origin
+
If the build system for the program you are packaging calls {{ic|svnversion}} or {{ic|svn info}} to determine its revision number, you can add a {{ic|prepare()}} function similar to this one to make it work:
  msg "The local files are updated."
+
  else
+
  git clone $_gitroot
+
  fi
+
  
  msg "GIT checkout done or server timeout"
+
prepare() {
  msg "Starting make..."
+
  cp -a "$SRCDEST/$_svnmod/.svn" "$srcdir/$_svnmod/"
 +
}
  
  cp -r $startdir/src/$_gitname $startdir/src/$_gitname-build
+
== Troubleshooting ==
  cd $startdir/src/$_gitname-build
+
  patch -Np0 -i ${startdir}/src/compiz-intel-copy-pixel-issue-workaround-1.diff
+
  
  ACLOCAL="aclocal -I /opt/gnome/share/aclocal" ./autogen.sh --host=${CHOST} \
+
=== Bazaar limitation ===
    --prefix=/usr \
+
Currently, bazaar URLs only work in the form of {{ic|http://bazaar.launchpad.net/}}, e.g.:
    --infodir=/usr/share/info \
+
source=('project_name::bzr+http://bazaar.launchpad.net/~project_team/project_path')
    --mandir=/usr/man \
+
    --sysconfdir=/opt/gnome/etc \
+
    --enable-gnome \
+
    --enable-libsvg-cairo \
+
    --enable-gconf-dump \
+
    --disable-kde || return 1
+
  make || return 1
+
  make DESTDIR=$startdir/pkg install
+
  
  find $startdir/pkg -type f -name '*.la' -exec rm {} \;
+
Using any other {{ic|http://}}, {{ic|https://}} or {{ic|ssh://}} URL (including {{ic|lp:project_name}}) will prevent makepkg from updating the local repo.
}  
+
</pre>
+
如您所见,我在 pkgname 后面使用 "-git" 后缀,另外两个变量 -- _gitroot 和 _gitname 用来表示包的“源”和包名字。
+
我需要解释一个 if 条件:
+
<pre>
+
if [ -d $startdir/src/$_gitname ] ; then
+
cd $_gitname && git-pull origin
+
msg "The local files are updated."
+
else
+
git clone $_gitroot
+
fi
+
</pre>
+
因为我们有两个命令,一个用来更新,一个迎来取得代码。我把源代码 copy 到一个 "-build" 目录(在 cvs 和 svn 版本的包里面,我们也这样做)。
+
  
===versionpkg - a <tt>makepkg</tt> wrapper for CVS/SVN builds===
+
The correct URL can be obtained with:
这是一个很简单的脚本,它能够让你在不改动 PKGBUILD 文件里面的日期或者修正号的前提下更新你的 CVS 或者 SVN 包。
+
  $ bzr config parent_location
 
+
简单地在你的 build 目录运行这个命令,代替 <tt>makepkg</tt>。这个脚本完全免除了用 backtick 扩展来设置 PKGBUILD 中的日期或者版本标记的必要。 (This script completely removes the need for backtick execution to set the date or tag version in PKGBUILDs.)
+
 
+
使用这个脚本之前;
+
* 确保在 PKGBUILD 的前10行的位置已经声明了 pkgver, 否则这个脚本不会正常工作!
+
* 确保你的文件包含了下面的变量以及 checkout 命令:
+
* CVS
+
_cvsroot=
+
: CVS 服务器根目录(The root of the CVS server) - 即的包含一个半角冒号 (:) 在用户名后面,就像上面提到的一样。
+
  _cvsmod=
+
: 你要 check out 的 CVS 模块,如:
+
_cvsroot=":pserver:anonymous:@mplayerhq.hu:/cvsroot/ffmpeg"
+
_cvsmod="ffmpeg"
+
: 下面这个 check out 的例子用到了上面提到的变来嗯。<strong>-D</strong> 选项对于正确使用 <code>versionpkg</code> 是必须的,它和 <strong>-f</strong> 选项是很好的组合.  在不使用 <strong>-f</strong> 选项的情况下使用 <strong>-D</strong> 可能会导致错误
+
cvs -z9 -q -d $_cvsroot co -D $pkgver -f $_cvsmod
+
: -z 控制压缩级别(1低9高)
+
: -D 指定 check out 的日期,这这个脚本里面我们用 $pkgver 来在设置时间。
+
: -q 是 quiet (关闭详细信息)模式开关。
+
* SVN
+
_svntrunk=
+
: SVN trunk 地址 (译注,相当于 CVS root)
+
_svnmod=
+
: 在说一次,这个是你想要 ckeck out 的模块名,如:
+
_svntrunk=svn://svn.berlios.de/fluxbox/trunk
+
_svnmod=fluxbox
+
: 下面这个例子使用了上面的变量。<strong>-r</strong> 选项对于正确使用 <code>versionpkg</code> 是必要的(译注,这个是用来设置修改号的,显然).
+
svn co $_svntrunk --config-dir ./ -r $pkgver $_svnmod
+
: 这里的 -r 指定修改号, 我们用 $pkgver 来表示修改号。
+
 
+
====看看这个脚本!====
+
为了提高安全性, versionpkg 现在可以直接从 [community] 安装,<code>pacman -S versionpkg</code>。 我强烈建议您这样做(I strongly recommend that you use that. )下面的脚本纯粹用来解释 :)<br>
+
Changelog (修改记录):
+
* check for both CVS/SVN vars (检查 SVN 和 CVS vars)
+
* 如果失败了,就回退到上一个 pkgver ,以便允许正确的 gensync 操作(译注,我不知道 gensync, 从名字看应该是和更新有关,英文原文:If build fails revert to previous pkgver to allow correct gensync operation)
+
* 加入了有色消息(coloured messages)的支持
+
<pre>#!/bin/bash
+
 
+
# versionpkg - a makepkg wrapper for building CVS/SVN pkgs
+
# dibblethewrecker.at.jiwe.org
+
 
+
# makepkg configuration
+
[ -f /etc/makepkg.conf ] && source /etc/makepkg.conf
+
 
+
# SUBROUTINES
+
plain() {
+
if [ "$USE_COLOR" = "Y" -o "$USE_COLOR" = "y" ]; then
+
echo -e "    \033[1;1m$1\033[1;0m" >&2
+
else
+
echo "    $1" >&2
+
fi
+
}
+
msg() {
+
if [ "$USE_COLOR" = "Y" -o "$USE_COLOR" = "y" ]; then
+
echo -e "\033[1;32m==>\033[1;0m \033[1;1m$1\033[1;0m" >&2
+
else
+
echo "==> $1" >&2
+
fi
+
}
+
warning() {
+
if [ "$USE_COLOR" = "Y" -o "$USE_COLOR" = "y" ]; then
+
echo -e "\033[1;33m==> WARNING:\033[1;0m \033[1;1m$1\033[1;0m" >&2
+
else
+
echo "==> WARNING: $1" >&2
+
fi
+
}
+
error() {
+
if [ "$USE_COLOR" = "Y" -o "$USE_COLOR" = "y" ]; then
+
echo -e "\033[1;31m==> ERROR:\033[1;0m \033[1;1m$1\033[1;0m" >&2
+
else
+
echo "==> ERROR: $1" >&2
+
fi
+
return 1
+
}
+
 
+
source ./PKGBUILD
+
oldpkgver=$pkgver
+
 
+
if [ ! -z ${_cvsroot} ] && [ ! -z ${_cvsmod} ] ; then
+
cvsdate=`date +%Y%m%d`
+
sed -i "1,11 s|pkgver=$oldpkgver|pkgver=$cvsdate|" ./PKGBUILD
+
makepkg $@
+
if [ $? -gt 0 ] ; then
+
error "Reverting pkgver..."
+
sed -i "1,11 s|pkgver=$cvsdate|pkgver=$oldpkgver|" ./PKGBUILD
+
fi   
+
elif [ ! -z ${_svntrunk} ] && [ ! -z ${_svnmod} ] ; then
+
svnrevno=`svn log $_svntrunk --limit 1 | grep -m 1 -o "r.*" | cut -d \| -f 1 | sed s@r@@g`
+
msg "Current revision number is $svnrevno"
+
if [ "${1}" != "-f" ] && [ "${oldpkgver}" == "${svnrevno}" ] ; then
+
error "No new revision available.  (use -f to overwrite)"
+
exit
+
fi
+
sleep 3
+
sed -i "1,11 s|pkgver=$oldpkgver|pkgver=$svnrevno|" ./PKGBUILD
+
makepkg $@
+
if [ $? -gt 0 ] ; then
+
error "Reverting pkgver..."
+
sed -i "1,11 s|pkgver=$svnrevno|pkgver=$oldpkgver|" ./PKGBUILD
+
fi
+
else
+
error "No SVN or CVS variables found! Aborting..."
+
exit
+
fi
+
</pre>
+
 
+
== 译者声明 ==
+
译者对本文的翻译全凭理解,部分内容可能没有经过实践,有错误的话,请直接编辑本文。
+

Revision as of 12:59, 15 May 2013

Template:Package Guidelines

Tango-preferences-desktop-locale.png本页面需要更新翻译,内容可能已经与英文脱节。要贡献翻译,请访问简体中文翻译组Tango-preferences-desktop-locale.png

附注: please use the first argument of the template to provide more detailed indications.

Version control systems can be used for retrieval of source code for both usual statically versioned packages and latest (trunk) version of packages. This article covers both cases.

Prototypes

The ABS package provides prototypes for cvs, svn, git, mercurial, and darcs PKGBUILDs. When abs is installed, you can find them in /usr/share/pacman. Latest versions can be found in the prototypes directory in the ABS Git repository.

Guidelines

  • Suffix pkgname with -cvs, -svn, -hg, -darcs, -bzr, -git etc. unless the package fetches a specific release.
  • If the resulting package is different after changing the dependencies, URL, sources, etc. increasing the pkgrel is mandatory. Touching the pkgver isn't.
  • Include what the package conflicts with and provides (e.g. for fluxbox-gitAUR: conflicts=('fluxbox') and provides=('fluxbox')).
  • replaces=() generally causes unnecessary problems and should be avoided.
  • When using the cvsroot, use anonymous:@ rather than anonymous@ to avoid having to enter a blank password or anonymous:password@, if one is required.

VCS sources

Note: Pacman 4.1 supports the following VCS sources: bzr, git, hg and svn. See the fragment section of man PKGBUILD or PKGBUILD(5) for a list of supported VCS.

Starting with pacman 4.1, the VCS sources should be specified in the source=() array and will be treated like any other source. makepkg will clone/checkout/branch the repo into $SRCDEST (same as $startdir if not set in makepkg.conf(5)) and copy it to $srcdir (in a specific way to each VCS). The local repo is left untouched, thus invalidating the need for a -build directory.

The general format of a VCS source=() array is:

source=('[folder::][vcs+]url[#fragment]')
  • folder (optional) is used to change the default repo name to something more relevant (e.g. than trunk) or to preserve the previous sources
  • vcs+ is needed for URLs that do not reflect the VCS type, e.g. git+http://some_repo.
  • url is the URL to the distant or local repo
  • #fragment (optional) is needed to pull a specific branch or commit

An example Git source array:

source=('project_name::git+http://project_url#branch=project_branch')

The pkgver() function

The pkgver autobump is now achieved via a dedicated pkgver() function. This allows for better control over the pkgver, and maintainers should favor a pkgver that makes sense. Following are some examples for several VCS.

Git

With tags:

pkgver() {
  cd "$srcdir"/local_repo
  git describe --always | sed 's|-|.|g'
}

Without tags:

pkgver() {
  cd "$srcdir"/local_repo
  echo "0.$(git rev-list --count HEAD).$(git describe --always)"
}

Using the last commit date:

pkgver() {
  cd "$srcdir"/local_repo
  git log -1 --format="%cd" --date=short | sed 's|-||g'
}

Subversion

pkgver() {
  cd "$SRCDEST"/local_repo
  svnversion |tr -d [A-z]
}
Note: The copy inside $srcdir is made using svn export which does not create working copies. Any svn related command has to be used in the local repo, hence $SRCDEST.

Mercurial

pkgver() {
  cd "$srcdir"/local_repo
  hg identify -ni | awk 'BEGIN{OFS=".";} {print $2,$1}'
}

Bazaar

pkgver() {
  cd "$srcdir"/local_repo
  bzr revno
}

Fallback

The following can be used in case no satisfactory pkgver can be extracted from the repo:

pkgver() {
  date +"%Y%m%d"
}

Tips

A sample Git PKGBUILD for pacman 4.1

# Maintainer: Dave Reisner <d@falconindy.com> 
# Contributor: William Giokas (KaiSforza) <1007380@gmail.com>

pkgname=expac-git
_gitname=expac
pkgver=0.0.0
pkgrel=1
pkgdesc="Pacman database extraction utility"
arch=('i686' 'x86_64')
url="https://github.com/falconindy/expac"
license=('MIT')
depends=('pacman')
makedepends=('git' 'perl')
conflicts=('expac')
provides=('expac')
# Here is the fun bit. Makepkg knows it's a git repo because the URL starts with 'git'
# it then knows to checkout the branch 'pacman41' upon cloning, expediating versioning:
#source=('git+https://github.com/falconindy/expac.git'
source=('git://github.com/falconindy/expac.git'
        'expac_icon.png')
# Because the sources are not static, skip Git checksum:
md5sums=('SKIP'
         '020c36e38466b68cbc7b3f93e2044b49')

pkgver() {
  cd "$srcdir/$_gitname"
  git describe --always | sed 's|-|.|g'
  # To give the total count of commits and the hash of the last one
  # (useful if you're making a repository with git packages so that they can have
  # sequential version numbers, else a "pacman -Syu" may not update the package):
  #echo "0.$(git rev-list --count $branch).$(git describe --always)"
  # Using the last commit date:
  #git log -1 --format="%cd" --date=short | sed 's|-||g'
}

build() {
  cd "$srcdir/$_gitname"
  make
}

package() {
  cd "$srcdir/$_gitname"
  make PREFIX=/usr DESTDIR="$pkgdir" install
  install -Dm644 "$srcdir/expac_icon.png" "$pkgdir/usr/share/pixmaps/expac.png"
}

Removing VCS leftovers

To make sure that there are no VCS leftovers use the following at the end of the package() function (replacing .git with .svn, .hg, etc.):

find "$pkgdir" -type d -name ".git" -exec rm -r '{}' +

SVN packages that try to get their revision number

If the build system for the program you are packaging calls svnversion or svn info to determine its revision number, you can add a prepare() function similar to this one to make it work:

prepare() {
  cp -a "$SRCDEST/$_svnmod/.svn" "$srcdir/$_svnmod/"
}

Troubleshooting

Bazaar limitation

Currently, bazaar URLs only work in the form of http://bazaar.launchpad.net/, e.g.:

source=('project_name::bzr+http://bazaar.launchpad.net/~project_team/project_path')

Using any other http://, https:// or ssh:// URL (including lp:project_name) will prevent makepkg from updating the local repo.

The correct URL can be obtained with:

$ bzr config parent_location