rename build->remotebuild, localbuild->build
authorEd Bartosh <eduard.bartosh@intel.com>
Wed, 16 May 2012 15:32:48 +0000 (18:32 +0300)
committerEd Bartosh <eduard.bartosh@intel.com>
Wed, 16 May 2012 15:32:48 +0000 (18:32 +0300)
Change-Id: Ida27a695bc6650b130b74d1a7e8b5f193350cb46

README.rst
gitbuildsys/cmd_build.py
gitbuildsys/cmd_localbuild.py [deleted file]
gitbuildsys/cmd_remotebuild.py [new file with mode: 0644]
gitbuildsys/conf.py
tools/gbs

index c8fdec06cf47e4ac7f3f8bfd24068c1c57413c16..646f13006a08c36444da899a95e23a5c86ab0cf2 100644 (file)
@@ -11,8 +11,8 @@ Overview
 ========
 git-build-system is a command line tools for Tizen package developers
 
-* gbs build : build rpm package from git repository on OBS
-* gbs local-build : build rpm package from git repository at local
+* gbs remotebuild : build rpm package from git repository on OBS
+* gbs build : build rpm package from git repository at local
 * gbs import-orig: import source tarball to current git repository, which can be used to upgrade a package
 * gbs import : import source rpm or specfile to git repository
 * gbs submit : maintain the changelogs file, sanity check etc.
@@ -161,13 +161,13 @@ configuration file by yourself.  Just make sure it looks like as below:
   [general]
   ; general settings
   tmpdir = /var/tmp
-  [build]
+  [remotebuild]
   ; settings for build subcommand
   build_server = <OBS API URL>
   user = <USER_NAME>
   passwd  = <PASSWORD in base64 string>
   passwdx = <PASSWORD encoded in base64 string>
-  [localbuild]
+  [build]
   build_cmd = /usr/bin/build
   build_root= /var/tmp/build-root-gbs
   su-wrapper= su -c
@@ -177,10 +177,10 @@ configuration file by yourself.  Just make sure it looks like as below:
   commit_email= <Author Email>
 
 In this configuration file, there are three sections: [common] is for general
-setting, [build] section is for the options of gbs build, and [localbuild]
-is for gbs localbuild.
+setting, [remotebuild] section is for the options of gbs remotebuild, and [build]
+is for gbs build.
 
-In the [build] section, the following values can be specified:
+In the [remotebuild] section, the following values can be specified:
 
 build_server
     OBS API url, which point to remote OBS. Available value can be:
@@ -192,7 +192,7 @@ passwd
 passwdx
     encoded OBS account user passwd, this key would be generated automaticlly.
 
-In the [localbuild] section, the following values can be specified:
+In the [build] section, the following values can be specified:
 
 build_cmd
     build script path for building RPMs in a chroot environment
@@ -213,17 +213,17 @@ Usages
 It's recommended to use `--help` or `help <subcmd>` to get the help message,
 for the tool is more or less self-documented.
 
-Running 'gbs build'
---------------------
+Running 'gbs remotebuild'
+------------------------
 
-Subcommand `build` is used to push local git code to remote obs build server
-to build. The usage of subcommand `build` can be available using `gbs build --help`
+Subcommand `remotebuild` is used to push local git code to remote obs build server
+to build. The usage of subcommand `remotebuild` can be available using `gbs remotebuild --help`
 ::
 
-  build (bl): test building for current pkg
+  remotebuild (rb): remote build package
 
   Usage:
-      gbs build [options] [OBS_project]
+      gbs remotebuild [options] [package git dir]
 
   Options:
       -h, --help          show this help message and exit
