From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 7D654138D01 for ; Sun, 21 Jun 2015 00:39:58 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DD5F014015; Sun, 21 Jun 2015 00:39:55 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 56B3A1400F for ; Sun, 21 Jun 2015 00:39:55 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3AC47340C77 for ; Sun, 21 Jun 2015 00:39:54 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id DD314A3A for ; Sun, 21 Jun 2015 00:39:52 +0000 (UTC) From: "Kent Fredric" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Kent Fredric" Message-ID: <1434846208.94b98bb0d11bfda14193cdb9c01c4c10d6e6f7ba.kent@gentoo> Subject: [gentoo-commits] proj/perl-overlay:master commit in: eclass/ X-VCS-Repository: proj/perl-overlay X-VCS-Files: eclass/perl-version.eclass X-VCS-Directories: eclass/ X-VCS-Committer: kent X-VCS-Committer-Name: Kent Fredric X-VCS-Revision: 94b98bb0d11bfda14193cdb9c01c4c10d6e6f7ba X-VCS-Branch: master Date: Sun, 21 Jun 2015 00:39:52 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: ad52a35e-f1b3-4387-9090-490ddac01ac7 X-Archives-Hash: e39025192fc687ebb906c0a0ddf400da commit: 94b98bb0d11bfda14193cdb9c01c4c10d6e6f7ba Author: Kent Fredric gmail com> AuthorDate: Sun Jun 21 00:14:19 2015 +0000 Commit: Kent Fredric gmail com> CommitDate: Sun Jun 21 00:23:28 2015 +0000 URL: https://gitweb.gentoo.org/proj/perl-overlay.git/commit/?id=94b98bb0 [eclass] Add perl-version.eclass which can turn normalised forms into floats eclass/perl-version.eclass | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/eclass/perl-version.eclass b/eclass/perl-version.eclass new file mode 100644 index 0000000..97022e2 --- /dev/null +++ b/eclass/perl-version.eclass @@ -0,0 +1,91 @@ +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +# @ECLASS: perl-versions.eclass +# @MAINTAINER: +# perl@gentoo.org +# Kent Fredric +# @BLURB: Perl versioning functions +# @DESCRIPTION: +# The perl-version eclass contains an assortment of functions for denormalizing versions +# in order to streamline version bumps and minimise risk of accidental failure to update +# MODULE_VERSION and unify all the ways of turning arbitrary normalised versions back into +# a form used upstream. + +# expand-tail 5 => 005 +# expand-tail 5.5 => 005005 +perl-version-expand-tail() { + local tail=$1 + if [ -z "${tail}" ]; then + echo '000'; + return; + fi + # Tail with no segments + if [ "${tail%%.*}" = "${tail}" ]; then + printf "%03d" "$tail" + return; + fi + local head="${tail%%.*}" + local rest=$( perl-version-expand-tail "${tail#*.}" ) + printf "%03d%s" $head $rest; + return; +} + +# float 5.1 => 5.001 +# float 5.10 => 5.010 +# float 5.100 => 5.100 +# float 5.1.1 => 5.001001 +perl-version-float() { + local version=$1 + local major=${version%%.*} + local tail=${version#*.} + if [ "$tail" = "$version" ]; then + tail=000; + else + tail=$( perl-version-expand-tail "${tail}" ) + fi + printf "%s.%s" "$major" "$tail"; + return; +} + +# float_n 5.201.505.200 8 => 5.20150520 +perl-version-float_n() { + local version=$1 + local mantissa=$2 + local major=${version%%.*} + if [ "$mantissa" -lt 1 ]; then + printf "%s" $major; + return; + fi + local tail=${version#*.} + if [ "$tail" = "$version" ]; then + tail=000; + else + tail=$( perl-version-expand-tail "${tail}" ) + fi + if [ "${#tail}" -lt $mantissa ]; then + local pad=$(( $mantissa - ${#tail} )); + printf "%s.%s%0${pad}d" "${major}" "${tail}" 0 + return + fi + printf "%s.%s" "${major}" "${tail:0:$mantissa}" +} + +# denormalize 5.201.505.200 float_n 8 => 5.20150520 +perl-version-denormalize() { + local version=$1; + local scheme=$2; + shift + shift + case "${scheme}" in + "float_n") + perl-version-float_n $version "$@" + return + ;; + *) + die "Unknown version scheme ${scheme}" + ;; + esac +} +