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

From ArchWiki
Jump to: navigation, search
 
(Packaging CVS, SVN & GIT files using makepkg)
Line 6: Line 6:
  
 
[[Category:Package Management]]
 
[[Category:Package Management]]
==Packaging CVS, SVN & GIT files using makepkg==
+
==用 makepkg CVS, SVN & GIT 文件==
  
 
This is actually very easy and doesn't require any special knowledge.  However, the more you know about cvs and svn the easier it is.  Many people introduce custom variables into the PKGBUILD that can over complicate things.  These are not ''really'' necessary but do help to clarify the syntax of the cvs/svn/git commands, which can appear quite complex.
 
This is actually very easy and doesn't require any special knowledge.  However, the more you know about cvs and svn the easier it is.  Many people introduce custom variables into the PKGBUILD that can over complicate things.  These are not ''really'' necessary but do help to clarify the syntax of the cvs/svn/git commands, which can appear quite complex.

Revision as of 07:54, 2 September 2006

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

用 makepkg CVS, SVN & GIT 文件

This is actually very easy and doesn't require any special knowledge. However, the more you know about cvs and svn the easier it is. Many people introduce custom variables into the PKGBUILD that can over complicate things. These are not really necessary but do help to clarify the syntax of the cvs/svn/git commands, which can appear quite complex.

一些小提示

  • Suffix pkgname with -cvs or -svn or -git where applicable - this prevents confusion with non-developement versions e.g. fluxbox-svn or fvwm-cvs vs fluxbox and fvwm.
  • You must also be careful about pacman conflicts. For example fluxbox-svn will conflict with fluxbox. In this case you need to use the conflicts= field
conflicts=('fluxbox')
You should also use the provides= field so that pkgs that require fluxbox to be installed recognise your fluxbox-svn pkg as fluxbox
provides=('fluxbox')
You should AVOID using replaces= it generally causes unecessary problems
  • When using/defining the cvsroot use anonymous:@ rather than anonymous@ to avoid having to press enter to give blank password OR anonymous:password@ - 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.
source=()
md5sums=()
  • 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)
  • don't forget to include cvs or svn in makedepends= as necessary
  • to preserve the integrity of the checked out code it is usually possible to build in a separate build dir e.g. having checked out source code to src/$_cvsmod from $startdir you can use:
  mkdir src/$_cvsmod-build

  cd src/$_cvsmod-build
  ../$_cvsmod/configure

OR if that fails you can try:

  cp -r src/$_cvsmod src/$_cvsmod-build
  cd src/$_cvsmod-build
  • With the introduction of the AUR it is most important to avoid using backtick execution to create pkg variables
    • For cvs pkgs you should avoid pkgver=`date +%y%m%d` - this also inteferes with the functionality of the AUR. Instead it is still possible to use a date format for the $pkgver variable and to use the cvs -D option to check out code from that date (see below)
    • For svn you can use the revision number. An easy way to find the revision number is to use the following command:
svn log $_svntrunk --limit 1 | grep -m 1 -o "r.*" | cut -d \| -f 1 | sed s@r@@g

That command grabs the most recent log entry from the svn repo and finds the revision number, which is prefixed with an r. This is from the fluxbox svn log, the revision number is in the top left, r4084

------------------------------------------------------------------------
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.
the "Sloppy" was always a bit .. unprecise.

Example CVS PKGBUILD

Here is a PKGBUILD for bmp-cvs that utilizes some of the tips above

# Contributor:  Lukas Sabota <punkrockguy318@comcast.net>
# 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"
_cvsmod="bmp"

