From 933ccf883f0955cc3795a9445e6450c45e245a04 Mon Sep 17 00:00:00 2001 From: Zhang Qiang Date: Thu, 10 May 2012 22:23:40 +0800 Subject: [PATCH] rename build->remotebuild, localbuild->build --- README.rst | 68 ++++++------ gitbuildsys/cmd_build.py | 211 ++++++++++++++++++++++++++--------- gitbuildsys/cmd_localbuild.py | 242 ----------------------------------------- gitbuildsys/cmd_remotebuild.py | 139 +++++++++++++++++++++++ gitbuildsys/conf.py | 8 +- tools/gbs | 26 ++--- 6 files changed, 347 insertions(+), 347 deletions(-) delete mode 100644 gitbuildsys/cmd_localbuild.py create mode 100644 gitbuildsys/cmd_remotebuild.py diff --git a/README.rst b/README.rst index c8fdec0..18cb689 100644 --- a/README.rst +++ b/README.rst @@ -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 = user = passwd = passwdx = - [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= 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 ` 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 build --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,33 +234,33 @@ to build. The usage of subcommand `build` can be available using `gbs build --he OBS target project being used to build package, use "home::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::gbs + $ gbs remotebuild + $ gbs remotebuild -B Test + $ gbs remotebuild -B Test -T home::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/ \ + gbs build -R http://example1.org/packages/ \ -R http://example2.org/packages/ \ -A i586 \ -D /usr/share/gbs/tizen-1.0.conf @@ -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. diff --git a/gitbuildsys/cmd_build.py b/gitbuildsys/cmd_build.py index 007788b..eaf35a6 100644 --- a/gitbuildsys/cmd_build.py +++ b/gitbuildsys/cmd_build.py @@ -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 @@ -20,19 +20,53 @@ """ import os +import sys import time import tempfile import glob import shutil +import subprocess import urlparse import msger import runner import utils +import errors from conf import configmgr import git -import obspkg -import errors +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', + } + +supportedarchs = [ + 'x86_64', + 'i686', + 'i586', + 'armv7hl', + 'armv7el', + 'armv7tnhl', + 'armv7nhl', + 'armv7l', + ] OSCRC_TEMPLATE = """[general] apiurl = %(apiurl)s @@ -46,19 +80,42 @@ user=%(user)s passx=%(passwdx)s """ -APISERVER = configmgr.get('build_server', 'build') -USER = configmgr.get('user', 'build') -PASSWDX = configmgr.get('passwdx', 'build') +APISERVER = configmgr.get('build_server', 'remotebuild') +USER = configmgr.get('user', 'remotebuild') +PASSWDX = configmgr.get('passwdx', 'remotebuild') 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) @@ -75,65 +132,111 @@ def do(opts, args): f = file(oscrcpath, 'w+') f.write(oscrc) f.close() - - # 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 - 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.') - - if opts.base_obsprj is None: - # TODO, get current branch of git to determine it - base_prj = 'Trunk' + distconf = configmgr.get('distconf', 'build') + 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', 'build') + build_root = configmgr.get('build_root', 'build') + 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: - base_prj = opts.base_obsprj + msger.error('No package repository specified.') - if opts.target_obsprj is None: - target_prj = "home:%s:gbs:%s" % (USER, base_prj) - else: - target_prj = opts.target_obsprj + if opts.noinit: + cmd += ['--no-init'] + if opts.ccache: + cmd += ['--ccache'] + cmd += [specfile] - 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) + if hostarch != buildarch and buildarch in change_personality: + cmd = [ change_personality[buildarch] ] + cmd; + + if buildarch.startswith('arm'): try: - prj.branch_from(base_prj) - except errors.ObsError, e: + utils.setup_qemu_emulator() + except errors.QemuError, e: msger.error('%s' % e) - msger.info('checking out %s/%s to %s ...' % (target_prj, name, tmpdir)) - localpkg = obspkg.ObsPackage(tmpdir, target_prj, name, APISERVER, oscrcpath) - oscworkdir = localpkg.get_workdir() - localpkg.remove_all() + 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.') source = utils.parse_spec(specfile, 'SOURCE0') urlres = urlparse.urlparse(source) - tarball = '%s/%s' % (oscworkdir, os.path.basename(urlres.path)) - msger.info('archive git tree to tarball: %s' % os.path.basename(tarball)) + tarball = 'packaging/%s' % os.path.basename(urlres.path) + msger.info('generate tar ball: %s' % tarball) mygit = git.Git(workdir) mygit.archive("%s-%s/" % (name, version), tarball) - for f in glob.glob('%s/packaging/*' % workdir): - shutil.copy(f, oscworkdir) - - 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'), name, target_prj)) + 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 index bfe6858..0000000 --- a/gitbuildsys/cmd_localbuild.py +++ /dev/null @@ -1,242 +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 sys -import time -import tempfile -import glob -import shutil -import subprocess -import urlparse - -import msger -import runner -import utils -import errors -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', - } - -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) - - 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.') - - source = utils.parse_spec(specfile, 'SOURCE0') - urlres = urlparse.urlparse(source) - - tarball = 'packaging/%s' % os.path.basename(urlres.path) - msger.info('generate tar ball: %s' % tarball) - mygit = git.Git(workdir) - mygit.archive("%s-%s/" % (name, version), tarball) - - 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 index 0000000..5d6971c --- /dev/null +++ b/gitbuildsys/cmd_remotebuild.py @@ -0,0 +1,139 @@ +#!/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: remotebuild +""" + +import os +import time +import tempfile +import glob +import shutil +import urlparse + +import msger +import runner +import utils +from conf import configmgr +import git +import obspkg +import errors + +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', 'remotebuild') +USER = configmgr.get('user', 'remotebuild') +PASSWDX = configmgr.get('passwdx', 'remotebuild') +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, + } + (fd, oscrcpath) = tempfile.mkstemp(dir=tmpdir,prefix='.oscrc') + os.close(fd) + f = file(oscrcpath, 'w+') + f.write(oscrc) + f.close() + + # 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 + 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.') + + 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, e: + msger.error('%s' % e) + + msger.info('checking out %s/%s to %s ...' % (target_prj, name, tmpdir)) + localpkg = obspkg.ObsPackage(tmpdir, target_prj, name, APISERVER, oscrcpath) + oscworkdir = localpkg.get_workdir() + localpkg.remove_all() + + source = utils.parse_spec(specfile, 'SOURCE0') + urlres = urlparse.urlparse(source) + + tarball = '%s/%s' % (oscworkdir, os.path.basename(urlres.path)) + 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('%s/packaging/*' % workdir): + shutil.copy(f, oscworkdir) + + 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'), name, target_prj)) diff --git a/gitbuildsys/conf.py b/gitbuildsys/conf.py index a51dfa6..d489f9d 100644 --- a/gitbuildsys/conf.py +++ b/gitbuildsys/conf.py @@ -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 -[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 diff --git a/tools/gbs b/tools/gbs index aa8d7ce..7f917ac 100755 --- a/tools/gbs +++ b/tools/gbs @@ -105,17 +105,17 @@ class TizenPkg(cmdln.Cmdln): 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 @@ -129,11 +129,11 @@ class TizenPkg(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', @@ -144,24 +144,24 @@ class TizenPkg(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::gbs - $ gbs build + $ gbs remotebuild + $ gbs remotebuild -B Test + $ gbs remotebuild -B Test -T home::gbs + $ gbs remotebuild ${cmd_option_list} """ - from gitbuildsys import cmd_build as cmd + from gitbuildsys import cmd_remotebuild as cmd cmd.do(opts, args) -- 2.7.4