automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: Automake::Version


From: Alexandre Duret-Lutz
Subject: FYI: Automake::Version
Date: Sat, 12 Apr 2003 00:10:45 +0200
User-agent: Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.2 (gnu/linux)

I'm installing this on HEAD.  The point is mainly to move
tests/version5.test with the other "Perl" tests.

2003-04-12  Alexandre Duret-Lutz  <address@hidden>

        * 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.

Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1442
diff -u -r1.1442 automake.in
--- automake.in 10 Apr 2003 19:50:20 -0000      1.1442
+++ automake.in 11 Apr 2003 22:09:50 -0000
@@ -128,6 +128,7 @@
 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 @@
 
 ################################################################
 
-# 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 (address@hidden, address@hidden)
-# ----------------------------------------
-# Return 1 if LVERSION > RVERSION,
-#       -1 if LVERSION < RVERSION,
-#        0 if LVERSION = RVERSION.
-sub version_compare (address@hidden@)
-{
-    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 @@
       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);
Index: lib/Automake/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/Makefile.am,v
retrieving revision 1.10
diff -u -r1.10 Makefile.am
--- lib/Automake/Makefile.am    19 Jan 2003 23:01:03 -0000      1.10
+++ lib/Automake/Makefile.am    11 Apr 2003 22:09:50 -0000
@@ -28,4 +28,5 @@
   General.pm \
   Location.pm \
   Struct.pm \
+  Version.pm \
   XFile.pm
Index: lib/Automake/Makefile.in
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/Makefile.in,v
retrieving revision 1.61
diff -u -r1.61 Makefile.in
--- lib/Automake/Makefile.in    11 Apr 2003 21:12:22 -0000      1.61
+++ lib/Automake/Makefile.in    11 Apr 2003 22:09:50 -0000
@@ -128,6 +128,7 @@
   General.pm \
   Location.pm \
   Struct.pm \
+  Version.pm \
   XFile.pm
 
 all: all-recursive
Index: lib/Automake/Version.pm
===================================================================
RCS file: lib/Automake/Version.pm
diff -N lib/Automake/Version.pm
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/Automake/Version.pm     11 Apr 2003 22:09:50 -0000
@@ -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<MAJOR.MINOR[.MICRO][ALPHA][-FORK]> where C<MAJOR>, C<MINOR>, and
+C<MICRO> are digits, C<ALPHA> is a character, and C<FORK> any
+alphanumeric word.
+
+Usually, C<ALPHA> is used to label alpha releases or intermediate
+snapshots, C<FORK> is used for CVS branches or patched releases, and
+C<MICRO> is used for bug fixes releases on the C<MAJOR.MINOR> 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<FORK> 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 ($version)>
+
+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 (address@hidden, address@hidden)>
+
+Compare two version tuples, as returned by C<split>.
+
+Return 1, 0, or -1, if C<LVERSION> is found to be respectively
+greater than, equal to, or less than C<RVERSION>.
+
+=cut
+
+sub compare (address@hidden@)
+{
+  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<check($VERSION, $REQUIRED)>
+
+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:
Index: lib/Automake/tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/tests/Makefile.am,v
retrieving revision 1.2
diff -u -r1.2 Makefile.am
--- lib/Automake/tests/Makefile.am      19 Jan 2003 23:01:03 -0000      1.2
+++ lib/Automake/tests/Makefile.am      11 Apr 2003 22:09:50 -0000
@@ -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)
Index: lib/Automake/tests/Makefile.in
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/tests/Makefile.in,v
retrieving revision 1.5
diff -u -r1.5 Makefile.in
--- lib/Automake/tests/Makefile.in      11 Apr 2003 21:12:22 -0000      1.5
+++ lib/Automake/tests/Makefile.in      11 Apr 2003 22:09:51 -0000
@@ -107,7 +107,8 @@
 TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
 TESTS = \
 Condition.pl \
-DisjConditions.pl
+DisjConditions.pl \
+Version.pl
 
 EXTRA_DIST = $(TESTS)
 all: all-am
