Implement 'fallback-to-native' option
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 29 Sep 2014 09:32:42 +0000 (12:32 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 29 Sep 2014 09:32:42 +0000 (12:32 +0300)
Add a new '--fallback-to-native' command line option and a corresponding
'fallback_to_native' configuration option. This option re-introducs the
old behaviour (removed in v0.17) of falling back to to native packaging
mode if upstream tarball or patch generation fails. That is gbs will
simply create the source tarball from the exported commit (instead of
upstream tag or pristine-tar) and doesn't generate any patches.

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

index 63022ee..537a129 100644 (file)
@@ -355,6 +355,8 @@ def main(args):
         cmd += ['--upstream-branch=%s' % args.upstream_branch]
     if args.upstream_tag:
         cmd += ['--upstream-tag=%s' % args.upstream_tag]
+    if args.fallback_to_native:
+        cmd += ['--fallback-to-native']
     if args.squash_patches_until:
         cmd += ['--squash-patches-until=%s' % args.squash_patches_until]
     if args.no_patch_export:
index 1094c0b..7fc771e 100644 (file)
@@ -49,6 +49,14 @@ def mkdir_p(path):
         else:
             raise GbsError('failed to create %s: %s' % (path, exc.strerror))
 
+def config_is_true(config_value):
+    """Return if a config value is true"""
+    if isinstance(config_value, bool):
+        return config_value
+    if config_value.lower() in ['yes', 'on', '1', 'true', 'enabled']:
+        return True
+    return False
+
 def is_native_pkg(repo, args):
     """
     Determine if the package is "native"
@@ -208,8 +216,7 @@ def export_sources(repo, commit, export_dir, spec, args, create_tarball=True):
     try:
         ret = gbp_build(gbp_args)
         if ret == 2 and not is_native_pkg(repo, args):
-            # Try falling back to old logic of one monolithic tarball
-            log.error("Generating upstream tarball and/or generating patches "
+            errmsg = ("Generating upstream tarball and/or generating patches "
                       "failed. GBS tried this as you have upstream branch in "
                       "you git tree. Fix the problem by either:\n"
                       "  1. Update your upstream branch and/or fix the spec "
@@ -218,6 +225,19 @@ def export_sources(repo, commit, export_dir, spec, args, create_tarball=True):
                       "package to native)\n"
                       "See https://source.tizen.org/documentation/reference/"
                       "git-build-system/upstream-package for more details.")
+            fallback = configmgr.get_arg_conf(args, 'fallback_to_native')
+            if config_is_true(fallback):
+                # Try falling back to old logic of one monolithic tarball
+                log.warn(errmsg)
+                log.info("Falling back to native, i.e. creating source archive "
+                         "directly from exported commit, without any patches.")
+                gbp_args = create_gbp_export_args(repo, commit, export_dir,
+                                                  tmp.path, spec, args,
+                                                  force_native=True,
+                                                  create_tarball=create_tarball)
+                ret = gbp_build(gbp_args)
+            else:
+                log.error(errmsg)
         if ret:
             raise GbsError("Failed to export packaging files from git tree")
     except GitRepositoryError, excobj:
index 95600eb..a63fce6 100644 (file)
@@ -183,6 +183,7 @@ class ConfigMgr(object):
                 'buildroot':    '~/GBS-ROOT/',
                 'packaging_dir': 'packaging',
                 'work_dir': '.',
+                'fallback_to_native': '',
             },
             'orphan-devel': {
                 'packaging_branch': '',
index e3bf0f4..1cd94c7 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -107,6 +107,12 @@ def export_parser(parser):
     parser.add_argument('--include-all', action='store_true',
                         help='uncommitted changes and untracked files '
                         'would be included while generating tar ball')
+    parser.add_argument('--fallback-to-native', action='store_true',
+                        default=None,
+                        help='Fall back to native packaging mode (i.e. create '
+                        'tarball directly from exported commit, not from '
+                        'upstream tag, and without patches) in case patch '
+                        'or upstream tarball generation fails.')
     parser.add_argument('--source-rpm', action='store_true',
                         help='generate source rpm')
     parser.add_argument('--no-patch-export', action='store_true',
@@ -239,6 +245,12 @@ def build_parser(parser):
                         help="upstream tag format, '${upstreamversion}' is "
                         "expanded to the version in the spec file. "
                         "E.g. 'v${upstreamversion}'")
+    group.add_argument('--fallback-to-native', action='store_true',
+                       default=None,
+                       help='Fall back to native packaging mode (i.e. create '
+                       'tarball directly from exported commit, not from '
+                       'upstream tag, and without patches) in case patch '
+                       'or upstream tarball generation fails.')
     group.add_argument('--squash-patches-until',
                         help='when generating patches, squash patches up '
                         'to given commit-ish into one monolithic diff file. '
@@ -349,6 +361,12 @@ def remotebuild_parser(parser):
     parser.add_argument('--include-all', action='store_true',
                         help='uncommitted changes and untracked files will be '
                         'included while generating tar ball')
+    parser.add_argument('--fallback-to-native', action='store_true',
+                        default=None,
+                        help='Fall back to native packaging mode (i.e. create '
+                        'tarball directly from exported commit, not from '
+                        'upstream tag, and without patches) in case patch '
+                        'or upstream tarball generation fails.')
     parser.add_argument('--upstream-branch', help='upstream branch')
     parser.add_argument('--upstream-tag',
                         help="upstream tag format, '${upstreamversion}' is "