Mailinglist Archive: opensuse-buildservice (239 mails)

< Previous Next >
[opensuse-buildservice] [PATCH] Add --build-abuild-id to osc and build and add --map-repo to osc
  • From: David Greaves <david@xxxxxxxxxxxx>
  • Date: Thu, 21 May 2009 17:05:42 +0100
  • Message-id: <4A157BD6.2070700@xxxxxxxxxxxx>
When building locally in a qemu/chroot and debugging I find I want to edit the
files in the chroot from my desktop gui editor but they're all owned by 399:399.

This pair of patches allows me to set the uid:gid to match my local user and
eases this process.

usage is:
build --build-abuild-id uid:gid

or more usually:
osc build --build-abuild-id 500:500

osc also accepts (and extends the default) .oscrc settings:
build-abuild-id = 500:500

It only supports numeric ids.


The osc patch also adds --map-repo to aggregatepac which
allows repository mapping(s) to be given as SRC=TARGET[,SRC=TARGET]

eg, a real usage:
osc aggregatepac -m
MerStable_Debian_5.0=Mer0.13_Debian_5.0,MerStable_Ubuntu_9.04=Mer0.13_Ubuntu_9.04
Maemo:Mer:0.13:HW:N8x0 advanced-power Maemo:Mer:Stable:HW:N8x0

https://build.opensuse.org/package/view_file?file=_aggregate&package=advanced-power&project=Maemo%3AMer%3AStable%3AHW%3AN8x0

David


--
"Don't worry, you'll be fine; I saw it work in a cartoon once..."

diff -uNr build-2009.04.23/build build-2009.04.23lbt/build
--- build-2009.04.23/build 2009-04-22 09:15:50.000000000 +0100
+++ build-2009.04.23lbt/build 2009-05-08 20:35:51.166699320 +0100
@@ -36,6 +36,9 @@
# whether we have virtio support
kvm_virtio=

+# Default uid:gid for the build user
+ABUILD_UID=399
+ABUILD_GID=399
DO_INIT=true
DO_LINT=
DO_CHECKS=true
@@ -160,6 +163,11 @@
--debug
enable creation of a debuginfo package

+ --build-abuild-id uid:gid
+ Specify the uid and gid to use for abuild
+ This is useful if you are hacking in the buildroot.
+ This must be set to the same value if the buildroot is re-used.
+
Remember to have fun!

[*] Maximum RPM: http://www.rpm.org/max-rpm/
@@ -682,6 +690,16 @@
*-changelog)
CHANGELOG=true
;;
+ --build-abuild-id)
+ ABUILD_ID="$ARG"
+ if [[ ${BASH_VERSINFO[0]} -ge 3 && ! $ABUILD_ID =~
^[0-9]{1,5}:[0-9]{1,5}$ ]] ; then
+ echo "abuild argument must be uid:gid"
+ cleanup_and_exit
+ fi
+ ABUILD_UID=${ABUILD_ID%:*}
+ ABUILD_GID=${ABUILD_ID#*:}
+ shift
+ ;;
-*)
echo Unknown Option "$PARAM". Exit.
cleanup_and_exit 1
@@ -1170,12 +1188,12 @@

if test $BUILD_USER = abuild ; then
if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
- echo 'abuild::399:399:Autobuild:/home/abuild:/bin/bash'
$BUILD_ROOT/etc/passwd
+ echo
"abuild::${ABUILD_UID}:${ABUILD_GID}:Autobuild:/home/abuild:/bin/bash"
$BUILD_ROOT/etc/passwd
echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/shadow # This is needed
on Mandriva 2009
echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/gshadow # This is needed
on Ubuntu 8.10
- echo 'abuild::399:' >>$BUILD_ROOT/etc/group
+ echo "abuild::${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
mkdir -p $BUILD_ROOT/home/abuild
- chown 399:399 $BUILD_ROOT/home/abuild
+ chown ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT/home/abuild
fi
if test -f $BUILD_ROOT/etc/shadow ; then
sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow >
$BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
@@ -1231,7 +1249,7 @@
rm -rf $BUILD_ROOT$TOPDIR
for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS
BUILDROOT; do
mkdir -p $BUILD_ROOT$TOPDIR/$i
- test $BUILD_USER = abuild && chown 399:399 $BUILD_ROOT$TOPDIR/$i
+ test $BUILD_USER = abuild && chown ${ABUILD_UID}:${ABUILD_GID}
$BUILD_ROOT$TOPDIR/$i
done
test -e $BUILD_ROOT/exit && cleanup_and_exit

@@ -1289,7 +1307,7 @@

