]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* lib/Autom4te/Request.pm, lib/Autom4te/C4che.pm: New.
authorAkim Demaille <akim@epita.fr>
Fri, 22 Aug 2003 08:09:12 +0000 (08:09 +0000)
committerAkim Demaille <akim@epita.fr>
Fri, 22 Aug 2003 08:09:12 +0000 (08:09 +0000)
* bin/autom4te.in: Adjust.

ChangeLog
bin/autom4te.in
lib/Autom4te/C4che.pm [new file with mode: 0644]
lib/Autom4te/Makefile.am
lib/Autom4te/Makefile.in
lib/Autom4te/Request.pm [new file with mode: 0644]

index e9f0d308ba2ea32bbe5688df89eccb4eb429609d..1ed03087d18782e207a4dcf168d2e7051ec21194 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-08-22  Akim Demaille  <akim@epita.fr>
+
+       * lib/Autom4te/Request.pm, lib/Autom4te/C4che.pm: New.
+       * bin/autom4te.in: Adjust.
+
 2003-08-21  Akim Demaille  <akim@epita.fr>
 
        * lib/Autom4te/General.pm (&file_name_is_absolute): Remove.
index a6d06c10737c6a912189491a265267ed006fffb6..6a7bc80d734e951fe8061f66ad785695d702b371 100644 (file)
@@ -36,212 +36,13 @@ BEGIN
   $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
 }
 
-## --------- ##
-## Request.  ##
-## --------- ##
-
-package Request;
-
-use Data::Dumper;
-use Autom4te::FileUtils;
-use Autom4te::General;
-use Autom4te::Struct;
-use Autom4te::XFile;
-use Carp;
-use strict;
-
-# List of requests.
-# We can't declare it `my' as the loading, performed via `do',
-# would refer to another scope, and @request would not be updated.
-# It used to work with `my' vars, and I don't know whether the current
-# behavior (5.6) is wanted or not.
-use vars qw(@request);
-
-struct
-  (
-   # The key of the cache files.
-   'id' => "\$",
-   # True iff %MACRO contains all the macros we want to trace.
-   'valid' => "\$",
-   # The include path.
-   'path' => '@',
-   # The set of input files.
-   'input' => '@',
-   # The set of macros currently traced.
-   'macro' => '%',
-  );
-
-
-# $REQUEST-OBJ
-# retrieve ($SELF, %ATTR)
-# -----------------------
-# Find a request with the same path and input.
-# Private.
-sub retrieve
-{
-  my ($self, %attr) = @_;
-
-  foreach (@request)
-    {
-      # Same path.
-      next
-       if join ("\n", @{$_->path}) ne join ("\n", @{$attr{path}});
-
-      # Same inputs.
-      next
-       if join ("\n", @{$_->input}) ne join ("\n", @{$attr{input}});
-
-      # Found it.
-      return $_;
-    }
-
-  return undef;
-}
-
-
-# $REQUEST-OBJ
-# register ($SELF, %ATTR)
-# -----------------------
-# NEW should not be called directly.
-# Private.
-sub register ($%)
-{
-  my ($self, %attr) = @_;
-
-  # path and input are the only ID for a request object.
-  my $obj = $self->new ('path'  => $attr{path},
-                       'input' => $attr{input});
-  push @request, $obj;
-
-  # Assign an id for cache file.
-  $obj->id ("$#request");
-
-  return $obj;
-}
-
-
-# $REQUEST-OBJ
-# request($SELF, %REQUEST)
-# ------------------------
-# Return a request corresponding to $REQUEST{path} and $REQUEST{input},
-# using a cache value if it exists.
-sub request ($%)
-{
-  my ($self, %request) = @_;
-
-  my $req = Request->retrieve (%request) || Request->register (%request);
-
-  # If there are new traces to produce, then we are not valid.
-  foreach (@{$request{'macro'}})
-    {
-      if (! exists ${$req->macro}{$_})
-       {
-         ${$req->macro}{$_} = 1;
-         $req->valid (0);
-       }
-    }
-
-  # It would be great to have $REQ check that it up to date wrt its
-  # dependencies, but that requires getting traces (to fetch the
-  # included files), which is out of the scope of Request
-  # (currently?).
-
-  return $req;
-}
-
-# Serialize a request or all the current requests.
-sub marshall
-{
-  my ($caller) = @_;
-  my $res = '';
-
-  if (ref ($caller))
-    {
-      # CALLER is an object: instance method.
-      my $marshall = Data::Dumper->new ([$caller]);
-      $marshall->Indent(2)->Terse(0);
-      $res = $marshall->Dump . "\n";
-    }
-  else
-    {
-      # CALLER is the package: class method.
-      my $marshall = Data::Dumper->new ([\@request], [qw (*request)]);
-      $marshall->Indent(2)->Terse(0);
-      $res = $marshall->Dump . "\n";
-    }
-
-  return $res;
-}
-
-
-# includes_p (@MACRO)
-# -------------------
-# Does this request covers all the @MACRO.
-sub includes_p
-{
-  my ($self, @macro) = @_;
-
-  foreach (@macro)
-    {
-      return 0
-       if ! exists ${$self->macro}{$_};
-    }
-  return 1;
-}
-
-
-# SAVE ($FILE)
-# ------------
-# Save the cache in the $FILE Autom4te::XFile object.
-sub save
-{
-  my ($self, $file) = @_;
-
-  croak "$me: cannot save a single request\n"
-    if ref ($self);
-
-  $file->seek (0, 0);
-  $file->truncate (0);
-  print $file
-    "# This file was created by $me.\n",
-    "# It contains the lists of macros which have been traced.\n",
-    "# It can be safely removed.\n",
-    "\n",
-    $self->marshall;
-}
-
-
-# LOAD ($FILE)
-# ------------
-# "eval" the content of the $FILE Autom4te::XFile object.
-sub load
-{
-  my ($self, $file) = @_;
-  my $fname = $file->name;
-
-  croak "$me: cannot load a single request\n"
-    if ref ($self);
-
-  my $contents = join "", $file->getlines;
-
-  eval $contents;
-
-  croak "$me: cannot eval $fname: $@\n" if $@;
-}
-
-
-## ---------- ##
-## Autom4te.  ##
-## ---------- ##
-
-package Autom4te;
-
+use Autom4te::C4che;
 use Autom4te::ChannelDefs;
 use Autom4te::Channels;
 use Autom4te::FileUtils;
 use Autom4te::General;
