Add upstream-branch and upstream-tag options
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 17 Aug 2012 13:58:10 +0000 (16:58 +0300)
committerZhang Qiang <qiang.z.zhang@intel.com>
Sat, 8 Sep 2012 06:50:27 +0000 (14:50 +0800)
Add config file and command line options to specify the upstream branch
name and upstream tag format for build, export and remotebuild commands.
This is needed in order to be able to support different maintenance
models of non-native packages (with patch-generation enabled):
1. If upstream sources are imported with GBS, these options are not
   needed
2. However, if maintainer uses upstream git tree directly, he needs to
   be able to specify the tag format - otherwise gbp is unable to
   create orig source archive or generate patches

Command line option takes preference over the config file.

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

index 5b140e3..4df2238 100644 (file)
@@ -363,7 +363,7 @@ def do(opts, args):
             commit = 'HEAD'
         relative_spec = specfile.replace('%s/' % workdir, '')
         msger.info('export tar ball and packaging files ... ')
-        export_sources(repo, commit, export_dir, relative_spec)
+        export_sources(repo, commit, export_dir, relative_spec, opts)
 
     # Parse spec file
     try:
index 8622a26..6f51d11 100644 (file)
@@ -44,24 +44,42 @@ def mkdir_p(path):
         else:
             raise
 
-def is_native_pkg(repo):
+def is_native_pkg(repo, opts):
     """
     Determine if the package is "native"
     """
-    return not repo.has_branch("upstream")
+    if opts.upstream_branch:
+        upstream_branch = opts.upstream_branch
+    else:
+        upstream_branch = configmgr.get('upstream_branch', 'general')
+    return not repo.has_branch(upstream_branch)
 
-def create_gbp_export_args(repo, commit, export_dir, spec, force_native=False):
+def create_gbp_export_args(repo, commit, export_dir, spec, opts,
+                           force_native=False):
     """
     Construct the cmdline argument list for git-buildpackage export
     """
+    if opts.upstream_branch:
+        upstream_branch = opts.upstream_branch
+    else:
+        upstream_branch = configmgr.get('upstream_branch', 'general')
+    if opts.upstream_tag:
+        upstream_tag = opts.upstream_tag
+    else:
+        upstream_tag = configmgr.get('upstream_tag', 'general')
+    msger.debug("Using upstream branch: %s" % upstream_branch)
+    msger.debug("Using upstream tag format: '%s'" % upstream_tag)
+
     args = ["argv[0] placeholder", "--git-export-only",
             "--git-ignore-new", "--git-builder=osc",
             "--git-upstream-branch=upstream",
             "--git-export-dir=%s" % export_dir,
             "--git-packaging-dir=packaging",
             "--git-spec-file=%s" % spec,
-            "--git-export=%s" % commit]
-    if force_native or is_native_pkg(repo):
+            "--git-export=%s" % commit,
+            "--git-upstream-branch=%s" % upstream_branch,
+            "--git-upstream-tag=%s" % upstream_tag]
+    if force_native or is_native_pkg(repo, opts):
         args.extend(["--git-no-patch-export",
                      "--git-upstream-tree=%s" % commit])
     else:
@@ -73,14 +91,14 @@ def create_gbp_export_args(repo, commit, export_dir, spec, force_native=False):
 
     return args
 
-def export_sources(repo, commit, export_dir, spec):
+def export_sources(repo, commit, export_dir, spec, opts):
     """
     Export packaging files using git-buildpackage
     """
-    gbp_args = create_gbp_export_args(repo, commit, export_dir, spec)
+    gbp_args = create_gbp_export_args(repo, commit, export_dir, spec, opts)
     try:
         ret = gbp_build(gbp_args)
-        if ret and not is_native_pkg(repo):
+        if ret and not is_native_pkg(repo, opts):
             # Try falling back to old logic of one monolithic tarball
             msger.warning("Generating upstream tarball and/or generating "\
                           "patches failed. GBS tried this as you have "\
@@ -88,12 +106,12 @@ def export_sources(repo, commit, export_dir, spec):
                           "mode introduced in GBS v0.10. "\
                           "Consider fixing the problem by either:\n"\
                           "  1. Update your upstream branch and/or fix the "\
-                          "spec file\n"\
+                          "spec file. Also, check the upstream tag format.\n"\
                           "  2. Remove or rename the upstream branch")
             msger.info("Falling back to the old method of generating one "\
                        "monolithic source archive")
             gbp_args = create_gbp_export_args(repo, commit, export_dir,
-                                              spec, force_native=True)
+                                              spec, opts, force_native=True)
             ret = gbp_build(gbp_args)
         if ret:
             msger.error("Failed to get export packaging files from git tree")
@@ -149,7 +167,7 @@ def do(opts, args):
         else:
             commit = 'HEAD'
         relative_spec = specfile.replace('%s/' % workdir, '')
-        export_sources(repo, commit, export_dir, relative_spec)
+        export_sources(repo, commit, export_dir, relative_spec, opts)
 
     try:
         spec = rpm.parse_spec(os.path.join(export_dir,
index a8e5b16..ee49cdb 100644 (file)
@@ -197,7 +197,7 @@ def do(opts, args):
         else:
             commit = 'HEAD'
         relative_spec = specfile.replace('%s/' % workdir, '')
-        export_sources(repo, commit, exportdir, relative_spec)
+        export_sources(repo, commit, exportdir, relative_spec, opts)
 
     try:
         commit_msg = repo.get_commit_info(opts.commit or 'HEAD')['subject']
index f186459..3199608 100644 (file)
@@ -161,6 +161,8 @@ class ConfigMgr(object):
             'general': {
                 'tmpdir': '/var/tmp',
                 'editor': '',
+                'upstream_branch': 'upstream',
+                'upstream_tag': 'upstream/%(upstreamversion)s',
             },
             'remotebuild': {
                 'build_server': 'https://api.tizen.org',
index 3ac0621..58980b4 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -152,6 +152,14 @@ class Gbs(cmdln.Cmdln):
                   default=False,
                   dest='source_rpm',
                   help='generate source rpm')
+    @cmdln.option('--upstream-branch',
+                  default=None,
+                  dest='upstream_branch',
+                  help='Upstream branch')
+    @cmdln.option('--upstream-tag',
+                  default=None,
+                  dest='upstream_tag',
+                  help="Upstream tag format, e.g. 'v%(upstreamversion)s'")
     def do_export(self, _subcmd, opts, *args):
         """${cmd_name}: export files and prepare for build
 
@@ -232,6 +240,14 @@ class Gbs(cmdln.Cmdln):
                   default=None,
                   dest='out',
                   help='output directory for RPMs')
+    @cmdln.option('--upstream-branch',
+                  default=None,
+                  dest='upstream_branch',
+                  help='Upstream branch')
+    @cmdln.option('--upstream-tag',
+                  default=None,
+                  dest='upstream_tag',
+                  help="Upstream tag format, e.g. 'v%(upstreamversion)s'")
     def do_build(self, _subcmd, opts, *args):
         """${cmd_name}: local build package
 
@@ -321,6 +337,14 @@ class Gbs(cmdln.Cmdln):
                   dest='include_all',
                   help='uncommitted changes and untracked files will be '\
                        'included while generating tar ball')
+    @cmdln.option('--upstream-branch',
+                  default=None,
+                  dest='upstream_branch',
+                  help='Upstream branch')
+    @cmdln.option('--upstream-tag',
+                  default=None,
+                  dest='upstream_tag',
+                  help="Upstream tag format, e.g. 'v%(upstreamversion)s'")
     def do_remotebuild(self, subcmd, opts, *args):
         """${cmd_name}: remote build package