From 5630fa2f0287dff7cbc0fc4151a3d71e39fe9b54 Mon Sep 17 00:00:00 2001 From: Zhang Qiang Date: Fri, 6 Jul 2012 14:54:36 +0800 Subject: [PATCH] gbs chroot support, implement #70 --- gitbuildsys/cmd_chroot.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++ tools/gbs | 21 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 gitbuildsys/cmd_chroot.py diff --git a/gitbuildsys/cmd_chroot.py b/gitbuildsys/cmd_chroot.py new file mode 100644 index 0000000..6cf8b8a --- /dev/null +++ b/gitbuildsys/cmd_chroot.py @@ -0,0 +1,53 @@ +#!/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: chroot +""" + +import os +import subprocess + +import msger +from conf import configmgr + +def do(opts, args): + + if opts.arch in ['ia32', 'i686', 'i586', 'i386']: + arch = 'i686' + else: + arch = opts.arch + userid = configmgr.get('user', 'remotebuild') + tmpdir = configmgr.get('tmpdir', 'general') + build_root = os.path.join(tmpdir, userid, 'gbs-builroot.%s' % arch) + running_lock = '%s/not-ready' % build_root + if os.path.exists(running_lock) or not os.path.exists(build_root): + msger.error('build root %s is not ready' % build_root) + + msger.info('chroot %s' % build_root) + user = 'abuild' + if opts.root: + user = 'root' + cmd = ['sudo', 'chroot', build_root, 'su', user] + try: + build_env = os.environ + build_env['PS1']="(tizen-build-env)@\h \W]\$ " + subprocess.call(cmd, env=build_env) + except OSError, err: + msger.error('failed to chroot to %s: %s' % (build_root, err)) + except KeyboardInterrupt: + msger.info('keyboard interrupt ...') diff --git a/tools/gbs b/tools/gbs index 6191573..54139a5 100755 --- a/tools/gbs +++ b/tools/gbs @@ -227,6 +227,27 @@ class Gbs(cmdln.Cmdln): from gitbuildsys import cmd_build as cmd cmd.do(opts, args) + @cmdln.alias('ch') + @cmdln.option('-r', '--root', + action='store_true', + default=False, + dest='root', + help='chroot as root instead of abuild by default') + @cmdln.option('-A', '--arch', + default='i586', + dest='arch', + help='specify the build root arch') + def do_chroot(self, subcmd, opts, *args): + """${cmd_name}: chroot to build root + + Usage: + gbs chroot [options] + + ${cmd_option_list} + """ + + from gitbuildsys import cmd_chroot as cmd + cmd.do(opts, args) @cmdln.alias('rb') @cmdln.option('-T', '--target-obsprj', -- 2.7.4