From 9b0a3e84f6d5d558d45250dd48748b27af4fecef Mon Sep 17 00:00:00 2001 From: Zhang Qiang Date: Wed, 22 Feb 2012 15:21:54 +0800 Subject: [PATCH] gbs local build support First version of localbuild support. Design: As the quick start and first version, gbs-localbuild call build scripts directly, in other words, it's a wrapper of build scripts, Here's the basic work follow of gbs local build: 1) Check options and generate command options transfer to 'build' i) arch: build target arch ii) repository: Specify package repositories to create build env iii) dist conf file: this can be specified from gbs.conf or command line iiii)buildroot: Specify build rootdir to setup chroot environment 2) call linux32 to build 32bit packages if necessary 3) change to root user to run rpmbuild 4) call build scripts to all the build stuff. --- data/tizen-1.0.conf | 446 ++++++++++++++++++++++++++++++++++++++++++ distfiles/debian/control | 1 + distfiles/gbs.spec | 1 + gitbuildsys/buildservice.py | 27 +++ gitbuildsys/cmd_build.py | 22 +-- gitbuildsys/cmd_localbuild.py | 218 +++++++++++++++++++++ gitbuildsys/conf.py | 23 ++- gitbuildsys/git.py | 12 +- gitbuildsys/utils.py | 16 ++ tools/gbs | 65 ++++++ 10 files changed, 811 insertions(+), 20 deletions(-) create mode 100644 data/tizen-1.0.conf create mode 100644 gitbuildsys/cmd_localbuild.py diff --git a/data/tizen-1.0.conf b/data/tizen-1.0.conf new file mode 100644 index 0000000..51238db --- /dev/null +++ b/data/tizen-1.0.conf @@ -0,0 +1,446 @@ +%define _project Tizen:Main + +### from Tizen:Base +%define _repository standard +Patterntype: rpm-md comps +Release: . +Support: build build-compare build-mkbaselibs + +%if "%_repository" == "cov" +Support: coverity-build +%endif + +VMinstall: util-linux-ng libblkid libuuid + +ExportFilter: \.armv7hl\.rpm$ armv8el +ExportFilter: \.armv7thl*\.rpm$ armv8el +ExportFilter: \.armv7tnh*\.rpm$ armv8el +ExportFilter: \.armv7h*\.rpm$ armv8el +ExportFilter: \.armv7nh*\.rpm$ armv8el +ExportFilter: \.x86_64\.rpm$ x86_64 +ExportFilter: \.i586\.rpm$ i586 +ExportFilter: \.armv5el\.rpm$ armv5el +ExportFilter: \.armv5tel\.rpm$ armv5el +ExportFilter: \.armv6el\.rpm$ armv6el +ExportFilter: \.armv6l\.rpm$ armv6el +ExportFilter: \.armv6vl\.rpm$ armv6el +ExportFilter: \.armv7el\.rpm$ armv7el +ExportFilter: \.armv7l\.rpm$ armv7el +ExportFilter: \.armv7vl\.rpm$ armv7el +# filter out packages of cross setup on ia32 +ExportFilter: .*vanish\.rpm +PublishFilter: .*vanish\.rpm +ExportFilter: .*dontuse\.rpm +PublishFilter: .*dontuse\.rpm + + +# +# ARM Start +# +%ifarch %arm +# arm land +%define cross_5 1 +%define cross_7 1 +%define native 1 + +%define cross_7h 1 + +%ifarch armv8el +Changetarget: armv7hl-meego-linux +%define _gnu gnueabi +%if %{cross_7h} +Prefer: cross-armv7hl-binutils-accel-armv7hl +Prefer: cross-armv7hl-gcc-accel-armv7hl +%define speedcommon 1 +%define speedbash 1 +%define speedbinutils 1 +%define speedgcc 1 +%define native 0 +%define speedtools 1 +#Support: cross-armv7tnhl-platformfile +%endif +%endif +%ifarch armv7hl +Changetarget: armv7hl-meego-linux +%define _gnu gnueabi +%if %{cross_7h} +Prefer: cross-armv7hl-binutils-accel-armv7hl +Prefer: cross-armv7hl-gcc-accel-armv7hl +%define speedcommon 1 +%define speedbash 1 +%define speedbinutils 1 +%define speedgcc 1 +%define native 0 +%define speedtools 1 +#Support: cross-armv7tnhl-platformfile +%endif +%endif + + + +######################## +# preselect rpm targets +# more ifs for _repository possible as needed +######################### +%ifarch armv5el +Changetarget: armv5tel-meego-linux +%define _gnu gnueabi +%if %{cross_5} +%define speedcommon 1 +%define speedbash 1 +%define speedbinutils 1 +%define speedgcc 1 +%define native 0 +%endif +%endif + +%ifarch armv6el +Changetarget: armv6l-meego-linux +%define _gnu gnueabi +%endif + + + +%ifarch armv7el +Changetarget: armv7l-meego-linux +%define _gnu gnueabi +%if %{cross_7} +Support: cross-armv7l-platformfile +Prefer: cross-armv7l-binutils-accel-armv7l +Prefer: cross-armv7l-gcc-accel-armv7l +%define speedcommon 1 +%define speedbash 1 +%define speedbinutils 1 +%define speedgcc 1 +%define native 0 +%define speedtools 1 +%endif + +%endif + +%if %speedtools +Support: patch-x86-arm findutils-x86-arm gawk-x86-arm fdupes-x86-arm +Preinstall: libfile-x86-arm +Preinstall: rpm-libs-x86-arm +Preinstall: bzip2-libs-x86-arm +Preinstall: elfutils-libelf-x86-arm +Preinstall: bzip2-x86-arm +Preinstall: nss-softokn-freebl-x86-arm +Preinstall: nss-x86-arm +Preinstall: nspr-x86-arm +Preinstall: tar-x86-arm +Preinstall: libgcc-x86-arm +Preinstall: libacl-x86-arm +Preinstall: libattr-x86-arm +Preinstall: coreutils-x86-arm +Preinstall: libcap-x86-arm +Preinstall: liblua-x86-arm +Preinstall: popt-x86-arm +Preinstall: sed-x86-arm +Preinstall: xz-libs-x86-arm +Preinstall: zlib-x86-arm +Preinstall: file +Preinstall: diffutils-x86-arm +Preinstall: file-x86-arm +Preinstall: sqlite-x86-arm +Required: nss-softokn-freebl-x86-arm +Required: nss-x86-arm +Requires: nspr-x86-arm +Required: libfile-x86-arm +Required: bzip2-libs-x86-arm +Required: elfutils-x86-arm +Required: elfutils-libs-x86-arm +Required: elfutils-libelf-x86-arm +Required: diffutils-x86-arm +Required: gzip-x86-arm +Required: libgcc-x86-arm +Required: libacl-x86-arm +Required: libattr-x86-arm +Required: coreutils-x86-arm +Required: libcap-x86-arm +Required: liblua-x86-arm +Required: popt-x86-arm +Required: xz-libs-x86-arm +Required: zlib-x86-arm +Required: file +Required: file-x86-arm +Required: sqlite-x86-arm +Required: rpm-libs-x86-arm +Required: rpm-x86-arm +Required: rpm-build-x86-arm +Runscripts: sed-x86-arm +Runscripts: nss-x86-arm +Runscripts: tar-x86-arm +Runscripts: bzip2-x86-arm +Runscripts: coreutils-x86-arm +Runscripts: diffutils-x86-arm + +Preinstall: rpm-x86-arm +Runscripts: rpm-x86-arm +Runscripts: file-x86-arm + +Support: !rpmlint-mini +Support: !rpmlint-mini-x86-arm +Prefer: python-libs +%endif + + +%if %speedcommon +# cross-compilation/speedup +Preinstall: aaa-meego-accelerator eglibc-x86-arm +Runscripts: aaa-meego-accelerator +Required: aaa-meego-accelerator +%endif + +%if %speedbash +# bash +Preinstall: bash-x86-arm libncurses-x86-arm +Runscripts: bash-x86-arm +%endif + +%if %speedbinutils +Required: cross-arm-binutils-accel +%endif + +%if %speedgcc +Required: cross-arm-gcc-accel +%endif + +Preinstall: rpm +Preinstall: rpm-libs +Required: rpm +Prefer: rpm-libs +Prefer: rpm + +# now i586 land +%else +Ignore: libncurses-x86 +Preinstall: rpm rpm-libs +Required: rpm +%endif + +# +# ARM End +# + +Preinstall: bash bzip2 coreutils liblua +Preinstall: filesystem eglibc eglibc-common libacl libattr +Preinstall: libgcc libcap +Preinstall: popt readline zlib sqlite +Preinstall: elfutils-libelf bzip2-libs libstdc++ setup libfile +Preinstall: xz-libs +Preinstall: libncurses +Preinstall: nss nspr +Preinstall: nss-softokn-freebl + +Runscripts: setup +VMinstall: perl libblkid e2fsprogs-libs libuuid perl-libs grep libpcre +Required: binutils gcc eglibc rpm-build libtool + +Support: libncurses +Support: util-linux-ng +Support: cpio gcc-c++ perl-libs perl net-tools findutils +Support: file findutils zlib bzip2 +Support: gzip +Support: make patch sed gawk tar grep coreutils pkgconfig +Support: m4 libfile tzdata tizen-release +Support: kernel-headers eglibc-headers +Support: xz-lzma-compat + +Keep: binutils cpp file findutils gawk gcc gcc-c++ +Keep: gdbm gzip libada libunwind eglibc-devel libpcre xz-lzma-compat +Keep: make gmp libcap groff cpio +Keep: patch rpm-build nss nspr elfutils python grep libgcc gcc-c++ +Keep: kernel-headers eglibc-headers perl-libs +Keep: pkgconfig glib2 +Keep: xz-lzma-compat +Keep: mpc mpfr tar sed +Keep: cloog cloog-ppl ppl +Keep: nss-softokn-freebl + + + +# SLP +Ignore: intltool:perl-libwww-perl +# Build dependency cycle +Ignore: filesystem:setup +Ignore: rpm-build:xz +Ignore: udev:udev-rules +Ignore: xdg-utils:libcontentaction +Ignore: cups:xinetd +Ignore: cups:xinitd +Ignore: alsa-lib:alsa-plugins-pulseaudio +Ignore: nautilus:gvfs +Ignore: polkit:ConsoleKit +Ignore: iso-codes:xml-common +Ignore: libzypp:gnupg +Ignore: gvfs:gnome-disk-utility +Ignore: firstboot:system-config-date +Ignore: SDL:mkinitrd +Ignore: SDL:kernel,kernel-netbook +Ignore: pulseaudio:kernel +Ignore: libzypp:expect +Ignore: pulseaudio:rtkit +Ignore: rpm:libcap +Ignore: rpm-libs:libcap +Ignore: fuse-sshfs:fastinit +Ignore: dhcp:fastinit + +Ignore: libgnomeprint22:fastinit +Ignore: gvfs:fastinit +Ignore: gnome-desktop:gnome-user-docs +Ignore: gnome-settings-daemon:gnome-control-center +Ignore: avahi:fastinit +Ignore: fastinit:udev +Ignore: udev:fastinit +Ignore: PackageKit:udev +Ignore: cvs:vim-minimal +Ignore: bluez:fastinit +Ignore: aspell:aspell-en +Ignore: fuse:kernel +Ignore: fuse:fastinit +Ignore: fastinit:module-init-tools +Ignore: hwdata:module-init-tools +Ignore: gzip:less +Ignore: xmlto:text-www-browser +Ignore: docbook-utils:text-www-browser +Ignore: gtk2:hicolor-icon-theme +Ignore: docbook-dtds:openjade +Ignore: xmlto:passivetex +Ignore: GConf-dbus:openldap +Ignore: perl:rsyslog,tcsh,logrotate +Ignore: rpm:curl,crontabs,logrotate +Ignore: texinfo-tex:tetex +Ignore: xorg-x11-server:hal-info +Ignore: gcc:libgomp +Ignore: autoconf:imake +Ignore: ConsoleKit:dbus,dbus-devel +Ignore: fastinit:kernel,udev,ethtool,mingetty +Ignore: tetex:tetex-fonts,desktop-file-utils +Ignore: pam:glib2 + +Ignore: gettext-devel:libgcj,libstdc++-devel +Ignore: pam-modules:resmgr +Ignore: bind-utils:bind-libs +Ignore: alsa:dialog,pciutils +Ignore: portmap:syslogd +Ignore: fontconfig:freetype2 +Ignore: fontconfig-devel:freetype2-devel +Ignore: xorg-x11-libs:freetype2 +Ignore: xorg-x11:x11-tools,resmgr,xkeyboard-config,xorg-x11-Mesa,libusb,freetype2,libjpeg,libpng +Ignore: arts:alsa,audiofile,resmgr,libogg,libvorbis +Ignore: libxml2-devel:readline-devel +Ignore: gnome-vfs2:gnome-mime-data,desktop-file-utils,cdparanoia,dbus-1,dbus-1-glib,krb5,hal,libsmbclient,fam,file_alteration +Ignore: libgda:file_alteration +Ignore: gnutls:lzo,libopencdk +Ignore: libgnomecanvas-devel:glib-devel +Ignore: libgnomeui:gnome-icon-theme,shared-mime-info +Ignore: gnome-pilot:gnome-panel +Ignore: postfix:pcre +Ignore: docbook_4:iso_ent,sgml-skel,xmlcharent +Ignore: docbook-xsl-stylesheets:xmlcharent +Ignore: tetex:xorg-x11-libs,expat,fontconfig,freetype2,libjpeg,libpng,ghostscript-x11,xaw3d,gd,dialog,ed +Ignore: mailx:smtp_daemon +Ignore: cron:smtp_daemon + + + + +### from Tizen:Main +%define _repository standard +Ignore: telephony-server:libslp-telplugin +Macros: +%vendor obs://10.0.17.10/Tizen:Main +%_project Tizen:Main + +### from Tizen:Base +%_repository standard +%moblin_version 2 +%meego_version 1.2 +%meego 1.2 +%opensuse_bs 1 +%vendor meego +%_vendor meego +%_default_patch_fuzz 2 + + + +# python main version +%py_ver %(echo `python -c "import sys; print sys.version[:3]"`) + +# directories +%py_prefix %(echo `python -c "import sys; print sys.prefix"`) +%py_libdir %{py_prefix}/lib/python%{py_ver} +%py_incdir /usr/include/python%{py_ver} +%py_sitedir %{py_libdir}/site-packages +%py_dyndir %{py_libdir}/lib-dynload + +# pure python modules compilation +%py_comp python -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])" +%py_ocomp python -O -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])" + +%ext_info .gz +%ext_man .gz + +%info_add(:-:) test -x /sbin/install-info -a -f %{?2}%{?!2:%{_infodir}}/%{1}%ext_info && /sbin/install-info --info-dir=%{?2}%{?!2:%{_infodir}} %{?2}%{?!2:%{_infodir}}/%{1}%ext_info \ +%{nil} + +%info_del(:-:) test -x /sbin/install-info -a ! -f %{?2}%{?!2:%{_infodir}}/%{1}%ext_info && /sbin/install-info --quiet --delete --info-dir=%{?2}%{?!2:%{_infodir}} %{?2}%{?!2:%{_infodir}}/%{1}%ext_info \ +%{nil} + +%lang_package \ +%package locale \ +Summary: Translations and Locale for package %{name}\ +Group: Translations\ +AutoReqProv: 0\ +%description locale\ +This package provides translations for package %{name}.\ +%files locale -f %{name}.lang\ +%defattr(-,root,root,-)\ +%{nil} + + +%docs_package \ +%package docs \ +Summary: Documentation for package %{name}\ +Group: Documentation\ +AutoReqProv: 0\ +%description docs\ +This package provides documentation for package %{name}.\ +%files docs -f documentation.list\ +%defattr(-,root,root,-)\ +%{nil} + +%devel_package \ +%package devel \ +Summary: Development files for package %{name}\ +Group: Development\ +%description devel\ +This package provides header files and other developer releated files for package %{name}.\ +%files devel \ +%{_includedir}/*\ +%{_libdir}/pkgconfig/*.pc\ +%{_libdir}/*.so\ +%{nil} + + +%_smp_mflags -j4 + + +%remove_docs \ + rm -rf %{?buildroot:%{buildroot}}%{_infodir} \ + rm -rf %{?buildroot:%{buildroot}}%{_defaultdocdir} \ + rm -rf %{?buildroot:%{buildroot}}%{_datadir}/doc/%{name} \ + rm -rf %{?buildroot:%{buildroot}}%{_datadir}/gtk-doc \ + rm -rf %{?buildroot:%{buildroot}}%{_datadir}/man \ + find %{?buildroot:%{buildroot}} -regex ".*/man/man./.*\.[0-9]" | xargs rm -f -- \ + find %{?buildroot:%{buildroot}} -regex ".*/man/../man./.*\.[0-9]" | xargs rm -f -- \ + find %{?buildroot:%{buildroot}} -regex ".*/man/man./.*\.[0-9]pm" | xargs rm -f -- + + + +%define __global_cflags -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security +Optflags: armv7l %{__global_cflags} -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=vfpv3 -mfloat-abi=softfp -D__SOFTFP__ + +%distribution Tizen:Main +%_project Tizen:Main diff --git a/distfiles/debian/control b/distfiles/debian/control index e6880cc..fc37e32 100644 --- a/distfiles/debian/control +++ b/distfiles/debian/control @@ -11,6 +11,7 @@ Architecture: all Depends: ${misc:Depends}, ${python:Depends}, git-core, osc (>= 0.131), + build (>= 2011.10.10), rpm Description: The command line tools for Tizen package developers The command line tools for Tizen package developers will diff --git a/distfiles/gbs.spec b/distfiles/gbs.spec index 7d532b0..dd35c1d 100644 --- a/distfiles/gbs.spec +++ b/distfiles/gbs.spec @@ -11,6 +11,7 @@ Source0: %{name}-%{version}.tar.gz Requires: python >= 2.5 Requires: git-core Requires: osc >= 0.131 +Requires: build >= 2011.10.10 %if 0%{?fedora_version} Requires: rpm-build %else diff --git a/gitbuildsys/buildservice.py b/gitbuildsys/buildservice.py index e3919ae..6ec5fd6 100644 --- a/gitbuildsys/buildservice.py +++ b/gitbuildsys/buildservice.py @@ -1164,3 +1164,30 @@ class BuildService(object): force=True) return (targetprj, targetpkg) + + def get_buildconfig(self, prj, repository): + return core.get_buildconfig(self.apiurl, prj, repository) + + def get_repos(self, prj): + repos = [] + for repo in core.get_repos_of_project(self.apiurl, prj): + repos.append(repo) + return repos + + def get_ArchitectureList(self, prj, target): + """ + return the list of Archictecture of the target of the projectObsName for a OBS server. + """ + url = core.makeurl(self.apiurl,['build', prj, target]) + f = core.http_GET(url) + if f == None: + return None + + aElement = ElementTree.fromstring(''.join(f.readlines())) + result = [] + for directory in aElement: + for entry in directory.getiterator(): + result.append(entry.get("name")) + + return result + diff --git a/gitbuildsys/cmd_build.py b/gitbuildsys/cmd_build.py index 3b0bf7c..4c0c936 100644 --- a/gitbuildsys/cmd_build.py +++ b/gitbuildsys/cmd_build.py @@ -51,12 +51,11 @@ TMPDIR = configmgr.get('tmpdir') def do(opts, args): - if not os.path.isdir('.git'): - msger.error('You must run this command under a git tree') - - mygit = git.Git('.') - if mygit.get_branches()[0] != 'master': - msger.error('You must run this command under the master branch') + workdir = os.getcwd() + if len(args) > 1: + msger.error('only one work directory can be specified in args.') + if len(args) == 1: + workdir = args[0] tmpdir = '%s/%s' % (TMPDIR, USER) if not os.path.exists(tmpdir): @@ -76,7 +75,7 @@ def do(opts, args): f.close() # TODO: check ./packaging dir at first - specs = glob.glob('./packaging/*.spec') + specs = glob.glob('%s/packaging/*.spec' % workdir) if not specs: msger.error('no spec file found under /packaging sub-directory') @@ -109,15 +108,16 @@ def do(opts, args): msger.info('checking out %s/%s to %s ...' % (target_prj, name, tmpdir)) localpkg = obspkg.ObsPackage(tmpdir, target_prj, name, APISERVER, oscrcpath) - workdir = localpkg.get_workdir() + oscworkdir = localpkg.get_workdir() localpkg.remove_all() - tarball = '%s/%s-%s-tizen.tar.bz2' % (workdir, name, version) + tarball = '%s/%s-%s-tizen.tar.bz2' % (oscworkdir, name, version) msger.info('archive git tree to tarball: %s' % os.path.basename(tarball)) + mygit = git.Git(workdir) mygit.archive("%s-%s/" % (name, version), tarball) - for f in glob.glob('packaging/*'): - shutil.copy(f, workdir) + for f in glob.glob('%s/packaging/*' % workdir): + shutil.copy(f, oscworkdir) localpkg.update_local() diff --git a/gitbuildsys/cmd_localbuild.py b/gitbuildsys/cmd_localbuild.py new file mode 100644 index 0000000..62c9270 --- /dev/null +++ b/gitbuildsys/cmd_localbuild.py @@ -0,0 +1,218 @@ +#!/usr/bin/python -tt +# vim: ai ts=4 sts=4 et sw=4 +# +# Copyright (c) 2012 Intel, Inc. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation; version 2 of the License +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., 59 +# Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +"""Implementation of subcmd: localbuild +""" + +import os +import sys +import time +import tempfile +import glob +import shutil +import subprocess + +import msger +import runner +import utils +from conf import configmgr +import git +import buildservice + +change_personality = { + 'i686': 'linux32', + 'i586': 'linux32', + 'i386': 'linux32', + 'ppc': 'powerpc32', + 's390': 's390', + 'sparc': 'linux32', + 'sparcv8': 'linux32', + } + +obsarchmap = { + 'i686': 'i586', + 'i586': 'i586', + } + +buildarchmap = { + 'i686': 'i686', + 'i586': 'i686', + 'i386': 'i686', + } + +OSCRC_TEMPLATE = """[general] +apiurl = %(apiurl)s +plaintext_passwd=0 +use_keyring=0 +http_debug = %(http_debug)s +debug = %(debug)s +gnome_keyring=0 +[%(apiurl)s] +user=%(user)s +passx=%(passwdx)s +""" + +APISERVER = configmgr.get('build_server', 'build') +USER = configmgr.get('user', 'build') +PASSWDX = configmgr.get('passwdx', 'build') +TMPDIR = configmgr.get('tmpdir') + +def do(opts, args): + + workdir = os.getcwd() + if len(args) > 1: + msger.error('only one work directory can be specified in args.') + if len(args) == 1: + workdir = args[0] + + + hostarch = utils.get_hostarch() + buildarch = hostarch + if opts.arch: + if opts.arch in buildarchmap: + buildarch = buildarchmap[opts.arch] + else: + buildarch = opts.arch + + specs = glob.glob('%s/packaging/*.spec' % workdir) + if not specs: + msger.error('no spec file found under /packaging sub-directory') + + specfile = specs[0] #TODO: + if len(specs) > 1: + msger.warning('multiple specfiles found.') + + name = utils.parse_spec(specfile, 'name') + version = utils.parse_spec(specfile, 'version') + if not name or not version: + msger.error('can\'t get correct name or version from spec file.') + + tarball = 'packaging/%s-%s-tizen.tar.bz2' % (name, version) + msger.info('generate tar ball: %s' % tarball) + mygit = git.Git(workdir) + mygit.archive("%s-%s/" % (name, version), tarball) + + tmpdir = '%s/%s' % (TMPDIR, USER) + if not os.path.exists(tmpdir): + os.makedirs(tmpdir) + + oscrc = OSCRC_TEMPLATE % { + "http_debug": 1 if msger.get_loglevel() == 'debug' else 0, + "debug": 1 if msger.get_loglevel() == 'verbose' else 0, + "apiurl": APISERVER, + "user": USER, + "passwdx": PASSWDX, + } + (fd, oscrcpath) = tempfile.mkstemp(dir=tmpdir,prefix='.oscrc') + os.close(fd) + f = file(oscrcpath, 'w+') + f.write(oscrc) + f.close() + + distconf = configmgr.get('distconf', 'localbuild') + if opts.dist: + distconf = opts.dist + + # get dist build config info from OBS prject. + bc_filename = None + if distconf is None: + msger.error('no dist config specified, see: gbs localbuild -h.') + """ + msger.info('get build config file from OBS server') + bc_filename = '%s/%s.conf' % (tmpdir, name) + bs = buildservice.BuildService(apiurl=APISERVER, oscrc=oscrcpath) + prj = 'Trunk' + arch = None + for repo in bs.get_repos(prj): + archs = bs.get_ArchitectureList(prj, repo.name) + if buildarch in obsarchmap and obsarchmap[buildarch] in archs: + arch = obsarchmap[buildarch] + break + for a in archs: + if msger.ask('Get build conf from %s/%s, OK? '\ + % (repo.name, a)): + arch = a + if arch is None: + msger.error('target arch is not correct, please check.') + + bc = bs.get_buildconfig('Trunk', arch) + bc_file = open(bc_filename, 'w') + bc_file.write(bc) + bc_file.flush() + bc_file.close() + distconf = bc_filename + """ + + need_root = True # TODO: kvm don't need root. + + build_cmd = configmgr.get('build_cmd', 'localbuild') + build_root = configmgr.get('build_root', 'localbuild') + if opts.buildroot: + build_root = opts.buildroot + cmd = [ build_cmd, + '--root='+build_root, + '--dist='+distconf, + '--arch='+buildarch ] + build_jobs = utils.get_processors() + if build_jobs > 1: + cmd += ['--jobs=%s' % build_jobs] + if opts.clean: + cmd += ['--clean'] + if opts.debuginfo: + cmd += ['--debug'] + + if opts.repositories: + for repo in opts.repositories: + cmd += ['--repository='+repo] + else: + msger.error('No package repository specified.') + + if opts.noinit: + cmd += ['--noinit'] + cmd += [specfile] + + if need_root: + sucmd = configmgr.get('su-wrapper', 'localbuild').split() + if sucmd[0] == 'su': + if sucmd[-1] == '-c': + sucmd.pop() + cmd = sucmd + ['-s', cmd[0], 'root', '--' ] + cmd[1:] + else: + cmd = sucmd + cmd + + if hostarch != buildarch and buildarch in change_personality: + cmd = [ change_personality[buildarch] ] + cmd; + + msger.info(' '.join(cmd)) + + # runner.show() can't support interactive mode, so use subprocess insterad. + try: + rc = subprocess.call(cmd) + if rc: + print 'The buildroot was:', build_root + except KeyboardInterrupt, i: + print "keyboard interrupt, killing build ..." + subprocess.call(cmd + ["--kill"]) + raise i + + os.unlink("%s/%s" % (workdir, tarball)) + os.unlink(oscrcpath) + if bc_filename: + os.unlink(bc_filename) + + msger.info('Done') diff --git a/gitbuildsys/conf.py b/gitbuildsys/conf.py index a901f7d..3f09ec5 100644 --- a/gitbuildsys/conf.py +++ b/gitbuildsys/conf.py @@ -220,9 +220,15 @@ class ConfigMgr(object): }, 'build': { 'build_server': 'https://build.tizen.org', - 'user': 'my_user_id', - 'passwd': '', - 'passwdx': '', + 'user': 'my_user_id', + 'passwd': '', + 'passwdx': '', + }, + 'localbuild': { + 'build_cmd': '/usr/bin/build', + 'build_root': '/var/tmp/build-root-gbs', + 'su-wrapper': 'su -c', + 'distconf': None, }, } @@ -235,6 +241,11 @@ tmpdir = $general__tmpdir build_server = $build__build_server user = $build__user passwdx = $build__passwdx +[localbuild] +build_cmd = /usr/bin/build +build_root= /var/tmp/build-root-gbs +su-wrapper= su -c +distconf= /usr/share/gbs/tizen-1.0.conf """ # make the manager class as singleton @@ -351,6 +362,12 @@ passwdx = $build__passwdx else: raise errors.ConfigError('no opt: %s in section %s' \ % (opt, section)) + def check_opt(self, opt, section='general'): + if section in self.DEFAULTS and \ + opt in self.DEFAULTS[section]: + return True + else: + return False def get(self, opt, section='general'): if opt == 'passwd': diff --git a/gitbuildsys/git.py b/gitbuildsys/git.py index 642dd72..acfe893 100644 --- a/gitbuildsys/git.py +++ b/gitbuildsys/git.py @@ -168,10 +168,10 @@ class Git: '--output=%s' % tarname, '--prefix=%s' % prefix ] - self._exec_git('archive', options) - - if zipcmd: - runner.quiet('%s %s' % (zipcmd, tarname)) + with Workdir(self.path): + self._exec_git('archive', options) + if zipcmd: + runner.quiet('%s %s' % (zipcmd, tarname)) - if finalname != tarfname: - os.rename(finalname, tarfname) + if finalname != tarfname: + os.rename(finalname, tarfname) diff --git a/gitbuildsys/utils.py b/gitbuildsys/utils.py index 2aadfe7..3b0b01a 100644 --- a/gitbuildsys/utils.py +++ b/gitbuildsys/utils.py @@ -107,3 +107,19 @@ def parse_spec(spec_path, macro): # TBD parse it directly msger.warning('cannot support parsing spec without rpmbuild command') return '' + +def get_processors(): + """ + get number of processors (online) based on + SC_NPROCESSORS_ONLN (returns 1 if config name does not exist). + """ + try: + return os.sysconf('SC_NPROCESSORS_ONLN') + except ValueError: + return 1 + +def get_hostarch(): + hostarch = os.uname()[4] + if hostarch == 'i686': + hostarch = 'i586' + return hostarch diff --git a/tools/gbs b/tools/gbs index c6e9334..93d7478 100755 --- a/tools/gbs +++ b/tools/gbs @@ -79,6 +79,71 @@ class TizenPkg(cmdln.Cmdln): if self.options.debug: msger.set_loglevel('debug') + @cmdln.alias("lb") + @cmdln.option('-D', '--dist', + default=None, + dest='dist', + help='Specify distribution configure file, which should' \ + 'be full path') + @cmdln.option('-R', '--repository', + action="append", + default=None, + type="string", + dest='repositories', + help='Specify package repositories, Supported format ' \ + 'is rpm-md') + @cmdln.option('-B', '--buildroot', + default=None, + dest='buildroot', + help='Specify build rootdir to setup chroot environment') + @cmdln.option('-A', '--arch', + default=None, + dest='arch', + help='build target arch ') + @cmdln.option('-C', '--clean', + action="store_true", + default=False, + dest='clean', + help='Delete old build root before initializing it') + @cmdln.option('--noinit', + action="store_true", + default=False, + dest='noinit', + help='Skip initialization of build root and start with build immediately') + @cmdln.option('--debuginfo', + action="store_true", + default=False, + dest='debuginfo', + help='Enable build debuginfo sub-packages') + + def do_localbuild(self, subcmd, opts, *args): + """${cmd_name}: local build package + + Usage: + gbs localbuild -R repository -A ARCH [options] [package git dir] + + [package git dir] is optional, if not specified, current dir wuold + be used. + + Examples: + gbs localbuild -R http://example1.org/packages/ \\ + -R http://example2.org/packages/ \\ + -A i586 \\ + -D /usr/share/gbs/tizen-1.0.conf + + Note: + + if -D not specified, distconf key in ~/.gbs.conf would be used. + If distconf key is None, dist conf file would be got from OBS + project (Trunk by default). + + ${cmd_option_list} + """ + + from gitbuildsys import cmd_localbuild as cmd + cmd.do(opts, args) + + @cmdln.alias("bl") @cmdln.option('-T', '--target-obsprj', default=None, -- 2.7.4