Diff for /loncom/build/lpml_parse.pl between versions 1.13 and 1.20

version 1.13, 2001/10/30 22:27:32 version 1.20, 2001/11/17 21:30:28
Line 5 Line 5
 # May 2001  # May 2001
 # 06/19/2001,06/20,06/24 - Scott Harrison  # 06/19/2001,06/20,06/24 - Scott Harrison
 # 9/5/2001,9/6,9/7,9/8 - Scott Harrison  # 9/5/2001,9/6,9/7,9/8 - Scott Harrison
   # 9/17,9/18 - Scott Harrison
   # 11/4,11/5,11/6,11/7,11/16 - Scott Harrison
   #
   # $Id$
   ###
   
 ###############################################################################  ###############################################################################
 ##                                                                           ##  ##                                                                           ##
Line 14 Line 19
 ## 3. First pass through (grab distribution-specific information)            ##  ## 3. First pass through (grab distribution-specific information)            ##
 ## 4. Second pass through (parse out what is not necessary)                  ##  ## 4. Second pass through (parse out what is not necessary)                  ##
 ## 5. Third pass through (translate markup according to specified mode)      ##  ## 5. Third pass through (translate markup according to specified mode)      ##
   ## 6. Functions (most all just format contents of different markup tags)     ##
   ## 7. POD (plain old documentation, CPAN style)                              ##
 ##                                                                           ##  ##                                                                           ##
 ###############################################################################  ###############################################################################
   
