Enable patch-generation
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 17 Aug 2012 10:03:55 +0000 (13:03 +0300)
committerZhang Qiang <qiang.z.zhang@intel.com>
Sat, 8 Sep 2012 06:49:19 +0000 (14:49 +0800)
This commit enables the "proper" maintenance model of packages. That is,
create a real upstream source archive (matching the upstream tag) and
patches on top of that. It facilitates the patch compression support in
git-buildpackage: patches bigger that 100kB are compressed with gzip.
GBP also modifies the spec file to contain the new list of patches.

GBS enables this mode if the git tree has 'upstream' branch. It tries to
checkout the orig tarball with pristine-tar, if 'pristine-tar'
branch is found. If this fails, it tries to create the orig tarball from
a git tag corresponding the upstream version.

GBS falls back to the old method of generating one monolithic tarball if
exporting of packaging files (i.e. upstream archive and patch
generation) in this new mode fails.

NOTE: .spec file autoupdate feature is limited and might not work with
more exotic packaging. E.g. patches inside conditionals are not
supported, at the moment.

TODO: Currently, also packaging-only commits generate patches which is
only noise from source code perspective. This needs to be fixed in
git-buildpackage.

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

index 149bc54..5b140e3 100644 (file)
@@ -31,7 +31,7 @@ import pwd
 from gitbuildsys import msger, utils, runner, errors
 from gitbuildsys.conf import configmgr
 from gitbuildsys.safe_url import SafeURL
-from gitbuildsys.cmd_export import create_gbp_export_args
+from gitbuildsys.cmd_export import export_sources
 
 from gbp.scripts.buildpackage_rpm import main as gbp_build
 from gbp.rpm.git import GitRepositoryError, RpmGitRepository
@@ -363,12 +363,7 @@ def do(opts, args):
             commit = 'HEAD'
         relative_spec = specfile.replace('%s/' % workdir, '')
         msger.info('export tar ball and packaging files ... ')
-        gbp_args = create_gbp_export_args(commit, export_dir, relative_spec)
-        try:
-            if gbp_build(gbp_args):
-                msger.error("Failed to get packaging info from git tree")
-        except GitRepositoryError, excobj:
-            msger.error("Repository error: %s" % excobj)
+        export_sources(repo, commit, export_dir, relative_spec)
 
     # Parse spec file
     try:
index b14050f..8622a26 100644 (file)
@@ -44,17 +44,63 @@ def mkdir_p(path):
         else:
             raise
 
-def create_gbp_export_args(commit, export_dir, spec):
+def is_native_pkg(repo):
+    """
+    Determine if the package is "native"
+    """
+    return not repo.has_branch("upstream")
+
+def create_gbp_export_args(repo, commit, export_dir, spec, force_native=False):
+    """
+    Construct the cmdline argument list for git-buildpackage export
+    """
     args = ["argv[0] placeholder", "--git-export-only",
             "--git-ignore-new", "--git-builder=osc",
-            "--git-no-patch-export",
-            "--git-upstream-tree=%s" % commit,
+            "--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):
+        args.extend(["--git-no-patch-export",
+                     "--git-upstream-tree=%s" % commit])
+    else:
+        args.extend(["--git-patch-export",
+                     "--git-patch-export-compress=100k",
+                     "--git-force-create",])
+        if repo.has_branch("pristine-tar"):
+            args.extend(["--git-pristine-tar"])
+
     return args
 
+def export_sources(repo, commit, export_dir, spec):
+    """
+    Export packaging files using git-buildpackage
+    """
+    gbp_args = create_gbp_export_args(repo, commit, export_dir, spec)
+    try:
+        ret = gbp_build(gbp_args)
+        if ret and not is_native_pkg(repo):
+            # 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 "\
+                          "upstream branch in you git tree. This is a new "\
+                          "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"\
+                          "  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)
+            ret = gbp_build(gbp_args)
+        if ret:
+            msger.error("Failed to get export packaging files from git tree")
+    except GitRepositoryError, excobj:
+        msger.error("Repository error: %s" % excobj)
+
+
 def do(opts, args):
     """
     The main plugin call
@@ -103,12 +149,7 @@ def do(opts, args):
         else:
             commit = 'HEAD'
         relative_spec = specfile.replace('%s/' % workdir, '')
-        gbp_args = create_gbp_export_args(commit, export_dir, relative_spec)
-        try:
-            if gbp_build(gbp_args):
-                msger.error("Failed to get packaging info from git tree")
-        except GitRepositoryError, excobj:
-            msger.error("Repository error: %s" % excobj)
+        export_sources(repo, commit, export_dir, relative_spec)
 
     try:
         spec = rpm.parse_spec(os.path.join(export_dir,
index 558fb64..a8e5b16 100644 (file)
@@ -26,7 +26,7 @@ from gitbuildsys import msger, errors, utils
 
 from gitbuildsys.conf import configmgr
 from gitbuildsys.oscapi import OSC, OSCError
-from gitbuildsys.cmd_export import create_gbp_export_args
+from gitbuildsys.cmd_export import export_sources
 
 import gbp.rpm
 from gbp.scripts.buildpackage_rpm import main as gbp_build
@@ -197,12 +197,7 @@ def do(opts, args):
         else:
             commit = 'HEAD'
         relative_spec = specfile.replace('%s/' % workdir, '')
-        gbp_args = create_gbp_export_args(commit, exportdir, relative_spec)
-        try:
-            if gbp_build(gbp_args):
-                msger.error("Failed to get packaging info from git tree")
-        except GitRepositoryError, excobj:
-            msger.error("Repository error: %s" % excobj)
+        export_sources(repo, commit, exportdir, relative_spec)
 
     try:
         commit_msg = repo.get_commit_info(opts.commit or 'HEAD')['subject']