From: Alexandre Duret-Lutz Date: Fri, 11 Apr 2003 22:11:43 +0000 (+0000) Subject: * lib/Automake/Version.pm: New file. X-Git-Tag: Release-1-7-3b~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7db82ebdfea5886b00820530b33e5eee3b7671b1;p=thirdparty%2Fautomake.git * lib/Automake/Version.pm: New file. * lib/Automake/Makefile.am (dist_perllib_DATA): Add Version.pm. * lib/Automake/tests/Version.pl: New file. * lib/Automake/tests/Makefile.am (TESTS): Add Version.pl. * tests/Makefile.am (TESTS): Remove version5.test. * tests/version5.test: Delete. Move the tests to Version.pl. * automake.in (version_split, version_compare, version_check): Move ... * lib/Automake/Version.pm (split, compare, check): ... here. --- diff --git a/ChangeLog b/ChangeLog index 6c19021d2..e5c188bf1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2003-04-12 Alexandre Duret-Lutz + + * lib/Automake/Version.pm: New file. + * lib/Automake/Makefile.am (dist_perllib_DATA): Add Version.pm. + * lib/Automake/tests/Version.pl: New file. + * lib/Automake/tests/Makefile.am (TESTS): Add Version.pl. + * tests/Makefile.am (TESTS): Remove version5.test. + * tests/version5.test: Delete. Move the tests to Version.pl. + * automake.in (version_split, version_compare, version_check): Move ... + * lib/Automake/Version.pm (split, compare, check): ... here. + 2003-04-11 Alexandre Duret-Lutz * lib/Automake/tests/Condition.pl (test_reduce_and) diff --git a/automake.in b/automake.in index c0b899b2a..ac582c595 100755 --- a/automake.in +++ b/automake.in @@ -128,6 +128,7 @@ use Automake::ChannelDefs; use Automake::Location; use Automake::Condition qw/TRUE FALSE/; use Automake::DisjConditions; +use Automake::Version; use File::Basename; use Tie::RefHash; use Carp; @@ -1634,92 +1635,6 @@ sub generate_makefile ################################################################ -# A version is a string that looks like -# MAJOR.MINOR[.MICRO][ALPHA][-FORK] -# where -# MAJOR, MINOR, and MICRO are digits, ALPHA is a character, and -# FORK any alphanumeric word. -# Usually, ALPHA is used to label alpha releases or intermediate snapshots, -# FORK is used for CVS branches or patched releases, and MICRO is used -# for bug fixes releases on the MAJOR.MINOR branch. -# -# For the purpose of ordering, 1.4 is the same as 1.4.0, but 1.4g is -# the same as 1.4.99g. The FORK identifier is ignored in the -# ordering, except when it looks like -pMINOR[ALPHA]: some versions -# were labeled like 1.4-p3a, this is the same as an alpha release -# labeled 1.4.3a. Yes, it's horrible, but Automake did not support -# two-dot versions in the past. - -# version_split (VERSION) -# ----------------------- -# Split a version string into the corresponding (MAJOR, MINOR, MICRO, -# ALPHA, FORK) tuple. For instance "1.4g" would be split into -# (1, 4, 99, 'g', ''). -# Return () on error. -sub version_split ($) -{ - my ($ver) = @_; - - # Special case for versions like 1.4-p2a. - if ($ver =~ /^(\d+)\.(\d+)(?:-p(\d+)([a-z]+)?)$/) - { - return ($1, $2, $3, $4 || '', ''); - } - # Common case. - elsif ($ver =~ /^(\d+)\.(\d+)(?:\.(\d+))?([a-z])?(?:-([A-Za-z0-9]+))?$/) - { - return ($1, $2, $3 || (defined $4 ? 99 : 0), $4 || '', $5 || ''); - } - return (); -} - -# version_compare (\@LVERSION, \@RVERSION) -# ---------------------------------------- -# Return 1 if LVERSION > RVERSION, -# -1 if LVERSION < RVERSION, -# 0 if LVERSION = RVERSION. -sub version_compare (\@\@) -{ - my @l = @{$_[0]}; - my @r = @{$_[1]}; - - for my $i (0, 1, 2) - { - return 1 if ($l[$i] > $r[$i]); - return -1 if ($l[$i] < $r[$i]); - } - for my $i (3, 4) - { - return 1 if ($l[$i] gt $r[$i]); - return -1 if ($l[$i] lt $r[$i]); - } - return 0; -} - -# Handles the logic of requiring a version number in AUTOMAKE_OPTIONS. -# Return 0 if the required version is satisfied, 1 otherwise. -sub version_check ($) -{ - my ($required) = @_; - my @version = version_split $VERSION; - my @required = version_split $required; - - prog_error "version is incorrect: $VERSION" - if $#version == -1; - - # This should not happen, because process_option_list and split_version - # use similar regexes. - prog_error "required version is incorrect: $required" - if $#required == -1; - - # If we require 3.4n-foo then we require something - # >= 3.4n, with the `foo' fork identifier. - return 1 - if ($required[4] ne '' && $required[4] ne $version[4]); - - return 0 > version_compare @version, @required; -} - # $BOOL # process_option_list ($CONFIG, @OPTIONS) # ------------------------------ @@ -1771,7 +1686,7 @@ sub process_option_list elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/) { # Got a version number. - if (version_check $&) + if (Automake::Version::check ($VERSION, $&)) { error ($where, "require Automake $_, but have $VERSION", uniq_scope => US_GLOBAL); diff --git a/lib/Automake/Makefile.am b/lib/Automake/Makefile.am index c724c874e..c51546f78 100644 --- a/lib/Automake/Makefile.am +++ b/lib/Automake/Makefile.am @@ -28,4 +28,5 @@ dist_perllib_DATA = \ General.pm \ Location.pm \ Struct.pm \ + Version.pm \ XFile.pm diff --git a/lib/Automake/Makefile.in b/lib/Automake/Makefile.in index d45051cd8..d6d04e4da 100644 --- a/lib/Automake/Makefile.in +++ b/lib/Automake/Makefile.in @@ -128,6 +128,7 @@ dist_perllib_DATA = \ General.pm \ Location.pm \ Struct.pm \ + Version.pm \ XFile.pm all: all-recursive diff --git a/lib/Automake/Version.pm b/lib/Automake/Version.pm new file mode 100644 index 000000000..5a874f817 --- /dev/null +++ b/lib/Automake/Version.pm @@ -0,0 +1,159 @@ +# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +package Automake::Version; +use strict; +use Automake::ChannelDefs; + +=head1 NAME + +Automake::Version - version comparison + +=head1 SYNOPSIS + + use Automake::Version; + + print "Version $version is older than required version $required\n" + if Automake::Version::check ($version, $required); + +=head1 DESCRIPTION + +This module provides support for comparing versions string +as they are used in Automake. + +A version is a string that looks like +C where C, C, and +C are digits, C is a character, and C any +alphanumeric word. + +Usually, C is used to label alpha releases or intermediate +snapshots, C is used for CVS branches or patched releases, and +C is used for bug fixes releases on the C branch. + +For the purpose of ordering, C<1.4> is the same as C<1.4.0>, but +C<1.4g> is the same as C<1.4.99g>. The C identifier is ignored +in the ordering, except when it looks like C<-pMINOR[ALPHA]>: some +versions were labeled like C<1.4-p3a>, this is the same as an alpha +release labeled C<1.4.3a>. Yes, it's horrible, but Automake did not +support two-dot versions in the past. + +=head2 FUNCTIONS + +=over 4 + +=item C + +Split the string C<$version> into the corresponding C<(MAJOR, MINOR, +MICRO, ALPHA, FORK)> tuple. For instance C<'1.4g'> would be split +into C<(1, 4, 99, 'g', '')>. Return C<()> on error. + +=cut + +sub split ($) +{ + my ($ver) = @_; + + # Special case for versions like 1.4-p2a. + if ($ver =~ /^(\d+)\.(\d+)(?:-p(\d+)([a-z]+)?)$/) + { + return ($1, $2, $3, $4 || '', ''); + } + # Common case. + elsif ($ver =~ /^(\d+)\.(\d+)(?:\.(\d+))?([a-z])?(?:-([A-Za-z0-9]+))?$/) + { + return ($1, $2, $3 || (defined $4 ? 99 : 0), $4 || '', $5 || ''); + } + return (); +} + +=item C + +Compare two version tuples, as returned by C. + +Return 1, 0, or -1, if C is found to be respectively +greater than, equal to, or less than C. + +=cut + +sub compare (\@\@) +{ + my @l = @{$_[0]}; + my @r = @{$_[1]}; + + for my $i (0, 1, 2) + { + return 1 if ($l[$i] > $r[$i]); + return -1 if ($l[$i] < $r[$i]); + } + for my $i (3, 4) + { + return 1 if ($l[$i] gt $r[$i]); + return -1 if ($l[$i] lt $r[$i]); + } + return 0; +} + +=item C + +Handles the logic of requiring a version number in Automake. +C<$VERSION> should be Automake's version, while C<$REQUIRED> +is the version required by the user input. + +Return 0 if the required version is satisfied, 1 otherwise. + +=cut + +sub check ($$) +{ + my ($version, $required) = @_; + my @version = Automake::Version::split ($version); + my @required = Automake::Version::split ($required); + + prog_error "version is incorrect: $version" + if $#version == -1; + + # This should not happen, because process_option_list and split_version + # use similar regexes. + prog_error "required version is incorrect: $required" + if $#required == -1; + + # If we require 3.4n-foo then we require something + # >= 3.4n, with the `foo' fork identifier. + return 1 + if ($required[4] ne '' && $required[4] ne $version[4]); + + return 0 > compare (@version, @required); +} + +1; + +### Setup "GNU" style for perl-mode and cperl-mode. +## Local Variables: +## perl-indent-level: 2 +## perl-continued-statement-offset: 2 +## perl-continued-brace-offset: 0 +## perl-brace-offset: 0 +## perl-brace-imaginary-offset: 0 +## perl-label-offset: -2 +## cperl-indent-level: 2 +## cperl-brace-offset: 0 +## cperl-continued-brace-offset: 0 +## cperl-label-offset: -2 +## cperl-extra-newline-before-brace: t +## cperl-merge-trailing-else: nil +## cperl-continued-statement-offset: 2 +## End: diff --git a/lib/Automake/tests/Makefile.am b/lib/Automake/tests/Makefile.am index 1fefa7157..22127660e 100644 --- a/lib/Automake/tests/Makefile.am +++ b/lib/Automake/tests/Makefile.am @@ -20,6 +20,7 @@ TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w TESTS = \ Condition.pl \ -DisjConditions.pl +DisjConditions.pl \ +Version.pl EXTRA_DIST = $(TESTS) diff --git a/lib/Automake/tests/Makefile.in b/lib/Automake/tests/Makefile.in index 9050a37e6..822c08170 100644 --- a/lib/Automake/tests/Makefile.in +++ b/lib/Automake/tests/Makefile.in @@ -107,7 +107,8 @@ target_alias = @target_alias@ TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w TESTS = \ Condition.pl \ -DisjConditions.pl +DisjConditions.pl \ +Version.pl EXTRA_DIST = $(TESTS) all: all-am diff --git a/tests/version5.test b/lib/Automake/tests/Version.pl old mode 100755 new mode 100644 similarity index 61% rename from tests/version5.test rename to lib/Automake/tests/Version.pl index 2995dcc13..f8e2a4084 --- a/tests/version5.test +++ b/lib/Automake/tests/Version.pl @@ -1,5 +1,4 @@ -#! /bin/sh -# Copyright (C) 2002 Free Software Foundation, Inc. +# Copyright (C) 2002, 2003 Free Software Foundation, Inc. # # This file is part of GNU Automake. # @@ -14,46 +13,36 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with autoconf; see the file COPYING. If not, write to +# along with Automake; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -# Exercise &version_compare. - -. ./defs || exit 1 - -set -e - -# FIXME: probably ought to let users override this like we do in `defs'. -amfile=../../automake - -sed 1q $amfile >>automake_tmp -cat << 'END' >> automake_tmp +use Automake::Version; my $failed = 0; sub test_version_compare { my ($left, $right, $result) = @_; - my @leftver = Automake::version_split ($left); - my @rightver = Automake::version_split ($right); + my @leftver = Automake::Version::split ($left); + my @rightver = Automake::Version::split ($right); if ($#leftver == -1) { - print "can't grok \"$left\"\n"; - $failed = 1; - return; + print "can't grok \"$left\"\n"; + $failed = 1; + return; } if ($#rightver == -1) { - print "can't grok \"$right\"\n"; - $failed = 1; - return; + print "can't grok \"$right\"\n"; + $failed = 1; + return; } - my $res = Automake::version_compare (\@leftver, \@rightver); + my $res = Automake::Version::compare (@leftver, @rightver); if ($res != $result) { - print "version_compare (\"$left\", \"$right\") = $res! (not $result?)\n"; - $failed = 1; + print "compare (\"$left\", \"$right\") = $res! (not $result?)\n"; + $failed = 1; } } @@ -93,8 +82,20 @@ my @tests = ( test_version_compare (@{$_}) foreach @tests; exit $failed; -END - -cat $amfile >>automake_tmp -$PERL ./automake_tmp +### Setup "GNU" style for perl-mode and cperl-mode. +## Local Variables: +## perl-indent-level: 2 +## perl-continued-statement-offset: 2 +## perl-continued-brace-offset: 0 +## perl-brace-offset: 0 +## perl-brace-imaginary-offset: 0 +## perl-label-offset: -2 +## cperl-indent-level: 2 +## cperl-brace-offset: 0 +## cperl-continued-brace-offset: 0 +## cperl-label-offset: -2 +## cperl-extra-newline-before-brace: t +## cperl-merge-trailing-else: nil +## cperl-continued-statement-offset: 2 +## End: diff --git a/tests/Makefile.am b/tests/Makefile.am index 3f70ff58f..e0c9ae65c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -440,7 +440,6 @@ version.test \ version2.test \ version3.test \ version4.test \ -version5.test \ version6.test \ version7.test \ vpath.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 65f4a8bd4..9a19ca9c3 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -543,7 +543,6 @@ version.test \ version2.test \ version3.test \ version4.test \ -version5.test \ version6.test \ version7.test \ vpath.test \