def main(argv): retval = 0 source = None options, args = parse_args(argv, '') if args or not options: return ExitCodes.parse_error try: repo = DebianGitRepository(os.path.curdir, toplevel=False) except GitRepositoryError: gbp.log.err("%s is not inside a git repository" % (os.path.abspath('.'))) return 1 try: try: source = DebianSource(repo.path) source.is_native() except Exception as e: raise GbpError("Can't determine package type: %s" % e) if options.tarball_dir and source.upstream_version is not None: options.tarball_dir = PkgPolicy.version_subst(options.tarball_dir, source.upstream_version) output_dir = options.tarball_dir or os.path.join(repo.path, '..') if source.is_native(): gbp.log.info("Nothing to be done for native package") return 0 prepare_upstream_tarballs(repo, source, options, output_dir, output_dir) except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if str(err): gbp.log.err(err) retval = 1 except DebianSourceError as err: gbp.log.err(err) source = None retval = 1 return retval
def version_to_tag(cls, format, version): """Generate a tag from a given format and a version %(version)s provides a clean version that works as a git tag. %(hversion)s provides the same thing, but with '.' replaced with '-'. hversion is useful for upstreams with tagging policies that prohibit . characters. %(version%A%B)s provides %(version)s with string 'A' replaced by 'B'. This way, simple version mangling is possible via substitution. Inside the substition string, '%' needs to be escaped. See the examples below. >>> DebianGitRepository.version_to_tag("debian/%(version)s", "0:0~0") 'debian/0%0_0' >>> DebianGitRepository.version_to_tag("libfoo-%(hversion)s", "1.8.1") 'libfoo-1-8-1' >>> DebianGitRepository.version_to_tag("v%(version%.%_)s", "1.2.3") 'v1_2_3' >>> DebianGitRepository.version_to_tag(r'%(version%-%\\%)s', "0-1.2.3") '0%1.2.3' """ return PkgPolicy.version_subst(format, version, cls._sanitize_version)
def main(argv): retval = 0 prefix = "git-" source = None hook_env = {} options, gbp_args, dpkg_args = parse_args(argv, prefix) if not options: return ExitCodes.parse_error try: repo = DebianGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: clean_working_tree(options, repo) check_branch(repo, options) tree = maybe_write_tree(repo, options) source = source_vfs(repo, options, tree) check_tag(options, repo, source) if not options.tag_only: output_dir = prepare_output_dir(options.export_dir) tarball_dir = output_dir if options.tarball_dir and source.upstream_version is not None: tarball_dir = PkgPolicy.version_subst(options.tarball_dir, source.upstream_version) tmp_dir = os.path.join(output_dir, "%s-tmp" % source.sourcepkg) build_env, hook_env = setup_pbuilder(options, repo, source.is_native()) major = (source.debian_version if source.is_native() else source.upstream_version) export_dir = os.path.join(output_dir, "%s-%s" % (source.sourcepkg, major)) build_dir = export_dir if options.export_dir else repo.path changes_file = changes_file_name(source, build_dir, options.builder, dpkg_args) # Run preexport hook if options.export_dir and options.preexport: Hook('Preexport', options.preexport, extra_env=Hook.md(hook_env, {'GBP_GIT_DIR': repo.git_dir, 'GBP_BUILD_DIR': build_dir}) )() # Get/build the upstream tarball if necessary. We delay this in # case of a postexport hook so the hook gets a chance to modify the # sources and create different tarballs (#640382) # We don't delay it in general since we want to fail early if the # tarball is missing. if not source.is_native(): if options.postexport: gbp.log.info("Postexport hook set, delaying tarball creation") else: prepare_upstream_tarballs(repo, source, options, tarball_dir, output_dir) # Export to another build dir if requested: if options.export_dir: export_source(repo, tree, source, options, tmp_dir, tarball_dir) # Run postexport hook if options.postexport: Hook('Postexport', options.postexport, extra_env=Hook.md(hook_env, {'GBP_GIT_DIR': repo.git_dir, 'GBP_TMP_DIR': tmp_dir}) )(dir=tmp_dir) gbp.log.info("Moving '%s' to '%s'" % (tmp_dir, export_dir)) move_old_export(export_dir) os.rename(tmp_dir, export_dir) # Delayed tarball creation in case a postexport hook is used: if not source.is_native() and options.postexport: prepare_upstream_tarballs(repo, source, options, tarball_dir, output_dir) if options.prebuild: Hook('Prebuild', options.prebuild, extra_env=Hook.md(hook_env, {'GBP_GIT_DIR': repo.git_dir, 'GBP_BUILD_DIR': build_dir}) )(dir=build_dir) # Finally build the package: gbp.log.info("Performing the build") RunAtCommand(options.builder, [pipes.quote(arg) for arg in dpkg_args], shell=True, extra_env=Hook.md(build_env, {'GBP_BUILD_DIR': build_dir}) )(dir=build_dir) if options.postbuild: gbp.log.debug("Looking for changes file %s" % changes_file) Hook('Postbuild', options.postbuild, extra_env=Hook.md(hook_env, {'GBP_CHANGES_FILE': changes_file, 'GBP_BUILD_DIR': build_dir}) )() if options.tag or options.tag_only: perform_tagging(repo, source, options, hook_env) except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if str(err): gbp.log.err(err) retval = 1 except DebianSourceError as err: gbp.log.err(err) source = None retval = 1 finally: drop_index(repo) if not options.tag_only: if options.export_dir and options.purge and not retval: RemoveTree(export_dir)() if source: summary, msg = gbp.notifications.build_msg(source.changelog, not retval) if not gbp.notifications.notify(summary, msg, options.notify): gbp.log.err("Failed to send notification") retval = 1 return retval