-use File::Basename;
 use Autom4te::XFile;
+use File::Basename;
 use strict;
 
 # Data directory.
@@ -1167,15 +968,15 @@ $icache_file = new Autom4te::XFile $icache, O_RDWR|O_CREAT;
 $icache_file->lock (LOCK_EX);
 
 # Read the cache index if available and older than autom4te itself.
-# If autom4te is younger, then some structures such as Request, might
+# If autom4te is younger, then some structures such as C4che, might
 # have changed, which would corrupt its processing.
-Request->load ($icache_file)
+Autom4te::C4che->load ($icache_file)
   if -f $icache && mtime ($icache) > mtime ($0);
 
 # Add the new trace requests.
-my $req = Request->request ('input' => \@ARGV,
-                           'path'  => \@include,
-                           'macro' => [keys %trace, @preselect]);
+my $req = Autom4te::C4che->request ('input' => \@ARGV,
+                                   'path'  => \@include,
+                                   'macro' => [keys %trace, @preselect]);
 
 # If $REQ's cache files are not up to date, or simply if the user
 # discarded them (-f), declare it invalid.
@@ -1219,7 +1020,7 @@ else
 
 # If we ran up to here, the cache is valid.
 $req->valid (1);
-Request->save ($icache_file);
+Autom4te::C4che->save ($icache_file);
 
 exit $exit_code;
 