Index: lib/Automake/tests/Version.pl
===================================================================
RCS file: lib/Automake/tests/Version.pl
diff -N lib/Automake/tests/Version.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/Automake/tests/Version.pl       11 Apr 2003 22:09:51 -0000
@@ -0,0 +1,101 @@
+# Copyright (C) 2002, 2003  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake 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.
+#
+# GNU Automake 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 Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+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);
+  if ($#leftver == -1)
+  {
+    print "can't grok \"$left\"\n";
+    $failed = 1;
+    return;
+  }
+  if ($#rightver == -1)
+  {
+    print "can't grok \"$right\"\n";
+    $failed = 1;
+    return;
+  }
+  my $res = Automake::Version::compare (@leftver, @rightver);
+  if ($res != $result)
+  {
+    print "compare (\"$left\", \"$right\") = $res! (not $result?)\n";
+    $failed = 1;
+  }
+}
+
+my @tests = (
+# basics
+  ['1.0', '2.0', -1],
+  ['2.0', '1.0', 1],
+  ['1.2', '1.2', 0],
+  ['1.1', '1.2', -1],
+  ['1.2', '1.1', 1],
+# alphas
+  ['1.4', '1.4g', -1],
+  ['1.4g', '1.5', -1],
+  ['1.4g', '1.4', 1],
+  ['1.5', '1.4g', 1],
+  ['1.4a', '1.4g', -1],
+  ['1.5a', '1.3g', 1],
+  ['1.6a', '1.6a', 0],
+# micros
+  ['1.5.1', '1.5', 1],
+  ['1.5.0', '1.5', 0],
+  ['1.5.4', '1.6.1', -1],
+# micros and alphas
+  ['1.5a', '1.5.1', 1],
+  ['1.5a', '1.5.1a', 1],
+  ['1.5a', '1.5.1f', 1],
+  ['1.5', '1.5.1a', -1],
+  ['1.5.1a', '1.5.1f', -1],
+# special exceptions
+  ['1.6-p5a', '1.6.5a', 0],
+  ['1.6', '1.6-p5a', -1],
+  ['1.6-p4b', '1.6-p5a', -1],
+  ['1.6-p4b', '1.6-foo', 1],
+  ['1.6-p4b', '1.6a-foo', -1]
+);
+
+test_version_compare (@{$_}) foreach @tests;
+
+exit $failed;
+
+### 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:
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.478
diff -u -r1.478 Makefile.am
--- tests/Makefile.am   6 Apr 2003 18:31:12 -0000       1.478
+++ tests/Makefile.am   11 Apr 2003 22:09:51 -0000
@@ -440,7 +440,6 @@
 version2.test \
 version3.test \
 version4.test \
-version5.test \
 version6.test \
 version7.test \
 vpath.test \
Index: tests/Makefile.in
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.in,v
retrieving revision 1.617
diff -u -r1.617 Makefile.in
--- tests/Makefile.in   11 Apr 2003 21:12:22 -0000      1.617
+++ tests/Makefile.in   11 Apr 2003 22:09:51 -0000
@@ -543,7 +543,6 @@
 version2.test \
 version3.test \
 version4.test \
-version5.test \
 version6.test \
 version7.test \
 vpath.test \
Index: tests/version5.test
===================================================================
RCS file: tests/version5.test
diff -N tests/version5.test
--- tests/version5.test 8 Sep 2002 13:07:56 -0000       1.2
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,100 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2002  Free Software Foundation, Inc.
-#
-# This file is part of GNU Automake.
-#
-# GNU Automake 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.
-#
-# GNU Automake 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 autoconf; 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
-
-my $failed = 0;
-
-sub test_version_compare
-{
-  my ($left, $right, $result) = @_;
-  my @leftver = Automake::version_split ($left);
-  my @rightver = Automake::version_split ($right);
-  if ($#leftver == -1)
-  {
-     print "can't grok \"$left\"\n";
-     $failed = 1;
-     return;
-  }
-  if ($#rightver == -1)
-  {
-     print "can't grok \"$right\"\n";
-     $failed = 1;
-     return;
-  }
-  my $res = Automake::version_compare (address@hidden, address@hidden);
-  if ($res != $result)
-  {
-     print "version_compare (\"$left\", \"$right\") = $res! (not $result?)\n";
-     $failed = 1;
-  }
-}
-
-my @tests = (
-# basics
-  ['1.0', '2.0', -1],
-  ['2.0', '1.0', 1],
-  ['1.2', '1.2', 0],
-  ['1.1', '1.2', -1],
-  ['1.2', '1.1', 1],
-# alphas
-  ['1.4', '1.4g', -1],
-  ['1.4g', '1.5', -1],
-  ['1.4g', '1.4', 1],
-  ['1.5', '1.4g', 1],
-  ['1.4a', '1.4g', -1],
-  ['1.5a', '1.3g', 1],
-  ['1.6a', '1.6a', 0],
-# micros
-  ['1.5.1', '1.5', 1],
-  ['1.5.0', '1.5', 0],
-  ['1.5.4', '1.6.1', -1],
-# micros and alphas
-  ['1.5a', '1.5.1', 1],
-  ['1.5a', '1.5.1a', 1],
-  ['1.5a', '1.5.1f', 1],
-  ['1.5', '1.5.1a', -1],
-  ['1.5.1a', '1.5.1f', -1],
-# special exceptions
-  ['1.6-p5a', '1.6.5a', 0],
-  ['1.6', '1.6-p5a', -1],
-  ['1.6-p4b', '1.6-p5a', -1],
-  ['1.6-p4b', '1.6-foo', 1],
-  ['1.6-p4b', '1.6a-foo', -1]
-);
-
-test_version_compare (@{$_}) foreach @tests;
-
-exit $failed;
-END
-
-cat $amfile >>automake_tmp
-
-$PERL ./automake_tmp
-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]