Line 79  if (@ARGV) { Line 86  if (@ARGV) {
 $sourceroot=~s/\/$//;  $sourceroot=~s/\/$//;
 $targetroot=~s/\/$//;  $targetroot=~s/\/$//;
   
   my $logcmd='| tee -a WARNINGS';
   
 my $invocation;  my $invocation;
 # --------------------------------------------------- Record program invocation  # --------------------------------------------------- Record program invocation
 if ($mode eq 'install') {  if ($mode eq 'install' or $mode eq 'configinstall' or $mode eq 'build') {
     $invocation=(<<END);      $invocation=(<<END);
 # Invocation: STDINPUT | lpml_parse.pl  # Invocation: STDINPUT | lpml_parse.pl
 #             1st argument (mode) is: $mode  #             1st argument (mode) is: $mode
Line 220  my $target; Line 229  my $target;
 my $source;  my $source;
 my $note;  my $note;
 my $build;  my $build;
   my $buildlink;
 my $commands;  my $commands;
 my $command;  my $command;
 my $status;  my $status;
Line 277  $parser->{textify}={ Line 287  $parser->{textify}={
     build => \&format_build,      build => \&format_build,
     status => \&format_status,      status => \&format_status,
     dependencies => \&format_dependencies,      dependencies => \&format_dependencies,
       buildlink => \&format_buildlink,
     glob => \&format_glob,      glob => \&format_glob,
     sourcedir => \&format_sourcedir,      sourcedir => \&format_sourcedir,
     filenames => \&format_filenames,      filenames => \&format_filenames,
Line 301  while ($token = $parser->get_tag('lpml') Line 312  while ($token = $parser->get_tag('lpml')
 }  }
 exit;  exit;
   
   # ---------- Functions (most all just format contents of different markup tags)
   
   # ------------------------ Final output at end of markup parsing and formatting
 sub end {  sub end {
     if ($mode eq 'html') {      if ($mode eq 'html') {
  return "<br />THE END\n";   return "<br />THE END\n";
Line 329  sub format_lpml { Line 343  sub format_lpml {
  print ' by Scott Harrison 2001'."\n";   print ' by Scott Harrison 2001'."\n";
  print '# This file was automatically generated on '.`date`;   print '# This file was automatically generated on '.`date`;
  print "\n".$invocation;   print "\n".$invocation;
    $lpml .= "SHELL=\"/bin/bash\"\n\n";
       }
       elsif ($mode eq 'configinstall') {
    print '# LPML configuration file targets (configinstall).'."\n";
    print '# Linux Packaging Markup Language,';
    print ' by Scott Harrison 2001'."\n";
    print '# This file was automatically generated on '.`date`;
    print "\n".$invocation;
    $lpml .= "SHELL=\"/bin/bash\"\n\n";
     }      }
     elsif ($mode eq 'build') {      elsif ($mode eq 'build') {
  $lpml = "# Dynamic Makefile generated by LON-CAPA build process\n";   $lpml = "# LPML build targets. Linux Packaging Markup Language,";
    $lpml .= ' by Scott Harrison 2001'."\n";
  $lpml .= '# This file was automatically generated on '.`date`;   $lpml .= '# This file was automatically generated on '.`date`;
  $lpml .= "\n";   $lpml .= "\n".$invocation;
  $lpml .= "SHELL=\"/bin/sh\"\n\n";   $lpml .= "SHELL=\"/bin/sh\"\n\n";
     }      }
     else {      else {
Line 348  sub format_targetroot { Line 372  sub format_targetroot {
     if ($mode eq 'html') {      if ($mode eq 'html') {
  return $targetroot="\n<br />TARGETROOT: $text";   return $targetroot="\n<br />TARGETROOT: $text";
     }      }
     elsif ($mode eq 'install') {      elsif ($mode eq 'install' or $mode eq 'build' or
  return '# TARGET INSTALL LOCATION is "'.$targetroot."\"\n";     $mode eq 'configinstall') {
     }  
     elsif ($mode eq 'build') {  
  return '# TARGET INSTALL LOCATION is "'.$targetroot."\"\n";   return '# TARGET INSTALL LOCATION is "'.$targetroot."\"\n";
     }      }
     else {      else {
Line 366  sub format_sourceroot { Line 388  sub format_sourceroot {
     if ($mode eq 'html') {      if ($mode eq 'html') {
  return $sourceroot="\n<br />SOURCEROOT: $text";   return $sourceroot="\n<br />SOURCEROOT: $text";
     }      }
     elsif ($mode eq 'install') {      elsif ($mode eq 'install' or $mode eq 'build' or
  return '# SOURCE CODE LOCATION IS "'.$sourceroot."\"\n";;     $mode eq 'configinstall') {
     }  
     elsif ($mode eq 'build') {  
  return '# SOURCE CODE LOCATION IS "'.$sourceroot."\"\n";;   return '# SOURCE CODE LOCATION IS "'.$sourceroot."\"\n";;
     }      }
     else {      else {
Line 654  sub format_files { Line 674  sub format_files {
     elsif ($mode eq 'configinstall') {      elsif ($mode eq 'configinstall') {
  return "\n".'configfiles: '.   return "\n".'configfiles: '.
  join(' ',@configall).   join(' ',@configall).
  "\n\n".$text;   "\n\n".$text.
    "\n\nalwaysrun:\n\n";
     }      }
     elsif ($mode eq 'build') {      elsif ($mode eq 'build') {
  my $binfo;   my $binfo;
Line 662  sub format_files { Line 683  sub format_files {
  my $command2;   my $command2;
  my @deps;   my @deps;
  foreach my $bi (@buildinfo) {   foreach my $bi (@buildinfo) {
     my ($source,$command,$trigger,@deps)=split(/\;/,$bi);      my ($target,$source,$command,$trigger,@deps)=split(/\;/,$bi);
     $tword=''; $tword=' alwaysrun' if $trigger eq 'always run';       $tword=''; $tword=' alwaysrun' if $trigger eq 'always run'; 
     $command=~s/\/([^\/]*)$//;      $command=~s/\/([^\/]*)$//;
     $command2="cd $command; sh ./$1;\\";      $command2="cd $command; sh ./$1;\\";
     my $depstring;      my $depstring;
       my $depstring2="\t\t\@echo '';\\\n";
       my $olddep;
     foreach my $dep (@deps) {      foreach my $dep (@deps) {
    unless ($olddep) {
       $olddep=$deps[$#deps];
    }
  $depstring.="\telif !(test -r $command/$dep);\\\n";   $depstring.="\telif !(test -r $command/$dep);\\\n";
  $depstring.="\t\tthen echo ".   $depstring.="\t\tthen echo ".
  "\"**** LON-CAPA WARNING **** missing the file: ".   "\"**** WARNING **** missing the file: ".
          "$command/$dep\";\\\n";           "$command/$dep\"$logcmd;\\\n";
    $depstring.="\t\ttest -e $source || test -e $target || echo ".
       "'**** ERROR **** neither source=$source nor target=".
       "$target exist and they cannot be built'$logcmd;\\\n";
    $depstring.="\t\tmake -f Makefile.build ${source}___DEPS;\\\n";
    if ($olddep) {
       $depstring2.="\t\tECODE=0;\\\n";
       $depstring2.="\t\t! test -e $source && test -r $command/$olddep &&".
    " { perl filecompare.pl -b2 $command/$olddep $target ||  ECODE=\$\$?; } && { [ \$\$ECODE != \"2\" ] || echo \"**** WARNING **** dependency $command/$olddep is newer than target file $target; SOMETHING MAY BE WRONG\"$logcmd; };\\\n";
    }
    $olddep=$dep;
     }      }
     $binfo.="$source: $tword\n".      $binfo.="$source: $tword\n".
  "\t\@if !(echo \"\");\\\n\t\tthen echo ".   "\t\@if !(echo \"\");\\\n\t\tthen echo ".
  "\"**** LON-CAPA WARNING **** Strange shell. ".   "\"**** WARNING **** Strange shell. ".
          "Check your path settings.\";\\\n".           "Check your path settings.\"$logcmd;\\\n".
  $depstring.   $depstring.
  "\telse \\\n\t\t$command2\n\tfi\n\n";   "\telse \\\n\t\t$command2\n\tfi\n\n";
       $binfo.="${source}___DEPS:\n".$depstring2."\t\tECODE=0;\n\n";
  }   }
  return 'all: '.join(' ',@buildall)."\n\n".   return 'all: '.join(' ',@buildall)."\n\n".
          $text.           $text.
Line 714  sub format_file { Line 751  sub format_file {
     $file=''; $source=''; $target=''; $categoryname=''; $description='';      $file=''; $source=''; $target=''; $categoryname=''; $description='';
     $note=''; $build=''; $status=''; $dependencies='';      $note=''; $build=''; $status=''; $dependencies='';
     my $text=&trim($parser->get_text('/file'));      my $text=&trim($parser->get_text('/file'));
       my $buildtest;
     if ($source) {      if ($source) {
  $parser->get_tag('/file');   $parser->get_tag('/file');
  if ($mode eq 'html') {   if ($mode eq 'html') {
Line 723  sub format_file { Line 761  sub format_file {
  "\nEND FILE");   "\nEND FILE");
  }   }
  elsif ($mode eq 'install' && $categoryname ne 'conf') {   elsif ($mode eq 'install' && $categoryname ne 'conf') {
     return "\t".'@test -e '.$sourceroot.'/'.$source.      if ($build) {
  ' && install '.   my $bi=$sourceroot.'/'.$source.';'.$build.';'.
  $categoryhash{$categoryname}.' '.      $dependencies;
  $sourceroot.'/'.$source.' '.   my ($source2,$command,$trigger,@deps)=split(/\;/,$bi);
  $targetroot.'/'.$target.   $tword=''; $tword=' alwaysrun' if $trigger eq 'always run'; 
  ' || echo "**** LON-CAPA WARNING '.   $command=~s/\/([^\/]*)$//;
  '**** CVS source file does not exist: '.$sourceroot.'/'.   $command2="cd $command; sh ./$1;\\";
  $source.'"'."\n";   my $depstring;
    foreach my $dep (@deps) {
       $depstring.=<<END;
    ECODE=0; DEP=''; \\
    test -e $command/$dep || (echo '**** WARNING **** cannot evaluate status of dependency $command/$dep (for building ${sourceroot}/${source} with)'$logcmd); DEP="1"; \\
    [ -n DEP ] && { perl filecompare.pl -b2 $command/$dep ${targetroot}/${target} || ECODE=\$\$?; } || DEP="1"; \\
    case "\$\$ECODE" in \\
    2) echo "**** WARNING **** dependency $command/$dep is newer than target file ${targetroot}/${target}; you may want to run make build"$logcmd;; \\
    esac; \\
   END
    }
                   chomp $depstring;
    $buildtest=<<END;
    \@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
    echo "**** ERROR **** ${sourceroot}/${source} is missing and is also not present at target location ${targetroot}/${target}; you must run make build"$logcmd; exit; \\
   END
                   $buildtest.=<<END if $depstring;
    elif !(test -e "${sourceroot}/${source}"); then \\
   $depstring
   END
                   $buildtest.=<<END;
    fi
   END
       }
               my $bflag='-b1';
               $bflag='-b3' if $dependencies or $buildlink;
       return <<END;
   $buildtest \@if !(test -e "${sourceroot}/${source}") && !(test -e "${targetroot}/${target}"); then \\
    echo "**** ERROR **** CVS source file does not exist: ${sourceroot}/${source} and neither does target: ${targetroot}/${target}"$logcmd; \\
    elif !(test -e "${sourceroot}/${source}"); then \\
    echo "**** WARNING **** CVS source file does not exist: ${sourceroot}/${source}"$logcmd; \\
    else \\
    ECODE=0; \\
    perl filecompare.pl $bflag ${sourceroot}/${source} ${targetroot}/${target} || ECODE=\$\$?; \\
    case "\$\$ECODE" in \\
    1) echo "${targetroot}/${target} is unchanged";; \\
    2) echo "**** WARNING **** target file ${targetroot}/${target} is newer than CVS source; creating ${targetroot}/${target}.lpmlnewfile instead"$logcmd && install -o www -g www -m 0500 ${sourceroot}/${source} ${targetroot}/${target}.lpmlnewfile;; \\
    0) echo "install -o www -g www -m 0500 ${sourceroot}/${source} ${targetroot}/${target}" && install -o www -g www -m 0500 ${sourceroot}/${source} ${targetroot}/${target};; \\
    esac; \\
    fi
   END
   #    return "\t".'@test -e '.$sourceroot.'/'.$source.
   # ' && perl filecompare.pl -b '.$sourceroot.'/'.$source.' '.
   # $targetroot.'/'.$target.
   # ' && install '.
   # $categoryhash{$categoryname}.' '.
   # $sourceroot.'/'.$source.' '.
   # $targetroot.'/'.$target.
   # ' || echo "**** WARNING '.
   # '**** CVS source file does not exist: '.$sourceroot.'/'.
   # $source.'"'."\n";
  }   }
  elsif ($mode eq 'configinstall' && $categoryname eq 'conf') {   elsif ($mode eq 'configinstall' && $categoryname eq 'conf') {
     push @configall,$targetroot.'/'.$target;      push @configall,$targetroot.'/'.$target;
     return $targetroot.'/'.$target.':'."\n".      return $targetroot.'/'.$target.': alwaysrun'."\n".
  "\t".'@install '.$categoryhash{$categoryname}.' '.   "\t".'@echo -n ""; ECODE=0 && { perl filecompare.pl -b4 '.
    $sourceroot.'/'.$source.' '.$targetroot.'/'.$target.
    ' || ECODE=$$?; } && '.
    '{ [ $$ECODE != "2" ] || (install '.
                   $categoryhash{$categoryname}.' '.
  $sourceroot.'/'.$source.' '.   $sourceroot.'/'.$source.' '.
  $targetroot.'/'.$target.'.lpmlnewconf'.   $targetroot.'/'.$target.'.lpmlnewconf'.
  ' && echo "*** CONFIGURATION FILE CHANGE ***" && echo "'.   ' && echo "**** NOTE: CONFIGURATION FILE CHANGE ****"'.
  'You likely need to compare contents of "'.   $logcmd.' && echo "'.
  "$targetroot/$target with the new ".   'You likely need to compare contents of '.
                 "$targetroot/$target.lpmlnewconf".   ''.$targetroot.'/'.$target.' with the new '.
  "\n\n";                  ''.$targetroot.'/'.$target.'.lpmlnewconf"'.
    "$logcmd); } && ".
    '{ [ $$ECODE != "3" ] || (install '.
                   $categoryhash{$categoryname}.' '.
    $sourceroot.'/'.$source.' '.
    $targetroot.'/'.$target.''.
    ' && echo "**** WARNING: NEW CONFIGURATION FILE ADDED ****"'.
    $logcmd.' && echo "'.
    'You likely need to review the contents of '.
    ''.$targetroot.'/'.$target.' to make sure its '.
                   'settings are compatible with your overall system"'.
    "$logcmd); } && ".
    '{ [ $$ECODE != "1" ] || ('.
    'echo "**** ERROR ****"'.
    $logcmd.' && echo "'.
    'Configuration source file does not exist '.
    ''.$sourceroot.'/'.$source.'"'.
    "$logcmd); };\n\n";
  }   }
  elsif ($mode eq 'build' && $build) {   elsif ($mode eq 'build' && $build) {
     push @buildall,$sourceroot.'/'.$source;      push @buildall,$sourceroot.'/'.$source;
     push @buildinfo,$sourceroot.'/'.$source.';'.$build.';'.      push @buildinfo,$targetroot.'/'.$target.';'.$sourceroot.'/'.
    $source.';'.$build.';'.
  $dependencies;   $dependencies;
 #    return '# need to build '.$source.";  #    return '# need to build '.$source.";
  }   }
Line 868  sub format_build { Line 978  sub format_build {
     }      }
     return '';      return '';
 }  }
   # -------------------------------------------------------- Format build section
   sub format_buildlink {
       my @tokeninfo=@_;
       $buildlink='';
       my $text=&trim($parser->get_text('/buildlink'));
       if ($text) {
    $parser->get_tag('/buildlink');
    $buildlink=$sourceroot.'/'.$text;
       }
       return '';
   }
 # ------------------------------------------------------- Format status section  # ------------------------------------------------------- Format status section
 sub format_status {  sub format_status {
     my @tokeninfo=@_;      my @tokeninfo=@_;
Line 933  sub htmlsafe { Line 1054  sub htmlsafe {
 sub trim {  sub trim {
     my ($s)=@_; $s=~s/^\s*//; $s=~s/\s*$//; return $s;      my ($s)=@_; $s=~s/^\s*//; $s=~s/\s*$//; return $s;
 }   } 
   
   # ----------------------------------- POD (plain old documentation, CPAN style)
   
   =head1 NAME
   
   lpml_parse.pl - This is meant to parse files meeting the lpml document type.
   See lpml.dtd.  LPML=Linux Packaging Markup Language.
   
   =head1 SYNOPSIS
   
   Usage is for lpml file to come in through standard input.
   
   =over 4
   
   =item *
   
   1st argument is the mode of parsing.
   
   =item * 
   
   2nd argument is the category permissions to use (runtime or development)
   
   =item *
   
   3rd argument is the distribution
   (default,redhat6.2,debian2.2,redhat7.1,etc).
   
   =item *
   
   4th argument is to manually specify a sourceroot.
   
   =item *
   
   5th argument is to manually specify a targetroot.
   
   =back
   
   Only the 1st argument is mandatory for the program to run.
   
   Example:
   
   cat ../../doc/loncapafiles.lpml |\\
   perl lpml_parse.pl html default /home/sherbert/loncapa /tmp/install
   
   =head1 DESCRIPTION
   
   I am using a multiple pass-through approach to parsing
   the lpml file.  This saves memory and makes sure the server
   will never be overloaded.
   
   =head1 README
   
   I am using a multiple pass-through approach to parsing
   the lpml file.  This saves memory and makes sure the server
   will never be overloaded.
   
   =head1 PREREQUISITES
   
   HTML::TokeParser
   
   =head1 COREQUISITES
   
   =head1 OSNAMES
   
   linux
   
   =head1 SCRIPT CATEGORIES
   
   Packaging/Administrative
   
   =cut

Removed from v.1.13  
changed lines
  Added in v.1.20


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>