diff --git a/lib/Autom4te/C4che.pm b/lib/Autom4te/C4che.pm
new file mode 100644 (file)
index 0000000..ef6f0c3
--- /dev/null
@@ -0,0 +1,245 @@
+# autoconf -- create `configure' using m4 macros
+# Copyright (C) 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 Autom4te::C4che;
+
+=head1 NAME
+
+Autom4te::C4che - a single m4 run request
+
+=head1 SYNOPSIS
+
+  use Autom4te::C4che;
+
+=head1 DESCRIPTION
+
+This Perl module handles the cache of M4 runs used by autom4te.
+
+=cut
+
+use Data::Dumper;
+use Autom4te::Request;
+use Carp;
+use strict;
+
+=over 4
+
+=item @request
+
+List of requests.
+
+We cannot declare it "my" as the loading, performed via "do", would
+refer to another scope, and @request would not be updated.  It used to
+work with "my" vars, and I do not know whether the current behavior
+(5.6) is wanted or not.
+
+=cut
+
+use vars qw(@request);
+
+=item C<$req = Autom4te::C4che-E<gt>retrieve (%attr)>
+
+Find a request with the same path and input.
+
+=cut
+
+sub retrieve($%)
+{
+  my ($self, %attr) = @_;
+
+  foreach (@request)
+    {
+      # Same path.
+      next
+       if join ("\n", @{$_->path}) ne join ("\n", @{$attr{path}});
+
+      # Same inputs.
+      next
+       if join ("\n", @{$_->input}) ne join ("\n", @{$attr{input}});
+
+      # Found it.
+      return $_;
+    }
+
+  return undef;
+}
+
+=item C<$req = Autom4te::C4che-E<gt>register (%attr)>
+
+Create and register a request for these path and input.
+
+=cut
+
+# $REQUEST-OBJ
+# register ($SELF, %ATTR)
+# -----------------------
+# NEW should not be called directly.
+# Private.
+sub register ($%)
+{
+  my ($self, %attr) = @_;
+
+  # path and input are the only ID for a request object.
+  my $obj = new Autom4te::Request ('path'  => $attr{path},
+                                  'input' => $attr{input});
+  push @request, $obj;
+
+  # Assign an id for cache file.
+  $obj->id ("$#request");
+
+  return $obj;
+}
+
+
+=item C<$req = Autom4te::C4che-E<gt>request (%request)>
+
+Get (retrieve or create) a request for the path C<$request{path}> and
+the input C<$request{input}>.
+
+=cut
+
+# $REQUEST-OBJ
+# request($SELF, %REQUEST)
+# ------------------------
+sub request ($%)
+{
+  my ($self, %request) = @_;
+
+  my $req =
+    Autom4te::C4che->retrieve (%request)
+    || Autom4te::C4che->register (%request);
+
+  # If there are new traces to produce, then we are not valid.
+  foreach (@{$request{'macro'}})
+    {
+      if (! exists ${$req->macro}{$_})
+       {
+         ${$req->macro}{$_} = 1;
+         $req->valid (0);
+       }
+    }
+
+  # It would be great to have $REQ check that it up to date wrt its
+  # dependencies, but that requires getting traces (to fetch the
+  # included files), which is out of the scope of Request
+  # (currently?).
+
+  return $req;
+}
+
+
+=item C<$string = Autom4te::C4che-E<gt>marshall ()>
+
+Serialize all the current requests.
+
+=cut
+
+
+# marshall($SELF)
+# ---------------
+sub marshall ($)
+{
+  my ($caller) = @_;
+  my $res = '';
+
+  my $marshall = Data::Dumper->new ([\@request], [qw (*request)]);
+  $marshall->Indent(2)->Terse(0);
+  $res = $marshall->Dump . "\n";
+
+  return $res;
+}
+
+
+=item C<Autom4te::C4che-E<gt>save ($file)>
+
+Save the cache in the C<$file> file object.
+
+=cut
+
+# SAVE ($FILE)
+# ------------
+sub save ($$)
+{
+  my ($self, $file) = @_;
+
+  confess "cannot save a single request\n"
+    if ref ($self);
+
+  $file->seek (0, 0);
+  $file->truncate (0);
+  print $file
+    "# This file was generated.\n",
+    "# It contains the lists of macros which have been traced.\n",
+    "# It can be safely removed.\n",
+    "\n",
+    $self->marshall;
+}
+
+
+=item C<Autom4te::C4che-E<gt>load ($file)>
+
+Load the cache from the C<$file> file object.
+
+=cut
+
+# LOAD ($FILE)
+# ------------
+sub load ($$)
+{
+  my ($self, $file) = @_;
+  my $fname = $file->name;
+
+  confess "cannot load a single request\n"
+    if ref ($self);
+
+  my $contents = join "", $file->getlines;
+
+  eval $contents;
+
+  confess "cannot eval $fname: $@\n" if $@;
+}
+
+
+=head1 SEE ALSO
+
+L<Autom4te::Request>
+
+=head1 HISTORY
+
+Written by Akim Demaille E<lt>F<akim@freefriends.org>E<gt>.
+
+=cut
+
+1; # for require
+
+### 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 48ac0a8f021c1d3fd627bfd8fb7e0c0f4048508e..68321507834fe11c92a894925ff9aa7df3f58d94 100644 (file)
@@ -2,11 +2,13 @@
 
 perllibdir = $(pkgdatadir)/Autom4te
 dist_perllib_DATA = \
