From: wanchao-xu Date: Fri, 19 Apr 2024 05:31:56 +0000 (+0800) Subject: buildpackage_rpm: support '--git-pq-branch', '--git-rpmbuild-builddir', '--git-rpmbui... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=359a5929686933e0614010acd5fadd70e493e14c;p=tools%2Fgit-buildpackage.git buildpackage_rpm: support '--git-pq-branch', '--git-rpmbuild-builddir', '--git-rpmbuild-buidrootdir', '--git-rpmbuild-rpmdir', '--git-rpmbuild-srpmdir', '--git-patch-export', '--git-patch-export-rev', '--git-patch-export-compress', '--git-patch-export-ignore-path', '--git-patch-export-squash-until' and '--git-patch-numbers' options. Change-Id: I0b835c0c9a3af2a9ba2e016984399c8cc91d7d01 Signed-off-by: wanchao-xu --- diff --git a/docs/manpages/gbp-buildpackage-rpm.xml b/docs/manpages/gbp-buildpackage-rpm.xml index 978cd8fd..aaebe548 100644 --- a/docs/manpages/gbp-buildpackage-rpm.xml +++ b/docs/manpages/gbp-buildpackage-rpm.xml @@ -29,6 +29,7 @@ [auto|on|off] TREEISH BRANCH_NAME + BRANCH_NAME BUILD_CMD @@ -50,6 +51,10 @@ DIRECTORY LEVEL DIRECTORY + =DIRECTORY + =DIRECTORY + =DIRECTORY + =DIRECTORY TREEISH DIRECTORY FILEPATH @@ -64,6 +69,12 @@ =ARCHITECTURE =OPTIONS =ROOT + + TREEISH + THRESHOLD + REGEX + COMMITISH + =TAG_FORMAT @@ -268,6 +279,28 @@ + + =BRANCH_NAME + + + + Name (format string) of the patch-queue/development branch. This + makes building easier when working with separate packaging and + development branches. + + + If is enabled and + &gbp-buildpackage-rpm; detects that the current branch has a + patch-queue/development branch it exports the patches from there + instead of the tip of the current branch (unless + is defined, of course). + Similarly, if the current branch is a patch-queue/development branch + &gbp-buildpackage-rpm; will automatically enable patch-export and + export packaging files from the packaging branch instead of the + current branch (unless ) is defined. + + + @@ -454,6 +487,21 @@ + + =DIRECTORY + + =DIRECTORY + + =DIRECTORY + + =DIRECTORY + + + + Build subdirectory options for rpmbuild builder. + + + =DIRECTORY @@ -628,6 +676,81 @@ + + + + + + Create patches from the commits between the upstream version and + export-treeish. That is, after exporting packaging files (from the + pacakging directory) &gbp-buildpackage-rpm; creates one patch per + commit (similar to git-format-patch) and updates the spec file in the + export dir. You use to + specify the tip commit of the patch series. + + + + + TREEISH + + + + Use TREEISH as the tip commit of the patch + series instead of the default - i.e. treeish from which the packaging + files are exported (which is defined with + . + + + + + THRESHOLD + + + + Compress (auto-generated) patches larger than given + THRESHOLD bytes. Special value 0 disabled + patch compression. + + + + + REGEX + + + + Exclude changes to path(s) matching REGEX + in patch generation. + + + + + COMMITISH + + + + Squash commits up to the given COMMITISH + into one monolitic diff. Could be used if one wants to squash commits + from an upstream release up to a stable update into a single diff + (commits on top of the stable would generate one patch per commit as + usual). The format is '<commit_ish>[:<filename_base>]', + i.e. commitish optionally followed by a colon and the desired + filename base for the diff (suffix '.diff' is automatically added by + &gbp-buildpackage-rpm;). Magic word 'HEAD' translates to the + patch-export-treeish when given as the squash-point. This allows one + to configure gbp to always squash all commits into one monolithic + diff. + + + + + + + + + Whether the patch files should start with a number or not. + + + =TAG_FORMAT diff --git a/gbp/config.py b/gbp/config.py index 1b0d991a..23981712 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -816,6 +816,11 @@ class GbpOptionParserRpm(GbpOptionParser): 'packaging-tag': '%(vendor)s/%(version)s', 'pq-branch': 'development/%(branch)s', 'import-files': ['.gbp.conf', 'debian/gbp.conf'], + 'rpmbuild-builddir': 'BUILD', + 'rpmbuild-rpmdir': 'RPMS', + 'rpmbuild-srpmdir': 'SRPMS', + 'rpmbuild-buildrootdir': 'BUILDROOT', + 'patch-export': 'False', 'patch-export-ignore-path': '', 'patch-export-compress': '0', 'patch-export-squash-until': '', @@ -868,6 +873,9 @@ class GbpOptionParserRpm(GbpOptionParser): 'spec-file': "Spec file to use, causes the packaging-dir option to be " "ignored, default is '%(spec-file)s'", + 'patch-export': + "Create patches between upstream and export-treeish, default " + "is '%(patch-export)s'", 'patch-export-compress': "Compress (auto-generated) patches larger than given number of " "bytes, 0 never compresses, default is " diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py index 30f27f67..4d9f9da0 100644 --- a/gbp/scripts/buildpackage_rpm.py +++ b/gbp/scripts/buildpackage_rpm.py @@ -37,7 +37,8 @@ from gbp.tmpfile import init_tmpdir, del_tmpdir, tempfile from gbp.scripts.common import ExitCodes from gbp.scripts.common.buildpackage import (index_name, wc_name, dump_tree, write_wc, drop_index) -from gbp.scripts.pq_rpm import parse_spec +from gbp.scripts.pq_rpm import update_patch_series, parse_spec +from gbp.scripts.common.pq import is_pq_branch, pq_branch_name, pq_branch_base class GbpAutoGenerateError(GbpError): @@ -130,7 +131,7 @@ def get_upstream_tree(repo, version, options): """Determine the upstream tree from the given options""" if options.upstream_tree.upper() == 'TAG': tag_str_fields = {'upstreamversion': version, - 'version': version} + 'vendor': 'Upstream'} upstream_tree = repo.version_to_tag(options.upstream_tag, tag_str_fields) elif options.upstream_tree.upper() == 'BRANCH': @@ -192,6 +193,45 @@ def get_vcs_info(repo, treeish): return info +def guess_export_params(repo, options): + """Get commit and tree from where to export packaging and patches""" + tree = None + branch = None + if options.export in [wc_name, index_name, 'HEAD']: + branch = get_current_branch(repo) + elif options.export in repo.get_local_branches(): + branch = options.export + if branch: + if is_pq_branch(branch, options): + packaging_branch = pq_branch_base(branch, options) + if repo.has_branch(packaging_branch): + gbp.log.info("It seems you're building a development/patch-" + "queue branch. Export target changed to '%s' and " + "patch-export enabled!" % packaging_branch) + options.patch_export = True + if not options.patch_export_rev: + options.patch_export_rev = options.export + options.export = packaging_branch + else: + gbp.log.warn("It seems you're building a development/patch-" + "queue branch. No corresponding packaging branch " + "found. Build may fail!") + elif options.patch_export and not options.patch_export_rev: + tree = get_tree(repo, options.export) + spec = parse_spec(options, repo, treeish=tree) + pq_branch = pq_branch_name(branch, options, spec.version) + if repo.has_branch(pq_branch): + gbp.log.info("Exporting patches from development/patch-queue " + "branch '%s'" % pq_branch) + options.patch_export_rev = pq_branch + if tree is None: + tree = get_tree(repo, options.export) + spec = parse_spec(options, repo, treeish=tree) + + # Return tree-ish object and relative spec path for for exporting packaging + return tree, spec.specpath + + def git_archive_build_orig(repo, spec, output_dir, options): """ Build orig tarball using git-archive @@ -226,6 +266,17 @@ def git_archive_build_orig(repo, spec, output_dir, options): return upstream_tree +def export_patches(repo, spec, export_treeish, options): + """ + Generate patches and update spec file + """ + try: + upstream_tree = get_upstream_tree(repo, spec.upstreamversion, options) + update_patch_series(repo, spec, upstream_tree, export_treeish, options) + except (GitRepositoryError, GbpError) as err: + raise GbpAutoGenerateError(str(err)) + + def is_native(repo, options): """Determine whether a package is native or non-native""" if options.native.is_auto(): @@ -250,8 +301,16 @@ def setup_builder(options, builder_args): builder_args.append('-ba') builder_args.extend([ '--define', "_topdir %s" % os.path.abspath(options.export_dir), + '--define', "_builddir %%_topdir/%s" % options.build_dir, + '--define', "_rpmdir %%_topdir/%s" % options.rpm_dir, + '--define', "_srcrpmdir %%_topdir/%s" % options.srpm_dir, + '--define', "_buildrootdir %%_topdir/%s" % options.buildroot_dir, '--define', "_specdir %%_topdir/%s" % options.export_specdir, '--define', "_sourcedir %%_topdir/%s" % options.export_sourcedir]) + elif options.builder.startswith('osc'): + builder_args.insert(0, 'build') + options.source_dir = '' + options.spec_dir = '' def packaging_tag_data(repo, commit, name, version, options): @@ -382,6 +441,7 @@ def build_parser(name, prefix=None, git_treeish=None): dest="upstream_branch") branch_group.add_config_file_option(option_name="packaging-branch", dest="packaging_branch") + branch_group.add_config_file_option(option_name="pq-branch", dest="pq_branch") branch_group.add_boolean_config_file_option(option_name="ignore-branch", dest="ignore_branch") branch_group.add_boolean_config_file_option(option_name="submodules", @@ -422,6 +482,26 @@ def build_parser(name, prefix=None, git_treeish=None): dest="export_dir", type="path", help="Build topdir, also export the sources under " "EXPORT_DIR, default is '%(export-dir)s'") + export_group.add_config_file_option(option_name="rpmbuild-builddir", + dest="build_dir", type="path", + help="subdir where package is built (under " + "EXPORT_DIR), i.e. rpmbuild builddir, default is " + "'%(rpmbuild-builddir)s'") + export_group.add_config_file_option(option_name="rpmbuild-rpmdir", + dest="rpm_dir", type="path", + help="subdir where ready binary packages are stored " + "(under EXPORT_DIR), i.e. rpmbuild builddir, default " + "is '%(rpmbuild-rpmdir)s'") + export_group.add_config_file_option(option_name="rpmbuild-srpmdir", + dest="srpm_dir", type="path", + help="subdir where ready sources package is stored " + "(under EXPORT_DIR), i.e. rpmbuild srpmdir, default " + "is '%(rpmbuild-srpmdir)s'") + export_group.add_config_file_option(option_name="rpmbuild-buildrootdir", + dest="buildroot_dir", type="path", + help="subdir for build-time alternative root (under " + "EXPORT_DIR), i.e. rpmbuild buildrootdir, default is " + "'%(rpmbuild-buildrootdir)s'") export_group.add_config_file_option(option_name="export-specdir", dest="export_specdir", type="path") export_group.add_config_file_option(option_name="export-sourcedir", @@ -434,6 +514,17 @@ def build_parser(name, prefix=None, git_treeish=None): dest="packaging_dir") export_group.add_config_file_option(option_name="spec-file", dest="spec_file") + export_group.add_boolean_config_file_option("patch-export", dest="patch_export") + export_group.add_option("--git-patch-export-rev", dest="patch_export_rev", + metavar="TREEISH", + help="[experimental] Export patches from treeish object TREEISH") + export_group.add_config_file_option("patch-export-ignore-path", + dest="patch_export_ignore_path") + export_group.add_config_file_option("patch-export-compress", dest="patch_export_compress") + export_group.add_config_file_option("patch-export-squash-until", + dest="patch_export_squash_until") + export_group.add_boolean_config_file_option(option_name="patch-numbers", + dest="patch_numbers") export_group.add_config_file_option("spec-vcs-tag", dest="spec_vcs_tag") return parser @@ -496,9 +587,7 @@ def main(argv): try: init_tmpdir(options.tmp_dir, prefix='buildpackage-rpm_') - - tree = get_tree(repo, options.export) - spec = parse_spec(options, repo, treeish=tree) + tree, relative_spec_path = guess_export_params(repo, options) Command(options.cleaner, shell=True)() if not options.ignore_new: @@ -516,13 +605,12 @@ def main(argv): "--git-packaging-branch to set the branch name.") # Dump from git to a temporary directory: - packaging_tree = '%s:%s' % (tree, options.packaging_dir) - dump_dir = tempfile.mkdtemp(prefix='packaging_') - gbp.log.debug("Dumping packaging files to '%s'" % dump_dir) - if not dump_tree(repo, dump_dir, packaging_tree, False, False): + dump_dir = tempfile.mkdtemp(prefix='dump_tree_') + gbp.log.debug("Dumping tree '%s' to '%s'" % (options.export, dump_dir)) + if not dump_tree(repo, dump_dir, tree, options.with_submodules): raise GbpError - # Re-parse spec from dump dir to get version etc. - spec = rpm.SpecFile(os.path.join(dump_dir, spec.specfile)) + # Parse spec from dump dir to get version etc. + spec = rpm.SpecFile(os.path.join(dump_dir, relative_spec_path)) if not options.tag_only: # Setup builder opts @@ -530,6 +618,14 @@ def main(argv): if options.use_mock: setup_mock(options) + # Generate patches, if requested + if options.patch_export and not is_native(repo, options): + if options.patch_export_rev: + patch_tree = get_tree(repo, options.patch_export_rev) + else: + patch_tree = tree + export_patches(repo, spec, patch_tree, options) + # Prepare final export dirs export_dir = makedir(options.export_dir) source_dir = makedir(os.path.join(export_dir, @@ -555,7 +651,7 @@ def main(argv): try: shutil.copy2(src, dst) except IOError as err: - raise GbpError("Error exporting packaging files: %s" % err) + raise GbpError("Error exporting files: %s" % err) spec.specdir = os.path.abspath(spec_dir) # Get/build the orig tarball