def git_archive_build_origs(repo, source, output_dir, options): """ Build orig tarball(s) using git-archive @param source: the source of the package we're acting on @type source: L{DebianSource} @param output_dir: where to put the tarball @type output_dir: C{Str} @param options: the parsed options @type options: C{dict} of options """ comp = Compressor(options.comp_type, options.comp_level) upstream_tree = git_archive_get_upstream_tree(repo, source, options) gbp.log.info("Creating %s from '%s'" % (source.upstream_tarball_name(comp.type), upstream_tree)) gbp.log.debug("Building upstream tarball with compression %s" % comp) tree = repo.tree_drop_dirs(upstream_tree, options.components) if options.components else upstream_tree repo.create_upstream_tarball_via_git_archive(source, output_dir, tree, comp, options.with_submodules) for component in options.components: subtree = repo.tree_get_dir(upstream_tree, component) if not subtree: raise GbpError("No tree for '%s' found in '%s' to create additional tarball from" % (component, upstream_tree)) gbp.log.info("Creating additional tarball '%s' from '%s'" % (source.upstream_tarball_name(options.comp_type, component=component), subtree)) repo.create_upstream_tarball_via_git_archive(source, output_dir, subtree, comp, options.with_submodules, component=component)
def test_create_tarballs(): """Create an upstream tarball""" class MockedSource: def __init__(self, version): self.name = 'test' self.upstream_version = version def upstream_tarball_name(self, compression, component=None): return Policy.build_tarball_name(self.name, self.upstream_version, compression=compression) comp = Compressor('bzip2') # Tarball with submodules s = MockedSource('0.1') ok_( REPO.create_upstream_tarball_via_git_archive(s, str(TMPDIR), "HEAD", comp, with_submodules=True)) # Tarball without submodules s = MockedSource('0.2') ok_( REPO.create_upstream_tarball_via_git_archive(s, str(TMPDIR), "HEAD", comp, with_submodules=False))
def git_archive_build_orig(repo, spec, output_dir, options): """ Build orig tarball using git-archive @param repo: our git repository @type repo: L{RpmGitRepository} @param spec: spec file of the package @type spec: L{SpecFile} @param output_dir: where to put the tarball @type output_dir: C{Str} @param options: the parsed options @type options: C{dict} of options @return: the tree we built the tarball from @rtype: C{str} """ comp = None try: orig_prefix = spec.orig_src['prefix'] upstream_tree = get_upstream_tree(repo, spec.upstreamversion, options) gbp.log.info("%s does not exist, creating from '%s'" % (spec.orig_src['filename'], upstream_tree)) if spec.orig_src['compression']: comp = Compressor(spec.orig_src['compression'], options.comp_level) gbp.log.debug("Building upstream tarball with compression %s" % comp) if not git_archive(repo, spec, output_dir, upstream_tree, orig_prefix, comp, options.with_submodules): raise GbpError("Cannot create upstream tarball at '%s'" % output_dir) except (GitRepositoryError, GbpError) as err: raise GbpAutoGenerateError(str(err)) return upstream_tree
def pristine_tar_build_origs(repo, source, output_dir, options): """ Build orig tarball using pristine-tar @returns: C{True} if tarball was build, C{False} otherwise """ if not options.pristine_tar: return False if not repo.has_branch(repo.pristine_tar_branch): gbp.log.warn('Pristine-tar branch "%s" not found' % repo.pristine_tar.branch) comp = Compressor(options.comp_type) pristine_tar_prepare_orig_tree(repo, source, options) try: repo.create_upstream_tarball_via_pristine_tar(source, output_dir, comp) for component in options.components: repo.create_upstream_tarball_via_pristine_tar(source, output_dir, comp, component=component) return True except GitRepositoryError: if hasattr(options, 'pristine_tar_commit') and options.pristine_tar_commit: gbp.log.debug("pristine-tar checkout failed, will commit tarball " "due to '--pristine-tar-commit'") else: raise return False
def main(argv): """Entry point for gbp-buildpackage-rpm""" retval = 0 prefix = "git-" spec = None options, gbp_args, builder_args = parse_args(argv, prefix) if not options: return ExitCodes.parse_error try: repo = RpmGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 # Determine tree-ish to be exported try: tree = get_tree(repo, options.export) except GbpError as err: gbp.log.err('Failed to determine export treeish: %s' % err) return 1 # Re-parse config options with using the per-tree config file(s) from the # exported tree-ish options, gbp_args, builder_args = parse_args(argv, prefix, tree) branch = get_current_branch(repo) try: init_tmpdir(options.tmp_dir, prefix='buildpackage-rpm_') tree = get_tree(repo, options.export) spec = parse_spec(options, repo, treeish=tree) Command(options.cleaner, shell=True)() if not options.ignore_new: ret, out = repo.is_clean() if not ret: gbp.log.err( "You have uncommitted changes in your source tree:") gbp.log.err(out) raise GbpError("Use --git-ignore-new to ignore.") if not options.ignore_new and not options.ignore_branch: if branch != options.packaging_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.packaging_branch, branch)) raise GbpError( "Use --git-ignore-branch to ignore or " "--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): raise GbpError # Re-parse spec from dump dir to get version etc. spec = rpm.SpecFile(os.path.join(dump_dir, spec.specfile)) if not options.tag_only: # Setup builder opts setup_builder(options, builder_args) if options.use_mock: setup_mock(options) # Prepare final export dirs export_dir = makedir(options.export_dir) source_dir = makedir( os.path.join(export_dir, options.export_sourcedir)) spec_dir = makedir(os.path.join(export_dir, options.export_specdir)) # Move packaging files to final export dir gbp.log.debug("Exporting packaging files from '%s' to '%s'" % (dump_dir, export_dir)) for fname in os.listdir(dump_dir): src = os.path.join(dump_dir, fname) if fname == spec.specfile: dst = os.path.join(spec_dir, fname) else: dst = os.path.join(source_dir, fname) try: shutil.copy2(src, dst) except IOError as err: raise GbpError("Error exporting packaging files: %s" % err) spec.specdir = os.path.abspath(spec_dir) # Get/build the orig tarball if is_native(repo, options): if spec.orig_src and not options.no_create_orig: # Just build source archive from the exported tree gbp.log.info( "Creating (native) source archive %s from '%s'" % (spec.orig_src['filename'], tree)) comp = None if spec.orig_src['compression']: comp = Compressor(spec.orig_src['compression'], options.comp_level) gbp.log.debug("Building source archive with " "compression '%s" % comp) orig_prefix = spec.orig_src['prefix'] if not git_archive(repo, spec, source_dir, tree, orig_prefix, comp, options.with_submodules): raise GbpError("Cannot create source tarball at '%s'" % source_dir) # Non-native packages: create orig tarball from upstream elif spec.orig_src: prepare_upstream_tarball(repo, spec, options, source_dir) # Run postexport hook if options.postexport: RunAtCommand(options.postexport, shell=True, extra_env={ 'GBP_GIT_DIR': repo.git_dir, 'GBP_TMP_DIR': export_dir })(dir=export_dir) # Do actual build if not options.no_build and not options.tag_only: if options.prebuild: RunAtCommand(options.prebuild, shell=True, extra_env={ 'GBP_GIT_DIR': repo.git_dir, 'GBP_BUILD_DIR': export_dir })(dir=export_dir) # Finally build the package: if options.builder.startswith("rpmbuild"): builder_args.append( os.path.join(spec.specdir, spec.specfile)) else: builder_args.append(spec.specfile) RunAtCommand(options.builder, [pipes.quote(arg) for arg in builder_args], shell=True, extra_env={'GBP_BUILD_DIR': export_dir})(dir=export_dir) if options.postbuild: changes = os.path.abspath("%s/%s.changes" % (source_dir, spec.name)) gbp.log.debug("Looking for changes file %s" % changes) Command(options.postbuild, shell=True, extra_env={ 'GBP_CHANGES_FILE': changes, 'GBP_BUILD_DIR': export_dir })() # Tag (note: tags the exported version) if options.tag or options.tag_only: gbp.log.info("Tagging %s" % rpm.compose_version_str(spec.version)) tag = create_packaging_tag(repo, tree, spec.name, spec.version, options) vcs_info = get_vcs_info(repo, tag) if options.posttag: sha = repo.rev_parse("%s^{}" % tag) Command(options.posttag, shell=True, extra_env={ 'GBP_TAG': tag, 'GBP_BRANCH': branch, 'GBP_SHA1': sha })() else: vcs_info = get_vcs_info(repo, tree) # Put 'VCS:' tag to .spec spec.set_tag('VCS', None, format_str(options.spec_vcs_tag, vcs_info)) spec.write_spec_file() except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except GitRepositoryError as err: gbp.log.err("Git command failed: %s" % err) retval = 1 except GbpAutoGenerateError as err: if len(err.__str__()): gbp.log.err(err) retval = 2 except GbpError as err: if len(err.__str__()): gbp.log.err(err) retval = 1 finally: drop_index(repo) del_tmpdir() if not options.tag_only: if spec: summary = "Gbp-rpm %s" % ["failed", "successful"][not retval] message = ("Build of %s %s %s" % (spec.name, rpm.compose_version_str( spec.version), ["failed", "succeeded"][not retval])) if not gbp.notifications.notify(summary, message, options.notify): gbp.log.err("Failed to send notification") retval = 1 return retval