Diff for /loncom/build/lpml_parse.pl between versions 1.11 and 1.14

version 1.11, 2001/09/17 20:44:38 version 1.14, 2001/11/05 02:57:21
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 - Scott Harrison
   
 ###############################################################################  ###############################################################################
 ##                                                                           ##  ##                                                                           ##
Line 14 Line 16
 ## 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 220  my $target; Line 224  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 229  my @links; Line 234  my @links;
 my %categoryhash;  my %categoryhash;
   
 my @buildall;  my @buildall;
   my @buildinfo;
   
   my @configall;
   
 # Make new parser with distribution specific input  # Make new parser with distribution specific input
 undef $parser;  undef $parser;
Line 274  $parser->{textify}={ Line 282  $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 298  while ($token = $parser->get_tag('lpml') Line 307  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 326  sub format_lpml { Line 338  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 '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";
  $lpml .= "SHELL=\"/bin/sh\"\n\n";   $lpml .= "SHELL=\"/bin/sh\"\n\n";
Line 648  sub format_files { Line 662  sub format_files {
  return "\n".'files:'."\n".$text.   return "\n".'files:'."\n".$text.
     "\n".'links:'."\n".join('',@links);      "\n".'links:'."\n".join('',@links);
     }      }
       elsif ($mode eq 'configinstall') {
    return "\n".'configfiles: '.
    join(' ',@configall).
    "\n\n".$text.
    "\n\nalwaysrun:\n\n";
       }
     elsif ($mode eq 'build') {      elsif ($mode eq 'build') {
  my $binfo;   my $binfo;
  my $tword;   my $tword;
  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\";\\\n";
    $depstring.="\t\ttest -e $source || test -e $target || echo ".
       "'**** ERROR **** neither source=$source nor target=".
       "$target exist and they cannot be built';\\\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 -B $command/$olddep $target ||  ECODE=\$\$?; } && { [ \$\$ECODE != \"2\" ] || echo \"**** WARNING **** dependency $command/$olddep is newer than target file $target; SOMETHING MAY BE WRONG\"; };\\\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.\";\\\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 706  sub format_file { Line 742  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 715  sub format_file { Line 752  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;
    my ($source2,$command,$trigger,@deps)=split(/\;/,$bi);
    $tword=''; $tword=' alwaysrun' if $trigger eq 'always run'; 
    $command=~s/\/([^\/]*)$//;
    $command2="cd $command; sh ./$1;\\";
    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)'); DEP="1"; \\
    [ -n DEP ] && { perl filecompare.pl -B $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";; \\
    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"; exit; \\
   END
                   $buildtest.=<<END if $depstring;
    elif !(test -e "${sourceroot}/${source}"); then \\
   $depstring
   END
                   $buildtest.=<<END;
    fi
   END
       }
               my $bflag='-b';
               $bflag='-g' if $dependencies or $buildlink;
       return <<END;
   $buildtest \@if !(test -e "${sourceroot}/${source}"); then \\
    echo "**** WARNING **** CVS source file does not exist: ${sourceroot}/${source}"; \\
    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" && 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 "**** LON-CAPA WARNING '.
   # '**** CVS source file does not exist: '.$sourceroot.'/'.
   # $source.'"'."\n";
    }
    elsif ($mode eq 'configinstall' && $categoryname eq 'conf') {
       push @configall,$targetroot.'/'.$target;
       return $targetroot.'/'.$target.': alwaysrun'."\n".
    "\t".'@echo -n ""; ECODE=0 && { perl filecompare.pl -G '.$sourceroot.'/'.$source.' '.$targetroot.'/'.$target.' || ECODE=$$?; } && { [ $$ECODE != "2" ] || (install '.$categoryhash{$categoryname}.' '.
  $sourceroot.'/'.$source.' '.   $sourceroot.'/'.$source.' '.
  $targetroot.'/'.$target.   $targetroot.'/'.$target.'.lpmlnewconf'.
  ' || echo "**** LON-CAPA WARNING '.   ' && echo "*** CONFIGURATION FILE CHANGE ***" && echo "'.
  '**** CVS source file does not exist: '.$sourceroot.'/'.   'You likely need to compare contents of '.
  $source.'"'."\n";   ''.$targetroot.'/'.$target.' with the new '.
                   ''.$targetroot.'/'.$target.'.lpmlnewconf"'.
    ";) };\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 783  sub format_fileglob { Line 881  sub format_fileglob {
  elsif ($mode eq 'install') {   elsif ($mode eq 'install') {
     return "\t".'install '.      return "\t".'install '.
  $categoryhash{$categoryname}.' '.   $categoryhash{$categoryname}.' '.
  $sourceroot.'/'.$sourcedir.'[^CVS]'.$glob.' '.   $sourceroot.'/'.$sourcedir.'[^C][^V][^S]'.$glob.' '.
  $targetroot.'/'.$targetdir.'.'."\n";   $targetroot.'/'.$targetdir.'.'."\n";
  }   }
  else {   else {
Line 848  sub format_build { Line 946  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 913  sub htmlsafe { Line 1022  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)

Removed from v.1.11  
changed lines
  Added in v.1.14


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