if test "$BUILDTYPE" = dsc ; then
rm -rf $BUILD_ROOT$TOPDIR/BUILD
- test $BUILD_USER = abuild && chown 399:399 $BUILD_ROOT$TOPDIR
+ test $BUILD_USER = abuild && chown ${ABUILD_UID}:${ABUILD_GID}
$BUILD_ROOT$TOPDIR
DEB_TRANSFORM=
DEB_SOURCEDIR=$TOPDIR/SOURCES
DEB_DSCFILE=$SPECFILE
@@ -1311,7 +1329,7 @@
fi

if test $BUILD_USER = abuild ; then
- chown -R 399:399 $BUILD_ROOT$TOPDIR/*
+ chown -R ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT$TOPDIR/*
else
chown -R root:root $BUILD_ROOT$TOPDIR/*
fi
@@ -1563,7 +1581,7 @@
echo "... checking for files with abuild user/group"
BADFILE=
while read un gn fn ; do
- if test "$un" = abuild -o "$gn" = abuild -o "$un" = 399 -o "$gn" = 399
; then
+ if test "$un" = abuild -o "$gn" = abuild -o "$un" = "$ABUILD_UID" -o
"$gn" = "$ABUILD_GID" ; then
echo " $un $gn $fn"
BADFILE=true
fi

Only in osc-0.117lbt: build-stamp
Only in osc-0.117lbt: configure-stamp
Binary files osc-0.117/osc/babysitter.pyc and osc-0.117lbt/osc/babysitter.pyc
differ
diff -ur osc-0.117/osc/build.py osc-0.117lbt/osc/build.py
--- osc-0.117/osc/build.py 2009-04-22 12:16:00.000000000 +0100
+++ osc-0.117lbt/osc/build.py 2009-05-08 21:57:40.396766503 +0100
@@ -278,6 +278,18 @@
buildargs.append('--with %s' % opts._with)
if opts.without:
buildargs.append('--without %s' % opts.without)
+ if opts.build_abuild_id or config['build-abuild-id']:
+ buildidre = re.compile('^[0-9]{1,5}:[0-9]{1,5}$')
+ if opts.build_abuild_id:
+ if not buildidre.match(opts.build_abuild_id):
+ print >>sys.stderr, 'Error: build-abuild-id arg must be 2
colon separated numerics: "uid:gid"'
+ return 1
+ buildargs.append('--build-abuild-id %s' % opts.build_abuild_id)
+ elif config['build-abuild-id']:
+ if not buildidre.match(config['build-abuild-id']):
+ print >>sys.stderr, 'Error: build-abuild-id config must be 2
colon separated numerics: "uid:gid"'
+ return 1
+ buildargs.append('--build-abuild-id %s' %
config['build-abuild-id'])
# FIXME: quoting
# if opts.define:
# buildargs.append('--define "%s"' % opts.define)
Binary files osc-0.117/osc/cmdln.pyc and osc-0.117lbt/osc/cmdln.pyc differ
diff -ur osc-0.117/osc/commandline.py osc-0.117lbt/osc/commandline.py
--- osc-0.117/osc/commandline.py 2009-04-23 10:25:38.000000000 +0100
+++ osc-0.117lbt/osc/commandline.py 2009-05-21 12:55:08.535667244 +0100
@@ -791,6 +791,8 @@

link_pac(src_project, src_package, dst_project, dst_package, rev)

+ @cmdln.option('-m', '--map-repo', metavar='SRC=TARGET[,SRC=TARGET]',
+ help='Allows repository mapping(s) to be given as
SRC=TARGET[,SRC=TARGET]')
def do_aggregatepac(self, subcmd, opts, *args):
"""${cmd_name}: "Aggregate" a package to another package

@@ -827,7 +829,15 @@
if src_project == dst_project and src_package == dst_package:
print >>sys.stderr, 'Error: source and destination are the same.'
return 1
- aggregate_pac(src_project, src_package, dst_project, dst_package)
+
+ if opts.map_repo:
+ for pair in re.split(",", opts.map_repo):
+ src_tgt = re.split("=", pair)
+ if len(src_tgt) != 2 or not src_tgt[0] or not src_tgt[1]:
+ print >>sys.stderr, 'map "%s" must be
SRC=TARGET[,SRC=TARGET]'%opts.map_repo
+ return 1
+
+ aggregate_pac(src_project, src_package, dst_project, dst_package,
opts.map_repo)


@cmdln.option('-c', '--client-side-copy', action='store_true',
@@ -1979,6 +1989,9 @@
help='Run build as root. The default is to build as '
'unprivileged user. Note that a line "# norootforbuild" '
'in the spec file will invalidate this option.')
+ @cmdln.option('--build-abuild-id', metavar='uid:gid',
+ help='specify the numeric uid:gid pair to assign to the '
+ 'unprivileged "abuild" user')
@cmdln.option('--local-package', action='store_true',
help='build a package which does not exist on the server')
@cmdln.option('--alternative-project', metavar='PROJECT',
@@ -1999,9 +2012,9 @@
of the 'osc repos' output. BUILD_DESCR is either a RPM spec file, or a
Debian dsc file.

- The command honours packagecachedir and build-root settings in .oscrc,
- if present. You may want to set su-wrapper = 'sudo' in .oscrc, and
- configure sudo with option NOPASSWD for /usr/bin/build.
+ The command honours packagecachedir, build-root and build-abuild-id
+ settings in .oscrc, if present. You may want to set su-wrapper = 'sudo'
+ in .oscrc, and configure sudo with option NOPASSWD for /usr/bin/build.

If neither --clean nor --noinit is given, build will reuse an existing
build-root again, removing unneeded packages and add missing ones. This
Binary files osc-0.117/osc/commandline.pyc and osc-0.117lbt/osc/commandline.pyc
differ
diff -ur osc-0.117/osc/conf.py osc-0.117lbt/osc/conf.py
--- osc-0.117/osc/conf.py 2009-04-22 12:16:00.000000000 +0100
+++ osc-0.117lbt/osc/conf.py 2009-05-08 20:30:51.758699798 +0100
@@ -48,6 +48,7 @@
'build-cmd': '/usr/bin/build',
'build-type' : '', # may be empty for chroot, kvm or xen
'build-root': '/var/tmp/build-root',
+ 'build-abuild-id': '399:399',
'build-device': '', # required for VM builds
'build-memory' : '',# required for VM builds
'build-swap' : '', # optional for VM builds
@@ -85,6 +86,12 @@
# /srv/oscbuild/%%(repo)s-%%(arch)s-%%(project)s-%%(package)s
#build-root = %(build-root)s

+# Numeric uid:gid to assign to the "abuild" user in the build-root
+# This is convenient when sharing the buildroot with ordinary userids
+# on the host.
+# This should not be 0
+build-abuild-id = 399:399
+
# extra packages to install when building packages locally (osc build)
# this corresponds to osc build's -x option and can be overridden with that
# -x '' can also be given on the command line to override this setting, or
Binary files osc-0.117/osc/conf.pyc and osc-0.117lbt/osc/conf.pyc differ
diff -ur osc-0.117/osc/core.py osc-0.117lbt/osc/core.py
--- osc-0.117/osc/core.py 2009-04-23 10:25:58.000000000 +0100
+++ osc-0.117lbt/osc/core.py 2009-05-21 12:45:55.675166880 +0100
@@ -2525,11 +2525,12 @@
http_PUT(u, data=link_template)
print 'Done.'

-def aggregate_pac(src_project, src_package, dst_project, dst_package):
+def aggregate_pac(src_project, src_package, dst_project, dst_package,
map_repo):
"""
aggregate package
- "src" is the original package
- "dst" is the "aggregate" package that we are creating here
+ - "map" is an array of SRC=TARGET repository mappings
"""

src_meta = show_package_meta(conf.config['apiurl'], src_project,
src_package)
@@ -2550,10 +2551,20 @@
aggregate_template = """\
<aggregatelist>
<aggregate project="%s">
+""" % (src_project)
+ if map_repo:
+ # map_repo is pre-validated; add the repo mappings
+ for pair in re.split(",", map_repo):
+ src_tgt = re.split("=", pair)
+ aggregate_template += """\
+ <repository target="%s" source="%s" />
+""" % (src_tgt[0],src_tgt[1])
+
+ aggregate_template += """\
<package>%s</package>
</aggregate>
</aggregatelist>
-""" % (src_project, src_package)
+""" % ( src_package)

u = makeurl(conf.config['apiurl'], ['source', dst_project, dst_package,
'_aggregate'])
http_PUT(u, data=aggregate_template)
Binary files osc-0.117/osc/core.pyc and osc-0.117lbt/osc/core.pyc differ
Binary files osc-0.117/osc/__init__.pyc and osc-0.117lbt/osc/__init__.pyc differ
Binary files osc-0.117/osc/OscConfigParser.pyc and
osc-0.117lbt/osc/OscConfigParser.pyc differ
Binary files osc-0.117/osc/oscerr.pyc and osc-0.117lbt/osc/oscerr.pyc differ
< Previous Next >
This Thread
  • No further messages