build() {
  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"
  msg "Starting make..."

  cp -r ../$_cvsmod ../$_cvsmod-build
  cd ../$_cvsmod-build

  ./configure --prefix=/usr
  make || return 1
  make DESTDIR=$startdir/pkg install || return 1

  mkdir -p $startdir/pkg/usr/share/xmms/Skins
  mv $startdir/pkg/usr/share/bmp/Skins/* $startdir/pkg/usr/share/xmms/Skins
  rmdir $startdir/pkg/usr/share/bmp/Skins

  rm -r $startdir/src/$_cvsmod-build
}
# vim:syntax=sh

Example SVN PKGBUILD

If you use the source command on the PKGBUILD first it will store the _svntrunk and _svnmod variables. So if you run :

source PKGBUILD
svn log $_svntrunk --limit 1 | grep -m 1 -o "r.*" | cut -d \| -f 1 | sed s@r@@g

you can get the revision number which can be used in pkgver

# Contributor:  Lukas Sabota <punkrockguy318@comcast.net>
# Contributor: dibblethewrecker dibblethewrecker.at.jiwe.dot.org
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
_svnmod=fluxbox

build() {
  cd $startdir/src

  svn co $_svntrunk --config-dir ./ -r $pkgver $_svnmod
  cd $_svnmod
  ./autogen.sh

  msg "SVN checkout done or server timeout"
  msg "Starting make..."

  mkdir ../$_svnmod-build
  cd ../$_svnmod-build

  # fix for crap fb issue
  mkdir data
  cp ../$_svnmod/data/keys data/

  ../$_svnmod/configure --prefix=/usr --enable-xinerama --enable-imlib2 --enable-debug
  #./configure --prefix=/usr --enable-xinerama --enable-imlib2 --enable-debug
  make || return 1
  make DESTDIR=$startdir/pkg/ install

  rm -r $startdir/src/$_svnmod-build
}
# vim:syntax=sh

Example GIT PKGBUILD

pkgname=compiz-git
pkgver=20060707
pkgrel=1
pkgdesc="Composite and window manager for Xgl"
url="http://en.opensuse.org/Compiz"
license=""
depends=('xgl-cvs' 'mesa-xgl-cvs' 'cairo-devel' 'libxevie' \
         'startup-notification' 'libpng'  'libxdamage' \
         'libxrandr' 'libwnck-compiz' 'gnome-desktop' 'control-center' \
         'libsvg-cairo' 'libxcomposite')
makedepends=('git')
conflicts=()
replaces=()
backup=()
install=compiz.install
source=(compiz-intel-copy-pixel-issue-workaround-1.diff)
md5sums=('10a157b86d528bca2be6731c5eaff7b3')

_gitroot="git://anongit.freedesktop.org/git/xorg/app/compiz"
_gitname="compiz"
build() {
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
  cd $_gitname && git-pull origin
  msg "The local files are updated."
  else
  git clone $_gitroot
  fi

  msg "GIT checkout done or server timeout"
  msg "Starting make..."

  cp -r $startdir/src/$_gitname $startdir/src/$_gitname-build
  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} \
    --prefix=/usr \
    --infodir=/usr/share/info \
    --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 {} \;
} 

As you see, I use "-git" suffix in the pkgname, and two variables, _gitroot and _gitname for identify the repositories and the name of the package. I need to introduce an if condition:

if [ -d $startdir/src/$_gitname ] ; then
cd $_gitname && git-pull origin
msg "The local files are updated."
else
git clone $_gitroot
fi

because we have two commands, one for updating source and one for getting it. I copy the source code in a "-build" directory ( the same thing that we do with -cvs and -svn program ).

versionpkg - a makepkg wrapper for CVS/SVN builds

This is a very simple script that allows you to easily update your CVS and SVN packages without having to edit the PKGBUILDs manually to enter the date or revision number.

Simply run this script rather than makepkg in the build dir. This script completely removes the need for backtick execution to set the date or tag version in PKGBUILDs.

To use the script;

  • Ensure that pkgver is declared within the first ten lines of the PKGBUILD or it won't work!
  • Ensure you have include the following custom variables and checkout command:
  • CVS
_cvsroot=
The root of the CVS server - remember to include a colon (:) after the username as outlined above
_cvsmod=
Simply the CVS module name you wish to check out e.g.
_cvsroot=":pserver:anonymous:@mplayerhq.hu:/cvsroot/ffmpeg"
_cvsmod="ffmpeg"
Here is the checkout command for CVS that uses the above variables. The -D option is essential for proper use of versionpkg and is best used in combination with the -f option. Use of -D without -f may result in errors
cvs -z9 -q -d $_cvsroot co -D $pkgver -f $_cvsmod
-z controls the level of compression (1 is low 9 is high)
-D specifies the date to check out, we use $pkgver as that is set to the current date by the script.
-q is a quiet switch
  • SVN
_svntrunk=
The address of the SVN trunk
_svnmod=
Again the module you wish to check out from trun e.g.
_svntrunk=svn://svn.berlios.de/fluxbox/trunk
_svnmod=fluxbox
Here is the checkout command for SVN that uses the above variables. The -r option is essential for proper use of versionpkg.
svn co $_svntrunk --config-dir ./ -r $pkgver $_svnmod
Here -r specifies the revision number, we use $pkgver as that is set to the latest revision number by the script.

The script!

To improve security versionpkg can now be installed directly from [community] pacman -S versionpkg. I strongly recommend that you use that. The script below is purely for illustrative purposes :)
Changelog:

  • check for both CVS/SVN vars
  • If build fails revert to previous pkgver to allow correct gensync operation
  • Added support for coloured messages
#!/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