From: Benjamin Drung Date: Fri, 17 Jan 2014 14:58:53 +0000 (+0100) Subject: gentoo_build: Support building mutliple ebuilds from one git repository. X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=abcdb39c648f6ad8817d9bb0a8584e1c70e9d413;p=profitbricks%2Fjenkins-build-scripts.git gentoo_build: Support building mutliple ebuilds from one git repository. --- diff --git a/gentoo_build b/gentoo_build index 9fa0ade..29538ee 100755 --- a/gentoo_build +++ b/gentoo_build @@ -223,13 +223,14 @@ def shell_env(): def gentoo_build(script_name, logger, release_repo_uri, options): """Main function that creates a versioned ebuild file and releases it.""" - ebuild = find_ebuild(logger, options.category) + ebuilds = find_ebuilds(logger, options.category) if options.tag_from_debian: git_tag = tag_from_debian_changelog(logger) else: git_tag = get_latest_tag(logger) - ebuild.set_version(git_tag) - ebuild.set_git_commit(git_tag) + for ebuild in ebuilds: + ebuild.set_version(git_tag) + ebuild.set_git_commit(git_tag) tmpdir = tempfile.mkdtemp(prefix=script_name+".") try: # Checkout release repository @@ -241,21 +242,15 @@ def gentoo_build(script_name, logger, release_repo_uri, options): dir=tmpdir)) check_branch_existance(logger, release_repo_uri, branch) release_repo = git.Repo.clone_from(release_repo_uri, tmpdir, b=branch) - # Copy modified ebuild into release repository - ebuild.save(tmpdir) - # Update manifest file (in a Gentoo chroot) - cmd = ["schroot", "-c", options.chroot_name, "-u", options.chroot_user, - "-d", tmpdir, "--", "ebuild", ebuild.get_relpath(), "manifest"] - logger.info("Calling " + " ".join(cmd)) - retcode = subprocess.call(cmd) - if retcode != 0: - logger.error("ebuild command in Gentoo schroot failed with exit " - "code {code}.".format(code=retcode)) - sys.exit(retcode) - release_repo.git.add("-A") - release_repo.git.commit("-m", "Added " + ebuild.get_relpath()) - logger.info("Adding following commit:\n" + \ - release_repo.git.log("-p", "--stat", "HEAD~1..HEAD")) + for ebuild in ebuilds: + # Copy modified ebuild into release repository + ebuild.save(tmpdir) + update_manifest(logger, options.chroot_name, options.chroot_user, + tmpdir, ebuild.get_relpath()) + release_repo.git.add("-A") + release_repo.git.commit("-m", "Added " + ebuild.get_relpath()) + logger.info("Added following commit:\n" + \ + release_repo.git.log("-p", "--stat", "HEAD~1..HEAD")) # Push changes to the release repository if options.dry_run: logger.info("Not pushing changes to {repo} as dry run was " @@ -274,6 +269,17 @@ def gentoo_build(script_name, logger, release_repo_uri, options): else: shutil.rmtree(tmpdir) +def update_manifest(logger, chroot_name, chroot_user, workdir, ebuild_path): + """Update manifest file in a Gentoo chroot.""" + cmd = ["schroot", "-c", chroot_name, "-u", chroot_user, + "-d", workdir, "--", "ebuild", ebuild_path, "manifest"] + logger.info("Calling " + " ".join(cmd)) + retcode = subprocess.call(cmd) + if retcode != 0: + logger.error("ebuild command in Gentoo schroot failed with exit " + "code {code}.".format(code=retcode)) + sys.exit(retcode) + def check_branch_existance(logger, repo_uri, branch): """Check if the specified remote repository has the given branch. This check is needed, because a git clone on Debian 6.0 (squeeze) @@ -287,8 +293,8 @@ def check_branch_existance(logger, repo_uri, branch): "{repo}".format(branch=branch, repo=repo_uri)) sys.exit(1) -def find_ebuild(logger, category): - """Search for exactly one ebuild file in the current directory""" +def find_ebuilds(logger, category): + """Search for ebuild files in the current directory""" ebuild_files = glob.glob("*.ebuild") if len(ebuild_files) == 0: logger.error('No .ebuild file found in "{dir}".\n' @@ -296,15 +302,10 @@ def find_ebuild(logger, category): 'does your project contain an .ebuild file in the top ' 'directory?'.format(dir=os.getcwd())) sys.exit(1) - if len(ebuild_files) > 1: - logger.error('More than one .ebuild file found in "{dir}": ' - '{ebuild_files}\nThe script expects exactly one .ebuild ' - 'file.'.format(dir=os.getcwd(), - ebuild_files=ebuild_files)) - sys.exit(1) - ebuild_file = ebuild_files[0] - logger.info('Use ebuild file: {ebuild}'.format(ebuild=ebuild_file)) - return Ebuild(logger, ebuild_file, category) + logger.info('Found {n} ebuild file(s): ' + '{ebuild}'.format(n=len(ebuild_files), + ebuild=" ".join(ebuild_files))) + return [Ebuild(logger, e, category) for e in ebuild_files] def tag_from_debian_changelog(logger): """Create a tag from the version specified in debian/changelog.