Blame SOURCES/perl.prov.stack

f523ca
#!/usr/bin/perl
f523ca
f523ca
# RPM (and it's source code) is covered under two separate licenses.
f523ca
f523ca
# The entire code base may be distributed under the terms of the GNU
f523ca
# General Public License (GPL), which appears immediately below.
f523ca
# Alternatively, all of the source code in the lib subdirectory of the
f523ca
# RPM source code distribution as well as any code derived from that
f523ca
# code may instead be distributed under the GNU Library General Public
f523ca
# License (LGPL), at the choice of the distributor. The complete text
f523ca
# of the LGPL appears at the bottom of this file.
f523ca
f523ca
# This alternative is allowed to enable applications to be linked
f523ca
# against the RPM library (commonly called librpm) without forcing
f523ca
# such applications to be distributed under the GPL.
f523ca
f523ca
# Any questions regarding the licensing of RPM should be addressed to
f523ca
# Erik Troan <ewt@redhat.com>.
f523ca
f523ca
# a simple script to print the proper name for perl libraries.
f523ca
f523ca
# To save development time I do not parse the perl grammar but
f523ca
# instead just lex it looking for what I want.  I take special care to
f523ca
# ignore comments and pod's.
f523ca
f523ca
# it would be much better if perl could tell us the proper name of a
f523ca
# given script.
f523ca
f523ca
# The filenames to scan are either passed on the command line or if
f523ca
# that is empty they are passed via stdin.
f523ca
f523ca
# If there are lines in the file which match the pattern
f523ca
#      (m/^\s*\$VERSION\s*=\s+/)
f523ca
# then these are taken to be the version numbers of the modules.
f523ca
# Special care is taken with a few known idioms for specifying version
f523ca
# numbers of files under rcs/cvs control.
f523ca
f523ca
# If there are strings in the file which match the pattern
f523ca
#     m/^\s*\$RPM_Provides\s*=\s*["'](.*)['"]/i
f523ca
# then these are treated as additional names which are provided by the
f523ca
# file and are printed as well.
f523ca
f523ca
# I plan to rewrite this in C so that perl is not required by RPM at
f523ca
# build time.
f523ca
f523ca
# by Ken Estes Mail.com kestes@staff.mail.com
f523ca
f523ca
my $perl_prov ="__SCL_NAME__";
f523ca
f523ca
if ("@ARGV") {
f523ca
  foreach (@ARGV) {
f523ca
    process_file($_);
f523ca
  }
f523ca
} else {
f523ca
f523ca
  # notice we are passed a list of filenames NOT as common in unix the
f523ca
  # contents of the file.
f523ca
f523ca
  foreach (<>) {
f523ca
    process_file($_);
f523ca
  }
f523ca
}
f523ca
f523ca
f523ca
foreach $module (sort keys %require) {
f523ca
  if (length($require{$module}) == 0) {
f523ca
    print "$perl_prov($module)\n";
f523ca
  } else {
f523ca
f523ca
    # I am not using rpm3.0 so I do not want spaces around my
f523ca
    # operators. Also I will need to change the processing of the
f523ca
    # $RPM_* variable when I upgrade.
f523ca
f523ca
    print "$perl_prov($module) = $require{$module}\n";
f523ca
  }
f523ca
}
f523ca
f523ca
exit 0;
f523ca
f523ca
f523ca
f523ca
sub process_file {
f523ca
f523ca
  my ($file) = @_;
f523ca
  chomp $file;
f523ca
f523ca
  if (!open(FILE, $file)) {
f523ca
    warn("$0: Warning: Could not open file '$file' for reading: $!\n");
f523ca
    return;
f523ca
  }
f523ca
f523ca
  my ($package, $version, $incomment, $inover) = ();
f523ca
f523ca
  while (<FILE>) {
f523ca
f523ca
    # skip the documentation
f523ca
f523ca
    # we should not need to have item in this if statement (it
f523ca
    # properly belongs in the over/back section) but people do not
f523ca
    # read the perldoc.
f523ca
f523ca
    if (m/^=(head[1-4]|pod|for|item)/) {
f523ca
      $incomment = 1;
f523ca
    }
f523ca
f523ca
    if (m/^=(cut)/) {
f523ca
      $incomment = 0;
f523ca
      $inover = 0;
f523ca
    }
f523ca
f523ca
    if (m/^=(over)/) {
f523ca
      $inover = 1;
f523ca
    }
f523ca
f523ca
    if (m/^=(back)/) {
f523ca
      $inover = 0;
f523ca
    }
f523ca
f523ca
    if ($incomment || $inover) {
f523ca
       next;
f523ca
    }
f523ca
f523ca
    # skip the data section
f523ca
    if (m/^__(DATA|END)__$/) {
f523ca
      last;
f523ca
    }
f523ca
f523ca
    # not everyone puts the package name of the file as the first
f523ca
    # package name so we report all namespaces except some common
f523ca
    # false positives as if they were provided packages (really ugly).
f523ca
f523ca
    if (m/^\s*package\s+([_:a-zA-Z0-9]+)\s*;/) {
f523ca
      $package = $1;
f523ca
      undef $version;
f523ca
      if ($package eq 'main') {
f523ca
        undef $package;
f523ca
      } else {
f523ca
        # If $package already exists in the $require hash, it means
f523ca
        # the package definition is broken up over multiple blocks.
f523ca
        # In that case, don't stomp a previous $VERSION we might have
f523ca
        # found.  (See BZ#214496.)
f523ca
        $require{$package} = undef unless (exists $require{$package});
f523ca
      }
f523ca
    }
f523ca
f523ca
    # after we found the package name take the first assignment to
f523ca
    # $VERSION as the version number. Exporter requires that the
f523ca
    # variable be called VERSION so we are safe.
f523ca
f523ca
    # here are examples of VERSION lines from the perl distribution
f523ca
f523ca
    #FindBin.pm:$VERSION = $VERSION = sprintf("%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/);
f523ca
    #ExtUtils/Install.pm:$VERSION = substr q$Revision: 1.9 $, 10;
f523ca
    #CGI/Apache.pm:$VERSION = (qw$Revision: 1.9 $)[1];
f523ca
    #DynaLoader.pm:$VERSION = $VERSION = "1.03";     # avoid typo warning
f523ca
    #General.pm:$Config::General::VERSION = 2.33;
f523ca
    #
f523ca
    # or with the new "our" pragma you could (read will) see:
f523ca
    #
f523ca
    #    our $VERSION = '1.00'
f523ca
    if ($package && m/^\s*(our\s+)?\$(\Q$package\E::)?VERSION\s*=\s+/) {
f523ca
f523ca
      # first see if the version string contains the string
f523ca
      # '$Revision' this often causes bizarre strings and is the most
f523ca
      # common method of non static numbering.
f523ca
f523ca
      if (m/\$Revision: (\d+[.0-9]+)/) {
f523ca
        $version = $1;
f523ca
      } elsif (m/['"]?(\d+[.0-9]+)['"]?/) {
f523ca
f523ca
        # look for a static number hard coded in the script
f523ca
f523ca
        $version = $1;
f523ca
      }
f523ca
      $require{$package} = $version;
f523ca
    }
f523ca
f523ca
    # Allow someone to have a variable that defines virtual packages
f523ca
    # The variable is called $RPM_Provides.  It must be scoped with
f523ca
    # "our", but not "local" or "my" (just would not make sense).
f523ca
    #
f523ca
    # For instance:
f523ca
    #
f523ca
    #     $RPM_Provides = "blah bleah"
f523ca
    #
f523ca
    # Will generate provides for "blah" and "bleah".
f523ca
    #
f523ca
    # Each keyword can appear multiple times.  Don't
f523ca
    #  bother with datastructures to store these strings,
f523ca
    #  if we need to print it print it now.
f523ca
f523ca
    if (m/^\s*(our\s+)?\$RPM_Provides\s*=\s*["'](.*)['"]/i) {
f523ca
      foreach $_ (split(/\s+/, $2)) {
f523ca
        print "$_\n";
f523ca
      }
f523ca
    }
f523ca
f523ca
  }
f523ca
f523ca
  close(FILE) ||
f523ca
    die("$0: Could not close file: '$file' : $!\n");
f523ca
f523ca
  return;
f523ca
}