@@ -234,36 +234,36 @@ to build. The usage of subcommand `build` can be available using `gbs build --he
                           OBS target project being used to build package, use
                           "home:<userid>:gbs:Trunk" if not specified
 
-Before running gbs build, you need to prepare a package git repository first,
-and packaging directory must be exist and have spec file in it. The spec file
-is used to prepare package name, version and tar ball format, and tar ball
+Before running gbs remotebuild, you need to prepare a package git repository
+first, and packaging directory must be exist and have spec file in it. The spec
+file is used to prepare package name, version and tar ball format, and tar ball
 format is specified using SOURCE field in specfile.
 
 Once git reposoritory and packaging directory are  ready,  goto  the  root
 directory of git repository, run gbs build as follows:
 ::
 
-  $ gbs build
-  $ gbs build -B Test
-  $ gbs build -B Test -T home:<userid>:gbs
+  $ gbs remotebuild
+  $ gbs remotebuild -B Test
+  $ gbs remotebuild -B Test -T home:<userid>:gbs
 
-Running 'gbs localbuild'
+Running 'gbs build'
 ------------------------
 
-Subcommand `localbuild` is used to build rpm package at local by rpmbuild. The
-usage of subcommand `localbuild` can be available using `gbs localbuild --help`
+Subcommand `build` is used to build rpm package at local by rpmbuild. The
+usage of subcommand `build` can be available using `gbs build --help`
 ::
 
-  localbuild (lb): local build package
+  build (lb): local build package
   Usage:
-      gbs localbuild -R repository -A ARCH [options] [package git dir]
+      gbs build -R repository -A arch [options] [package git dir]
       [package git dir] is optional, if not specified, current dir would
       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
+      gbs build -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.
   Options:
@@ -285,17 +285,17 @@ usage of subcommand `localbuild` can be available using `gbs localbuild --help`
 
 git repository and packaging directory should be prepared like `gbs build`.
 
-Examples to run gbs localbuild:
+Examples to run gbs build:
 
 1) Use specified dist file in command line using -D option
 ::
 
-  $ gbs localbuild -R http://example1.org/ -A i586 -D /usr/share/gbs/tizen-1.0.conf
+  $ gbs build -R http://example1.org/ -A i586 -D /usr/share/gbs/tizen-1.0.conf
 
 2) Use dist conf file specified in ~/.gbs.conf, if distconf key exist.
 ::
 
-  $ gbs localbuild -R http://example1.org/ -A i586
+  $ gbs build -R http://example1.org/ -A i586
 
 3) Multi repos specified
 ::
@@ -305,19 +305,19 @@ Examples to run gbs localbuild:
 4) With --noinit option, Skip initialization of build root and start with build immediately
 ::
 
-  $ gbs localbuild -R http://example1.org/ -A i586  --noinit
+  $ gbs build -R http://example1.org/ -A i586  --noinit
 
 5) Specify a package git directory, instead of running in git top directory
 ::
 
-  $ gbs localbuild -R http://example1.org/ -A i586  PackageKit
+  $ gbs build -R http://example1.org/ -A i586  PackageKit
 
 6) Local repo example
 ::
 
-  $ gbs localbuild -R /path/to/repo/dir/ -A i586
+  $ gbs build -R /path/to/repo/dir/ -A i586
 
-'''BKM''': to have quick test with local repo, you can run 'gbs localbuild' 
+'''BKM''': to have quick test with local repo, you can run 'gbs build' 
 with remote repo. rpm packages will be downloaded to localdir /var/cache/\
 build/md5-value/, then you can use the following command to create it as local
 repo
@@ -326,9 +326,9 @@ repo
   $ mv /var/cache/build/md5-value/ /var/cache/build/localrepo
   $ cd /var/cache/build/localrepo
   $ createrepo . # if createrepo is not available, you should install it first
-  $ gbs localbuild -R /var/cache/build/localrepo/ -A i586/armv7hl
+  $ gbs build -R /var/cache/build/localrepo/ -A i586/armv7hl
 
-If gbs localbuild fails with dependencies, you should download it manually and
+If gbs build fails with dependencies, you should download it manually and
 put it to /var/cache/build/localrepo, then createrepo again.
 
 
index bc326b8720131c9dcc78531eed1caea65ea87b54..45dc453372f81ed679fe3a7ef6a96c47d1a5505e 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/python -tt
 # vim: ai ts=4 sts=4 et sw=4
 #
-# Copyright (c) 2011 Intel, Inc.
+# 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
 # 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: build
+"""Implementation of subcmd: localbuild
 """
 
 import os
 import tempfile
 import glob
+import subprocess
+import urlparse
 
 import msger
-from conf import configmgr
-import obspkg
+import utils
 import errors
-from utils import Workdir
+from conf import configmgr
 
-import gbp.rpm
-from gbp.scripts.buildpackage_rpm import main as gbp_build
+from gbp.scripts.buildpackage_rpm import git_archive, guess_comp_type
+from gbp.rpm.git import GitRepositoryError, RpmGitRepository
+import gbp.rpm as rpm
+from gbp.errors import GbpError
+
+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',
+          }
+
+supportedarchs = [
+            'x86_64',
+            'i686',
+            'i586',
+            'armv7hl',
+            'armv7el',
+            'armv7tnhl',
+            'armv7nhl',
+            'armv7l',
+          ]
 
 OSCRC_TEMPLATE = """[general]
 apiurl = %(apiurl)s
@@ -51,12 +86,35 @@ TMPDIR      = configmgr.get('tmpdir')
 
 def do(opts, args):
 
+    if os.geteuid() != 0:
+        msger.error('Root permission is required, please use sudo and try again')
+
     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
+    if not buildarch in supportedarchs:
+        msger.error('arch %s not supported, supported archs are: %s ' % \
+                   (buildarch, ','.join(supportedarchs)))
+
+    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.')
+
+
     tmpdir = '%s/%s' % (TMPDIR, USER)
     if not os.path.exists(tmpdir):
         os.makedirs(tmpdir)
@@ -68,65 +126,124 @@ def do(opts, args):
                 "user": USER,
                 "passwdx": PASSWDX,
             }
-    (fds, oscrcpath) = tempfile.mkstemp(dir=tmpdir, prefix='.oscrc')
-    os.close(fds)
-    with file(oscrcpath, 'w+') as foscrc:
-        foscrc.write(oscrc)
+    (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
+        """
+
+    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.')
 
-    # TODO: check ./packaging dir at first
-    specs = glob.glob('%s/packaging/*.spec' % workdir)
-    if not specs:
-        msger.error('no spec file found under /packaging sub-directory')
+    if opts.noinit:
+        cmd += ['--no-init']
+    if opts.ccache:
+        cmd += ['--ccache']
+    cmd += [specfile]
 
-    specfile = specs[0] #TODO:
-    if len(specs) > 1:
-        msger.warning('multiple specfiles found.')
+    if hostarch != buildarch and buildarch in change_personality:
+        cmd = [ change_personality[buildarch] ] + cmd;
 
-    # get 'name' and 'version' from spec file
-    spec = gbp.rpm.parse_spec(specfile)
+    if buildarch.startswith('arm'):
+        try:
+            utils.setup_qemu_emulator()
+        except errors.QemuError, e:
+            msger.error('%s' % e)
+
+    spec = rpm.parse_spec(specfile)
     if not spec.name or not spec.version:
         msger.error('can\'t get correct name or version from spec file.')
 
-    if opts.base_obsprj is None:
-        # TODO, get current branch of git to determine it
-        base_prj = 'Trunk'
-    else:
-        base_prj = opts.base_obsprj
-
-    if opts.target_obsprj is None:
-        target_prj = "home:%s:gbs:%s" % (USER, base_prj)
-    else:
-        target_prj = opts.target_obsprj
-
-    prj = obspkg.ObsProject(target_prj, apiurl = APISERVER, oscrc = oscrcpath)
-    msger.info('checking status of obs project: %s ...' % target_prj)
-    if prj.is_new():
-        msger.info('creating %s for package build ...' % target_prj)
-        try:
-            prj.branch_from(base_prj)
-        except errors.ObsError, exc:
-            msger.error('%s' % exc)
-
-    msger.info('checking out %s/%s to %s ...' % (target_prj, spec.name, tmpdir))
-    localpkg = obspkg.ObsPackage(tmpdir, target_prj, spec.name,
-                                 APISERVER, oscrcpath)
-    oscworkdir = localpkg.get_workdir()
-    localpkg.remove_all()
-
-    with Workdir(workdir):
-        if gbp_build(["argv[0] placeholder", "--git-export-only",
-                      "--git-ignore-new", "--git-builder=osc",
-                      "--git-export-dir=%s" % oscworkdir,
-                      "--git-packaging-dir=packaging"]):
-            msger.error("Failed to get packaging info from git tree")
-
-    localpkg.update_local()
-
-    msger.info('commit packaging files to build server ...')
-    localpkg.commit ('submit packaging files to obs for OBS building')
-
-    os.unlink(oscrcpath)
-    msger.info('local changes submitted to build server successfully')
-    msger.info('follow the link to monitor the build progress:\n'
-               '  %s/package/show?package=%s&project=%s' \
-               % (APISERVER.replace('api', 'build'), spec.name, target_prj))
+    urlres = urlparse.urlparse(spec.orig_file)
+
+    tarball = 'packaging/%s' % os.path.basename(urlres.path)
+    msger.info('generate tar ball: %s' % tarball)
+    try:
+        repo = RpmGitRepository(workdir)
+    except GitRepositoryError:
+        msger.error("%s is not a git repository" % (os.path.curdir))
+
+    try:
+        comp_type = guess_comp_type(spec)
+        if not git_archive(repo, spec, "%s/packaging" % workdir, 'HEAD', comp_type,
+                           comp_level=9, with_submodules=True):
+            msger.error("Cannot create source tarball %s" % tarball)
+    except GbpError, exc:
+        msger.error(str(exc))
+    if opts.incremental:
+        cmd += ['--rsync-src=%s' % os.path.abspath(workdir)]
+        cmd += ['--rsync-dest=/home/abuild/rpmbuild/BUILD/%s-%s' % (name, version)]
+
+    msger.info(' '.join(cmd))
+
+    # runner.show() can't support interactive mode, so use subprocess insterad.
+    try:
+        rc = subprocess.call(cmd)
+        if rc:
+            msger.error('rpmbuild fails')
+        else:
+            msger.info('The buildroot was: %s' % build_root)
+            msger.info('Done')
+    except KeyboardInterrupt, i:
+        msger.info('keyboard interrupt, killing build ...')
+        subprocess.call(cmd + ["--kill"])
+        msger.error('interrrupt from keyboard')
+    finally:
+        os.unlink("%s/%s" % (workdir, tarball))
+        os.unlink(oscrcpath)
+        if bc_filename:
+            os.unlink(bc_filename)
diff --git a/gitbuildsys/cmd_localbuild.py b/gitbuildsys/cmd_localbuild.py
deleted file mode 100644 (file)
index 45dc453..0000000
+++ /dev/null
@@ -1,249 +0,0 @@
-#!/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 tempfile
-import glob
-import subprocess
-import urlparse
-
-import msger
-import utils
-import errors
-from conf import configmgr
-
-from gbp.scripts.buildpackage_rpm import git_archive, guess_comp_type
-from gbp.rpm.git import GitRepositoryError, RpmGitRepository
-import gbp.rpm as rpm
-from gbp.errors import GbpError
-
-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',
-          }
-
-supportedarchs = [
-            'x86_64',
-            'i686',
-            'i586',
-            'armv7hl',
-            'armv7el',
-            'armv7tnhl',
-            'armv7nhl',
-            'armv7l',
-          ]
-
-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):
-
-    if os.geteuid() != 0:
-        msger.error('Root permission is required, please use sudo and try again')
-
-    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
-    if not buildarch in supportedarchs:
-        msger.error('arch %s not supported, supported archs are: %s ' % \
-                   (buildarch, ','.join(supportedarchs)))
-
-    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.')
-
-
-    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
-        """
-
-    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 += ['--no-init']
-    if opts.ccache:
-        cmd += ['--ccache']
-    cmd += [specfile]
-
-    if hostarch != buildarch and buildarch in change_personality:
-        cmd = [ change_personality[buildarch] ] + cmd;
-
-    if buildarch.startswith('arm'):
-        try:
-            utils.setup_qemu_emulator()
-        except errors.QemuError, e:
-            msger.error('%s' % e)
-
-    spec = rpm.parse_spec(specfile)
-    if not spec.name or not spec.version:
-        msger.error('can\'t get correct name or version from spec file.')
-
-    urlres = urlparse.urlparse(spec.orig_file)
-
-    tarball = 'packaging/%s' % os.path.basename(urlres.path)
-    msger.info('generate tar ball: %s' % tarball)
-    try:
-        repo = RpmGitRepository(workdir)
-    except GitRepositoryError:
-        msger.error("%s is not a git repository" % (os.path.curdir))
-
-    try:
-        comp_type = guess_comp_type(spec)
-        if not git_archive(repo, spec, "%s/packaging" % workdir, 'HEAD', comp_type,
-                           comp_level=9, with_submodules=True):
-            msger.error("Cannot create source tarball %s" % tarball)
-    except GbpError, exc:
-        msger.error(str(exc))
-    if opts.incremental:
-        cmd += ['--rsync-src=%s' % os.path.abspath(workdir)]
-        cmd += ['--rsync-dest=/home/abuild/rpmbuild/BUILD/%s-%s' % (name, version)]
-
-    msger.info(' '.join(cmd))
-
-    # runner.show() can't support interactive mode, so use subprocess insterad.
-    try:
-        rc = subprocess.call(cmd)
-        if rc:
-            msger.error('rpmbuild fails')
-        else:
-            msger.info('The buildroot was: %s' % build_root)
-            msger.info('Done')
-    except KeyboardInterrupt, i:
-        msger.info('keyboard interrupt, killing build ...')
-        subprocess.call(cmd + ["--kill"])
-        msger.error('interrrupt from keyboard')
-    finally:
-        os.unlink("%s/%s" % (workdir, tarball))
-        os.unlink(oscrcpath)
-        if bc_filename:
-            os.unlink(bc_filename)
diff --git a/gitbuildsys/cmd_remotebuild.py b/gitbuildsys/cmd_remotebuild.py
new file mode 100644 (file)
index 0000000..bc326b8
--- /dev/null
@@ -0,0 +1,132 @@
+#!/usr/bin/python -tt
+# vim: ai ts=4 sts=4 et sw=4
+#
+# Copyright (c) 2011 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: build
+"""
+
+import os
+import tempfile
+import glob
+
+import msger
+from conf import configmgr
+import obspkg
+import errors
+from utils import Workdir
+
+import gbp.rpm
+from gbp.scripts.buildpackage_rpm import main as gbp_build
+
+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]
+
+    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,
+            }
+    (fds, oscrcpath) = tempfile.mkstemp(dir=tmpdir, prefix='.oscrc')
+    os.close(fds)
+    with file(oscrcpath, 'w+') as foscrc:
+        foscrc.write(oscrc)
+
+    # TODO: check ./packaging dir at first
+    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.')
+
+    # get 'name' and 'version' from spec file
+    spec = gbp.rpm.parse_spec(specfile)
+    if not spec.name or not spec.version:
+        msger.error('can\'t get correct name or version from spec file.')
+
+    if opts.base_obsprj is None:
+        # TODO, get current branch of git to determine it
+        base_prj = 'Trunk'
+    else:
+        base_prj = opts.base_obsprj
+
+    if opts.target_obsprj is None:
+        target_prj = "home:%s:gbs:%s" % (USER, base_prj)
+    else:
+        target_prj = opts.target_obsprj
+
+    prj = obspkg.ObsProject(target_prj, apiurl = APISERVER, oscrc = oscrcpath)
+    msger.info('checking status of obs project: %s ...' % target_prj)
+    if prj.is_new():
+        msger.info('creating %s for package build ...' % target_prj)
+        try:
+            prj.branch_from(base_prj)
+        except errors.ObsError, exc:
+            msger.error('%s' % exc)
+
+    msger.info('checking out %s/%s to %s ...' % (target_prj, spec.name, tmpdir))
+    localpkg = obspkg.ObsPackage(tmpdir, target_prj, spec.name,
+                                 APISERVER, oscrcpath)
+    oscworkdir = localpkg.get_workdir()
+    localpkg.remove_all()
+
+    with Workdir(workdir):
+        if gbp_build(["argv[0] placeholder", "--git-export-only",
+                      "--git-ignore-new", "--git-builder=osc",
+                      "--git-export-dir=%s" % oscworkdir,
+                      "--git-packaging-dir=packaging"]):
+            msger.error("Failed to get packaging info from git tree")
+
+    localpkg.update_local()
+
+    msger.info('commit packaging files to build server ...')
+    localpkg.commit ('submit packaging files to obs for OBS building')
+
+    os.unlink(oscrcpath)
+    msger.info('local changes submitted to build server successfully')
+    msger.info('follow the link to monitor the build progress:\n'
+               '  %s/package/show?package=%s&project=%s' \
+               % (APISERVER.replace('api', 'build'), spec.name, target_prj))
index 9b184df8f710e7b31a9a6e0f50bcbd526bcb951e..e26d33ce8f901b110b91cd12bb9f160ff2c0cb0d 100644 (file)
@@ -218,13 +218,13 @@ class ConfigMgr(object):
             'general': {
                 'tmpdir': '/var/tmp'
             },
-            'build': {
+            'remotebuild': {
                 'build_server': 'https://api.tizen.org',
                 'user':         'my_user_id',
                 'passwd':       '',
                 'passwdx':      '',
             },
-            'localbuild': {
+            'build': {
                 'build_cmd':    '/usr/bin/build',
                 'build_root':   '/var/tmp/build-root-gbs',
                 'su-wrapper':   'sudo',
@@ -241,12 +241,12 @@ class ConfigMgr(object):
 ; general settings
 tmpdir = $general__tmpdir
 editor = 
-[build]
+[remotebuild]
 ; settings for build subcommand
 build_server = $build__build_server
 user = $build__user
 passwdx = $build__passwdx
-[localbuild]
+[build]
 build_cmd = /usr/bin/build
 build_root= /var/tmp/build-root-gbs
 su-wrapper= sudo
index a6dadf974a1fcc0ae534a2bd83084a41e0124ba1..24ca618795dafb15fe7f233e3ba6c31e90c4b955 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -104,17 +104,17 @@ class Gbs(cmdln.Cmdln):
                   default=False,
                   dest='debuginfo',
                   help='Enable build debuginfo sub-packages')
-    def do_localbuild(self, _subcmd, opts, *args):
+    def do_build(self, _subcmd, opts, *args):
         """${cmd_name}: local build package
 
         Usage:
-            gbs localbuild -R repository -A ARCH [options] [package git dir]
+            gbs build -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/ \\
+            gbs build -R http://example1.org/packages/ \\
                            -R http://example2.org/packages/ \\
                            -A i586                          \\
                            -D /usr/share/gbs/tizen-1.0.conf
@@ -128,11 +128,11 @@ class Gbs(cmdln.Cmdln):
         ${cmd_option_list}
         """
 
-        from gitbuildsys import cmd_localbuild as cmd
+        from gitbuildsys import cmd_build as cmd
         cmd.do(opts, args)
 
 
-    @cmdln.alias('bl')
+    @cmdln.alias('rb')
     @cmdln.option('-T', '--target-obsprj',
                   default=None,
                   dest='target_obsprj',
@@ -143,24 +143,24 @@ class Gbs(cmdln.Cmdln):
                   dest='base_obsprj',
                   help='Base OBS project being used to branch from, ' \
                        'use "Trunk" if not specified')
-    def do_build(self, subcmd, opts, *args):
-        """${cmd_name}: test building for current pkg
+    def do_remotebuild(self, subcmd, opts, *args):
+        """${cmd_name}: remote build package
 
         Usage:
-            gbs build [options] [package git dir]
+            gbs remotebuild [options] [package git dir]
 
             [package git dir] is optional, if not specified, current dir wuold
             be used.
 
         Examples:
-          $ gbs build
-          $ gbs build -B Test
-          $ gbs build -B Test -T home:<userid>:gbs
-          $ gbs build <package git directory>
+          $ gbs remotebuild
+          $ gbs remotebuild -B Test
+          $ gbs remotebuild -B Test -T home:<userid>:gbs
+          $ gbs remotebuild <package git directory>
         ${cmd_option_list}
         """
 
-        from gitbuildsys import cmd_build as cmd
+        from gitbuildsys import cmd_remotebuild as cmd
         cmd.do(opts, args)