gbs local build support
authorZhang Qiang <qiang.z.zhang@intel.com>
Wed, 22 Feb 2012 07:21:54 +0000 (15:21 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Wed, 22 Feb 2012 07:21:54 +0000 (15:21 +0800)
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 [new file with mode: 0644]
distfiles/debian/control
distfiles/gbs.spec
gitbuildsys/buildservice.py
gitbuildsys/cmd_build.py
gitbuildsys/cmd_localbuild.py [new file with mode: 0644]
gitbuildsys/conf.py
gitbuildsys/git.py
gitbuildsys/utils.py
tools/gbs

diff --git a/data/tizen-1.0.conf b/data/tizen-1.0.conf
new file mode 100644 (file)
index 0000000..51238db
--- /dev/null
@@ -0,0 +1,446 @@
+%define _project Tizen:Main
+
+### from Tizen:Base
+%define _repository standard
+Patterntype: rpm-md comps \r
+Release: <CI_CNT>.<B_CNT>\r
+Support: build build-compare build-mkbaselibs\r
+\r
+%if "%_repository" == "cov"  \r
+Support: coverity-build  \r
+%endif  \r
+\r
+VMinstall: util-linux-ng  libblkid libuuid\r
+\r
+ExportFilter: \.armv7hl\.rpm$ armv8el\r
+ExportFilter: \.armv7thl*\.rpm$ armv8el\r
+ExportFilter: \.armv7tnh*\.rpm$ armv8el\r
+ExportFilter: \.armv7h*\.rpm$ armv8el\r
+ExportFilter: \.armv7nh*\.rpm$ armv8el\r
+ExportFilter: \.x86_64\.rpm$ x86_64\r
+ExportFilter: \.i586\.rpm$ i586\r
+ExportFilter: \.armv5el\.rpm$ armv5el\r
+ExportFilter: \.armv5tel\.rpm$ armv5el\r
+ExportFilter: \.armv6el\.rpm$ armv6el\r
+ExportFilter: \.armv6l\.rpm$ armv6el\r
+ExportFilter: \.armv6vl\.rpm$ armv6el\r
+ExportFilter: \.armv7el\.rpm$ armv7el\r
+ExportFilter: \.armv7l\.rpm$ armv7el\r
+ExportFilter: \.armv7vl\.rpm$ armv7el\r
+# filter out packages of cross setup on ia32\r
+ExportFilter: .*vanish\.rpm\r
+PublishFilter: .*vanish\.rpm\r
+ExportFilter: .*dontuse\.rpm\r
+PublishFilter: .*dontuse\.rpm\r
+\r
+\r
+#\r
+# ARM Start\r
+#\r
+%ifarch %arm\r
+# arm land\r
+%define cross_5 1\r
+%define cross_7 1\r
+%define native 1\r
+\r
+%define cross_7h 1\r
+\r
+%ifarch armv8el\r
+Changetarget: armv7hl-meego-linux\r
+%define _gnu gnueabi\r
+%if %{cross_7h}\r
+Prefer: cross-armv7hl-binutils-accel-armv7hl\r
+Prefer: cross-armv7hl-gcc-accel-armv7hl\r
+%define speedcommon 1\r
+%define speedbash 1\r
+%define speedbinutils 1\r
+%define speedgcc 1\r
+%define native 0\r
+%define speedtools 1\r
+#Support: cross-armv7tnhl-platformfile\r
+%endif\r
+%endif\r
+%ifarch armv7hl\r
+Changetarget: armv7hl-meego-linux\r
+%define _gnu gnueabi\r
+%if %{cross_7h}\r
+Prefer: cross-armv7hl-binutils-accel-armv7hl\r
+Prefer: cross-armv7hl-gcc-accel-armv7hl\r
+%define speedcommon 1\r
+%define speedbash 1\r
+%define speedbinutils 1\r
+%define speedgcc 1\r
+%define native 0\r
+%define speedtools 1\r
+#Support: cross-armv7tnhl-platformfile\r
+%endif\r
+%endif\r
+
+\r
+\r
+########################\r
+# preselect rpm targets  \r
+# more ifs for _repository possible as needed  \r
+#########################  \r
+%ifarch armv5el\r
+Changetarget: armv5tel-meego-linux\r
+%define _gnu gnueabi\r
+%if %{cross_5}\r
+%define speedcommon 1\r
+%define speedbash 1\r
+%define speedbinutils 1\r
+%define speedgcc 1\r
+%define native 0\r
+%endif\r
+%endif\r
+\r
+%ifarch armv6el\r
+Changetarget: armv6l-meego-linux\r
+%define _gnu gnueabi\r
+%endif\r
+\r
+\r
+\r
+%ifarch armv7el\r
+Changetarget: armv7l-meego-linux\r
+%define _gnu gnueabi\r
+%if %{cross_7}\r
+Support: cross-armv7l-platformfile\r
+Prefer: cross-armv7l-binutils-accel-armv7l\r
+Prefer: cross-armv7l-gcc-accel-armv7l\r
+%define speedcommon 1\r
+%define speedbash 1\r
+%define speedbinutils 1\r
+%define speedgcc 1\r
+%define native 0\r
+%define speedtools 1\r
+%endif\r
+\r
+%endif\r
+\r
+%if %speedtools\r
+Support: patch-x86-arm findutils-x86-arm gawk-x86-arm fdupes-x86-arm \r
+Preinstall: libfile-x86-arm\r
+Preinstall: rpm-libs-x86-arm\r
+Preinstall: bzip2-libs-x86-arm\r
+Preinstall: elfutils-libelf-x86-arm\r
+Preinstall: bzip2-x86-arm\r
+Preinstall: nss-softokn-freebl-x86-arm\r
+Preinstall: nss-x86-arm\r
+Preinstall: nspr-x86-arm\r
+Preinstall: tar-x86-arm\r
+Preinstall: libgcc-x86-arm\r
+Preinstall: libacl-x86-arm\r
+Preinstall: libattr-x86-arm\r
+Preinstall: coreutils-x86-arm\r
+Preinstall: libcap-x86-arm\r
+Preinstall: liblua-x86-arm\r
+Preinstall: popt-x86-arm\r
+Preinstall: sed-x86-arm\r
+Preinstall: xz-libs-x86-arm\r
+Preinstall: zlib-x86-arm\r
+Preinstall: file\r
+Preinstall: diffutils-x86-arm\r
+Preinstall: file-x86-arm\r
+Preinstall: sqlite-x86-arm\r
+Required: nss-softokn-freebl-x86-arm\r
+Required: nss-x86-arm\r
+Requires: nspr-x86-arm\r
+Required: libfile-x86-arm\r
+Required: bzip2-libs-x86-arm\r
+Required: elfutils-x86-arm\r
+Required: elfutils-libs-x86-arm\r
+Required: elfutils-libelf-x86-arm\r
+Required: diffutils-x86-arm\r
+Required: gzip-x86-arm\r
+Required: libgcc-x86-arm\r
+Required: libacl-x86-arm\r
+Required: libattr-x86-arm\r
+Required: coreutils-x86-arm\r
+Required: libcap-x86-arm\r
+Required: liblua-x86-arm\r
+Required: popt-x86-arm\r
+Required: xz-libs-x86-arm\r
+Required: zlib-x86-arm\r
+Required: file\r
+Required: file-x86-arm\r
+Required: sqlite-x86-arm\r
+Required: rpm-libs-x86-arm\r
+Required: rpm-x86-arm\r
+Required: rpm-build-x86-arm\r
+Runscripts: sed-x86-arm\r
+Runscripts: nss-x86-arm\r
+Runscripts: tar-x86-arm\r
+Runscripts: bzip2-x86-arm\r
+Runscripts: coreutils-x86-arm\r
+Runscripts: diffutils-x86-arm\r
+\r
+Preinstall: rpm-x86-arm\r
+Runscripts: rpm-x86-arm\r
+Runscripts: file-x86-arm\r
+\r
+Support: !rpmlint-mini\r
+Support: !rpmlint-mini-x86-arm\r
+Prefer: python-libs\r
+%endif\r
+\r
+\r
+%if %speedcommon\r
+# cross-compilation/speedup\r
+Preinstall: aaa-meego-accelerator eglibc-x86-arm \r
+Runscripts: aaa-meego-accelerator\r
+Required: aaa-meego-accelerator\r
+%endif\r
+\r
+%if %speedbash\r
+# bash\r
+Preinstall: bash-x86-arm libncurses-x86-arm\r
+Runscripts: bash-x86-arm\r
+%endif\r
+\r
+%if %speedbinutils\r
+Required: cross-arm-binutils-accel\r
+%endif\r
+\r
+%if %speedgcc\r
+Required: cross-arm-gcc-accel\r
+%endif\r
+\r
+Preinstall: rpm\r
+Preinstall: rpm-libs\r
+Required:   rpm\r
+Prefer:     rpm-libs\r
+Prefer:     rpm\r
+\r
+# now i586 land\r
+%else\r
+Ignore: libncurses-x86\r
+Preinstall: rpm rpm-libs\r
+Required:   rpm\r
+%endif\r
+\r
+#\r
+# ARM End\r
+#\r
+\r
+Preinstall: bash bzip2 coreutils liblua\r
+Preinstall: filesystem eglibc eglibc-common libacl libattr\r
+Preinstall: libgcc libcap\r
+Preinstall: popt readline  zlib sqlite  \r
+Preinstall: elfutils-libelf bzip2-libs libstdc++ setup libfile\r
+Preinstall: xz-libs \r
+Preinstall: libncurses\r
+Preinstall: nss nspr\r
+Preinstall: nss-softokn-freebl\r
+\r
+Runscripts: setup\r
+VMinstall: perl libblkid e2fsprogs-libs libuuid perl-libs grep libpcre \r
+Required: binutils gcc eglibc rpm-build libtool\r
+\r
+Support: libncurses\r
+Support: util-linux-ng\r
+Support: cpio gcc-c++ perl-libs perl  net-tools findutils\r
+Support: file findutils zlib bzip2 \r
+Support: gzip \r
+Support: make  patch sed  gawk tar grep coreutils pkgconfig \r
+Support: m4 libfile tzdata tizen-release\r
+Support: kernel-headers eglibc-headers\r
+Support: xz-lzma-compat\r
+\r
+Keep: binutils cpp  file findutils gawk gcc  gcc-c++\r
+Keep: gdbm gzip libada libunwind  eglibc-devel libpcre xz-lzma-compat \r
+Keep: make  gmp libcap groff cpio\r
+Keep: patch rpm-build  nss nspr elfutils python grep libgcc gcc-c++ \r
+Keep:  kernel-headers eglibc-headers perl-libs\r
+Keep: pkgconfig glib2 \r
+Keep: xz-lzma-compat\r
+Keep: mpc mpfr  tar sed\r
+Keep: cloog cloog-ppl ppl  \r
+Keep: nss-softokn-freebl\r
+\r
+\r
+\r
+# SLP\r
+Ignore: intltool:perl-libwww-perl\r
+# Build dependency cycle\r
+Ignore: filesystem:setup\r
+Ignore: rpm-build:xz\r
+Ignore: udev:udev-rules\r
+Ignore: xdg-utils:libcontentaction\r
+Ignore: cups:xinetd\r
+Ignore: cups:xinitd\r
+Ignore: alsa-lib:alsa-plugins-pulseaudio\r
+Ignore: nautilus:gvfs\r
+Ignore: polkit:ConsoleKit\r
+Ignore: iso-codes:xml-common\r
+Ignore: libzypp:gnupg\r
+Ignore: gvfs:gnome-disk-utility\r
+Ignore: firstboot:system-config-date\r
+Ignore: SDL:mkinitrd\r
+Ignore: SDL:kernel,kernel-netbook\r
+Ignore: pulseaudio:kernel\r
+Ignore: libzypp:expect\r
+Ignore: pulseaudio:rtkit\r
+Ignore: rpm:libcap\r
+Ignore: rpm-libs:libcap\r
+Ignore: fuse-sshfs:fastinit\r
+Ignore: dhcp:fastinit\r
+\r
+Ignore: libgnomeprint22:fastinit\r
+Ignore: gvfs:fastinit\r
+Ignore: gnome-desktop:gnome-user-docs\r
+Ignore: gnome-settings-daemon:gnome-control-center\r
+Ignore: avahi:fastinit\r
+Ignore: fastinit:udev\r
+Ignore: udev:fastinit\r
+Ignore: PackageKit:udev\r
+Ignore: cvs:vim-minimal\r
+Ignore: bluez:fastinit\r
+Ignore: aspell:aspell-en\r
+Ignore: fuse:kernel\r
+Ignore: fuse:fastinit\r
+Ignore: fastinit:module-init-tools\r
+Ignore: hwdata:module-init-tools\r
+Ignore: gzip:less\r
+Ignore: xmlto:text-www-browser \r
+Ignore: docbook-utils:text-www-browser \r
+Ignore: gtk2:hicolor-icon-theme\r
+Ignore: docbook-dtds:openjade\r
+Ignore: xmlto:passivetex\r
+Ignore: GConf-dbus:openldap\r
+Ignore: perl:rsyslog,tcsh,logrotate\r
+Ignore: rpm:curl,crontabs,logrotate\r
+Ignore: texinfo-tex:tetex\r
+Ignore: xorg-x11-server:hal-info\r
+Ignore: gcc:libgomp\r
+Ignore: autoconf:imake\r
+Ignore: ConsoleKit:dbus,dbus-devel\r
+Ignore: fastinit:kernel,udev,ethtool,mingetty\r
+Ignore: tetex:tetex-fonts,desktop-file-utils\r
+Ignore: pam:glib2\r
+\r
+Ignore: gettext-devel:libgcj,libstdc++-devel\r
+Ignore: pam-modules:resmgr\r
+Ignore: bind-utils:bind-libs\r
+Ignore: alsa:dialog,pciutils\r
+Ignore: portmap:syslogd\r
+Ignore: fontconfig:freetype2\r
+Ignore: fontconfig-devel:freetype2-devel\r
+Ignore: xorg-x11-libs:freetype2\r
+Ignore: xorg-x11:x11-tools,resmgr,xkeyboard-config,xorg-x11-Mesa,libusb,freetype2,libjpeg,libpng\r
+Ignore: arts:alsa,audiofile,resmgr,libogg,libvorbis\r
+Ignore: libxml2-devel:readline-devel\r
+Ignore: gnome-vfs2:gnome-mime-data,desktop-file-utils,cdparanoia,dbus-1,dbus-1-glib,krb5,hal,libsmbclient,fam,file_alteration\r
+Ignore: libgda:file_alteration\r
+Ignore: gnutls:lzo,libopencdk\r
+Ignore: libgnomecanvas-devel:glib-devel\r
+Ignore: libgnomeui:gnome-icon-theme,shared-mime-info\r
+Ignore: gnome-pilot:gnome-panel\r
+Ignore: postfix:pcre\r
+Ignore: docbook_4:iso_ent,sgml-skel,xmlcharent\r
+Ignore: docbook-xsl-stylesheets:xmlcharent\r
+Ignore: tetex:xorg-x11-libs,expat,fontconfig,freetype2,libjpeg,libpng,ghostscript-x11,xaw3d,gd,dialog,ed\r
+Ignore: mailx:smtp_daemon\r
+Ignore: cron:smtp_daemon\r
+\r
+\r
+\r
+
+### 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\r
+%meego_version 1.2\r
+%meego 1.2\r
+%opensuse_bs 1\r
+%vendor meego\r
+%_vendor meego\r
+%_default_patch_fuzz   2\r
+\r
+\r
+\r
+# python main version\r
+%py_ver         %(echo `python -c "import sys; print sys.version[:3]"`)\r
+\r
+# directories\r
+%py_prefix      %(echo `python -c "import sys; print sys.prefix"`)\r
+%py_libdir      %{py_prefix}/lib/python%{py_ver}\r
+%py_incdir      /usr/include/python%{py_ver}\r
+%py_sitedir     %{py_libdir}/site-packages\r
+%py_dyndir      %{py_libdir}/lib-dynload\r
+\r
+# pure python modules compilation\r
+%py_comp        python -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"\r
+%py_ocomp       python -O -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"\r
+\r
+%ext_info .gz\r
+%ext_man .gz\r
+\r
+%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 \\r
+%{nil}\r
+\r
+%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 \\r
+%{nil}\r
+\r
+%lang_package \\r
+%package locale \\r
+Summary: Translations and Locale for package %{name}\\r
+Group: Translations\\r
+AutoReqProv: 0\\r
+%description locale\\r
+This package provides translations for package %{name}.\\r
+%files locale -f %{name}.lang\\r
+%defattr(-,root,root,-)\\r
+%{nil}\r
+\r
+\r
+%docs_package \\r
+%package docs \\r
+Summary: Documentation for package %{name}\\r
+Group: Documentation\\r
+AutoReqProv: 0\\r
+%description docs\\r
+This package provides documentation for package %{name}.\\r
+%files docs -f documentation.list\\r
+%defattr(-,root,root,-)\\r
+%{nil}\r
+\r
+%devel_package \\r
+%package devel \\r
+Summary: Development files for package %{name}\\r
+Group: Development\\r
+%description devel\\r
+This package provides header files and other developer releated files for package %{name}.\\r
+%files devel \\r
+%{_includedir}/*\\r
+%{_libdir}/pkgconfig/*.pc\\r
+%{_libdir}/*.so\\r
+%{nil}\r
+\r
+\r
+%_smp_mflags -j4\r
+\r
+\r
+%remove_docs \\r
+  rm -rf %{?buildroot:%{buildroot}}%{_infodir} \\r
+  rm -rf %{?buildroot:%{buildroot}}%{_defaultdocdir} \\r
+  rm -rf %{?buildroot:%{buildroot}}%{_datadir}/doc/%{name} \\r
+  rm -rf %{?buildroot:%{buildroot}}%{_datadir}/gtk-doc \\r
+  rm -rf %{?buildroot:%{buildroot}}%{_datadir}/man \\r
+  find %{?buildroot:%{buildroot}} -regex ".*/man/man./.*\.[0-9]" | xargs rm -f -- \\r
+  find %{?buildroot:%{buildroot}} -regex ".*/man/../man./.*\.[0-9]" | xargs rm -f -- \\r
+  find %{?buildroot:%{buildroot}} -regex ".*/man/man./.*\.[0-9]pm" | xargs rm -f --\r
+\r
+\r
+\r
+%define  __global_cflags        -O2 -g -pipe -Wall  -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security\r
+Optflags: armv7l %{__global_cflags}  -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian  -mfpu=vfpv3 -mfloat-abi=softfp -D__SOFTFP__\r
+
+%distribution Tizen:Main
+%_project Tizen:Main
index e6880cc5e4d1c1e4a5a5fe4ce324bb1fd304d834..fc37e32b75909861596bb2f02a1b4c8e86a8589e 100644 (file)
@@ -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
index 7d532b09b85efcac78e980536a50b8a8f3ad0f57..dd35c1d76f04b756ecb8dd941cc363411d953d03 100644 (file)
@@ -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
index e3919ae987b40f57f374deea3bccae841118c0ba..6ec5fd6d0e2208b47499b9db3eb047206c18e2b5 100644 (file)
@@ -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
+
index 3b0bf7ceb64caf0d37266304101cd8c3d0bf9077..4c0c9364a674d5295c7e416a3201ff783d43fb54 100644 (file)
@@ -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 (file)
index 0000000..62c9270
--- /dev/null
@@ -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')
index a901f7de553575ec086d6a20088147afd8da725d..3f09ec5bdd5d92ca779a381e9019649bad7ba2ae 100644 (file)
@@ -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':
index 642dd7284590389902d88d54d814ee4f45c92111..acfe8931587c1aa6cfff180bc503e750786ee78d 100644 (file)
@@ -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)
index 2aadfe72d079840162c7322b7b5003774f07c012..3b0b01a2507f78af64335f7113bddcb757f6d39d 100644 (file)
@@ -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
index c6e9334635b5eeacbad656a56ca23d9b9c500af0..93d7478ece1ee1b16990b5e86bcc41e8d705d56d 100755 (executable)
--- 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,