gbs chroot support, implement #70
authorZhang Qiang <qiang.z.zhang@intel.com>
Fri, 6 Jul 2012 06:54:36 +0000 (14:54 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Sat, 7 Jul 2012 06:22:42 +0000 (14:22 +0800)
gitbuildsys/cmd_chroot.py [new file with mode: 0644]
tools/gbs

diff --git a/gitbuildsys/cmd_chroot.py b/gitbuildsys/cmd_chroot.py
new file mode 100644 (file)
index 0000000..6cf8b8a
--- /dev/null
@@ -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 ...')
index 619157322433824954bd2230b185c5437a5ce38d..54139a55e2e1455ec9c6b7e52fd1445851894f2f 100755 (executable)
--- 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',