+  C4che.pm \
   ChannelDefs.pm \
   Channels.pm \
   Configure_ac.pm \
   FileUtils.pm \
   General.pm \
+  Request.pm \
   Struct.pm \
   XFile.pm
 
index 6e30d945c558b426da69195b937e4bbe3ab6ea0b..0eb9f854af88e1da76dc8d296e14eb3cbcb52ce6 100644 (file)
@@ -110,11 +110,13 @@ sysconfdir = @sysconfdir@
 target_alias = @target_alias@
 perllibdir = $(pkgdatadir)/Autom4te
 dist_perllib_DATA = \
+  C4che.pm \
   ChannelDefs.pm \
   Channels.pm \
   Configure_ac.pm \
   FileUtils.pm \
   General.pm \
+  Request.pm \
   Struct.pm \
   XFile.pm
 
diff --git a/lib/Autom4te/Request.pm b/lib/Autom4te/Request.pm
new file mode 100644 (file)
index 0000000..97a6f7f
--- /dev/null
@@ -0,0 +1,116 @@
+# autoconf -- create `configure' using m4 macros
+# 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 Autom4te::Request;
+
+=head1 NAME
+
+Autom4te::Request - a single m4 run request
+
+=head1 SYNOPSIS
+
+  use Autom4te::Request;
+
+=head1 DESCRIPTION
+
+This perl module provides various general purpose support functions
+used in several executables of the Autoconf and Automake packages.
+
+=cut
+
+use strict;
+use Autom4te::Struct;
+use Carp;
+use Data::Dumper;
+
+struct
+  (
+   # The key of the cache files.
+   'id' => "\$",
+   # True iff %MACRO contains all the macros we want to trace.
+   'valid' => "\$",
+   # The include path.
+   'path' => '@',
+   # The set of input files.
+   'input' => '@',
+   # The set of macros currently traced.
+   'macro' => '%',
+  );
+
+
+# Serialize a request or all the current requests.
+sub marshall($)
+{
+  my ($caller) = @_;
+  my $res = '';
+
+  # CALLER is an object: instance method.
+  my $marshall = Data::Dumper->new ([$caller]);
+  $marshall->Indent(2)->Terse(0);
+  $res = $marshall->Dump . "\n";
+
+  return $res;
+}
+
+
+# includes_p ($SELF, @MACRO)
+# --------------------------
+# Does this request covers all the @MACRO.
+sub includes_p
+{
+  my ($self, @macro) = @_;
+
+  foreach (@macro)
+    {
+      return 0
+       if ! exists ${$self->macro}{$_};
+    }
+  return 1;
+}
+
+
+=head1 SEE ALSO
+
+L<Autom4te::C4che>
+
+=head1 HISTORY
+
+Written by Akim Demaille E<lt>F<akim@freefriends.org>E<gt>.
+
+=cut
+
+
+
+1; # for require
+
+### 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: