Introduction
As a KDE packager, I usually have to write and test patches, especially build system related (Examples: Choqok, Amarok, Plasma and happy KStatusNotifierItem’d Akregator and Kaffeine, they don’t look ancient any more
). Gentoo, as a source based distro, has the ability to provide packages that clone/checkout the source from upstream’s SCM and compile it directly (called live ebuilds). For KDE, it provides live ebuilds from KDE SC master/trunk and the branch(es) (currently 4.7), plus live ebuilds for many extragear/playground and other packages (all of the above are available in the kde overlay). Also, we provide Qt live ebuilds both from master and many branches, in the qting-edge overlay. I wanted to use our Gentoo live ebuilds in order to test patches, but there were multiple problems. Emerge downloads the sources in $DISTDIR and stores them as the portage user. Plus, the git eclass was using bare repos, and it would reset the repo to master before each emerge. In order to solve those problems, I created a few scripts and wrappers, and convinced Tomas to introduce two new variables in the new git-2 eclass to fit my needs (thanks a lot bro, you owe me a beer).
Define the needs
In short, what I want is:
- download the sources somewhere in my homedir
- my everyday user to have write permissions to them
- non-bare clones
- url = anongit.kde.org AND pushUrl = git.kde.org, if possible directly on initial clone
- if possible, have a live and a regular release side by side
The last dot was solvable, but not any more. We used to provide a kdeprefix USE flag, that allowed us to do exactly this (install multiple KDE versions using different prefix (eg /usr/kde/4.7 /usr/kde/live). It had many problems though, that forced us to remove it. The problems it had were mostly in non-KDE packages, eg Sip, which also needed to be prefixed, which was too much workload. Anyway, a chroot could solve that issue.
As for the permission issue, I asked Zac if portage itself could provide something like this (using my user instead of the portage user), and he suggested that creating a git wrapper would be a clean solution.
After a while I was able to extend the above for my gentoo overlays (unofficial ebuild git repositories), since I have write access to most of the ones I use in my system.
Configuration
All the scripts mentioned can be found here. Although well tested here for the past few months, use them at your own risk. In the following examples I’m going to use the configurations for both the KDE and Gentoo git repos. Of course, you can ignore them (“Gentoo repos” blocks in the following scripts).
First, we need to set the following in /etc/make.conf:
# Needed by the Git wrapper
KDE_DEVELOPER=1 # For the KDE repos
GENTOO_DEVELOPER=1 # For the Gentoo repos
EGIT_NONBARE=1 # This one sets the git-2 eclass to clone non-bare repos
Next, we set up some git aliases in ~/.gitconfig, as suggested here:
# KDE Repos
[url "git://anongit.kde.org/"]
insteadOf = kde:
[url "git@git.kde.org:"]
pushInsteadOf = kde:
# Gentoo Repos
[url "git://git.overlays.gentoo.org/"]
insteadOf = gentoo:
[url "git@git.overlays.gentoo.org:"]
pushInsteadOf = gentoo:
And the git wrapper, which should be put in /usr/local/sbin/git:
#!/bin/bash
source /etc/make.conf
USER="tampakrap"
GROUP="tampakrap"
GIT="/usr/bin/git"
if [[ $1 == 'clone' ]]; then
# KDE Repos
if [[ $2 == "git://anongit.kde.org/"* ]] && [[ $KDE_DEVELOPER == 1 ]]; then
KDE_REPO=$(echo $2 | sed 's:git\://anongit.kde.org/::')
$GIT "$@"
chown -R $USER:$USER $DISTDIR/egit-src/$KDE_REPO
# Gentoo Repos
elif [[ $2 == "git://git.overlays.gentoo.org/"* ]] && [[ $GENTOO_DEVELOPER == 1 ]];then
GENTOO_REPO=$(echo $2 | sed 's:git\://git.overlays.gentoo.org/::')
$GIT "$@"
chown -R $USER:$GROUP $DISTDIR/egit-src/$GENTOO_REPO
else
$GIT "$@"
fi
else
if [[ ${PWD%/*} == $DISTDIR/egit-src ]] && ( grep -s -q gentoo .git/config || grep -s -q kde .git/config ); then
sudo -u $USER $GIT "$@"
else
$GIT "$@"
fi
fi
The above script consists of two parts: if the git argument is clone, it checks if the URL is a KDE or Gentoo one and chowns the repo after cloning. If it is something else (eg pull), it checks again if the URL is a KDE or Gentoo one, and uses sudo -u $USER:$GROUP to preserve the permissions of the repo. The repos are still in the $DISTDIR/egit-src dir ($DISTDIR is usually /usr/portage/distfiles, but it can be changed in /etc/make.conf), so the following script creates symlinks of those somewhere in the homedir (put it in /usr/local/bin/create_repolinks):
#!/bin/bash
# Headers
source /etc/make.conf
. /etc/init.d/functions.sh
# Variables
REPO_DIR="/home/tampakrap/Source_Code/" # Where to store the symlinks of the repos
GENTOO_REPO_DIR="${REPO_DIR}gentoo/" # Gentoo repos
KDE_REPO_DIR="${REPO_DIR}kde/" # KDE repos
OVERLAY_DIR="/var/lib/layman"
# No root
if [[ $UID == 0 ]]; then
eerror 'root is forbidden'
exit 1
fi
# Gentoo Overlays
cd $OVERLAY_DIR
for repo in `ls -d */`
do
pushd $repo > /dev/null
einfo "Checking $repo overlay"
if [[ ! -z `grep git.overlays.gentoo.org .git/config` ]]; then
sed -i -e 's:git\://git.overlays.gentoo.org/:gentoo\::' .git/config
ewarn "gentoo git url corrected for $repo overlay"
fi
[[ -L ${GENTOO_REPO_DIR}${repo%/*} ]] || (ln -s /var/lib/layman/$repo ${GENTOO_REPO_DIR} && ewarn "New symlink for $repo overlay")
popd > /dev/null
done
# KDE Repositories
cd $DISTDIR/egit-src
for repo in `ls -d */`
do
pushd $repo > /dev/null
einfo "Checking $repo repository"
if [[ ! -z `grep anongit.kde.org .git/config` ]]; then
sed -i -e 's:git\://anongit.kde.org:kde\::' .git/config
ewarn "kde git url corrected for $repo"
fi
if [[ ! -z `grep kde: .git/config` ]]; then
[[ -L ${KDE_REPO_DIR}${repo%/*} ]] || (ln -s ${DISTDIR}/egit-src/$repo ${KDE_REPO_DIR} && ewarn "New symlink for $repo")
fi
popd > /dev/null
done
Last but not least, we need the kde overlay, to get the live ebuilds:
For more information on this, take a look at the Gentoo KDE Guide
Usage
With the above configuration, we can use:
emerge -av =amarok-9999
create_repolinks
and get the amarok repository in our homedir, ready to patch it. As I said, in case we modified the code and tried to re-emerge the ebuild to get our patch in action, emerge will reset our repo to master again. Thus, we need to use the following variable:
EVCS_OFFLINE=1 emerge -av1 amarok
This will prevet the reset of the repo. In case we want to use a full live environment, we can even put that var in make.conf, but it is not recommended, better to use it in single emerge runs like the above.
That’s it. I plan to write a PyKDE UI for easy installation of the scripts, and maybe write a proper techbase article for it. Any feedback is appreciated.
