Make local buildroot configurable in config file
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 24 Sep 2012 10:47:22 +0000 (13:47 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 15 Oct 2012 07:14:36 +0000 (10:14 +0300)
The buildroot can be set under the 'general' section as a global setting
and/or under individual profiles as a profile-wide setting.

Setting supports string substitution for ${tmpdir} and ${profile}.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gitbuildsys/cmd_build.py
gitbuildsys/conf.py

index c6c7c90efa80057732ecad522b842668afa4d3da..d06d5084b028aab61b573a0267b3ada1f0e5931a 100644 (file)
@@ -24,10 +24,12 @@ import subprocess
 import tempfile
 import shutil
 import pwd
+import re
 
 from gitbuildsys import msger, utils, runner, errors
 from gitbuildsys.conf import configmgr
 from gitbuildsys.safe_url import SafeURL
+from gitbuildsys.cmd_export import transform_var_format_from_shell_to_python
 
 from gbp.rpm.git import GitRepositoryError, RpmGitRepository
 
@@ -59,14 +61,14 @@ SUPPORTEDARCHS = [
             'armv7l',
           ]
 
+USERID = pwd.getpwuid(os.getuid())[0]
+TMPDIR = os.path.join(configmgr.get('tmpdir', 'general'), '%s-gbs' % USERID)
+
 def prepare_repos_and_build_conf(args, arch):
     '''generate repos and build conf options for depanneur'''
 
     cmd_opts = []
-    userid     = pwd.getpwuid(os.getuid())[0]
-    tmpdir     = os.path.join(configmgr.get('tmpdir', 'general'),
-                              '%s-gbs' % userid)
-    cache = utils.Temp(prefix=os.path.join(tmpdir, 'gbscache'),
+    cache = utils.Temp(prefix=os.path.join(TMPDIR, 'gbscache'),
                        directory=True)
     cachedir  = cache.path
     if not os.path.exists(cachedir):
@@ -107,8 +109,8 @@ def prepare_repos_and_build_conf(args, arch):
                         'use snapshot repo or specify build config using '
                         '-D option')
         else:
-            shutil.copy(repoparser.buildconf, tmpdir)
-            distconf = os.path.join(tmpdir, os.path.basename(\
+            shutil.copy(repoparser.buildconf, TMPDIR)
+            distconf = os.path.join(TMPDIR, os.path.basename(\
                                     repoparser.buildconf))
             msger.info('build conf has been downloaded at:\n      %s' \
                        % distconf)
@@ -293,11 +295,20 @@ def main(args):
         msger.error('arch %s not supported, supported archs are: %s ' % \
                    (buildarch, ','.join(SUPPORTEDARCHS)))
 
-    build_root = os.path.expanduser('~/GBS-ROOT/')
-    if 'TIZEN_BUILD_ROOT' in os.environ:
-        build_root = os.environ['TIZEN_BUILD_ROOT']
+    profile = configmgr.get_current_profile()
     if args.buildroot:
         build_root = args.buildroot
+    elif 'TIZEN_BUILD_ROOT' in os.environ:
+        build_root = os.environ['TIZEN_BUILD_ROOT']
+    elif profile.buildroot:
+        build_root = profile.buildroot
+    else:
+        build_root = configmgr.get('buildroot', 'general')
+    build_root = os.path.expanduser(build_root)
+    build_root = transform_var_format_from_shell_to_python(build_root)
+    sanitized_profile_name = re.sub("[^a-zA-Z0-9:._-]", "_", profile.name)
+    build_root = build_root % {'tmpdir': TMPDIR,
+                               'profile': sanitized_profile_name}
     os.environ['TIZEN_BUILD_ROOT'] = build_root
 
     # get virtual env from system env first
index 0bb34498635dd99d93bc0c39347c1a7abadc5ff3..026fa120563eb3506c771de90c3167e16aa8946c 100644 (file)
@@ -188,6 +188,7 @@ class ConfigMgr(object):
                 'upstream_branch': 'upstream',
                 'upstream_tag': 'upstream/${upstreamversion}',
                 'squash_patches_until': '',
+                'buildroot':    '~/GBS-ROOT/',
             },
     }
 
@@ -463,6 +464,7 @@ class Profile(object):
         self.common_password = password
         self.repos = []
         self.obs = None
+        self.buildroot = None
 
     def add_repo(self, repoconf):
         '''add a repo to repo list of the profile'''
@@ -482,6 +484,8 @@ class Profile(object):
         if self.common_password:
             parser.set(self.name, 'passwdx',
                        encode_passwd(self.common_password))
+        if self.buildroot:
+            parser.set(self.name, 'buildroot', self.buildroot)
 
         if self.obs:
             parser.set(self.name, 'obs', self.obs.name)
@@ -593,6 +597,8 @@ class BizConfigManager(ConfigMgr):
                                     self._get_url_options(repo))
                 profile.add_repo(repoconf)
 
+        profile.buildroot = self.get_optional_item(name, 'buildroot')
+
         return profile
 
     def _parse_build_repos(self):