--- loncom/build/lpml_parse.pl 2001/09/18 13:18:33 1.12 +++ loncom/build/lpml_parse.pl 2001/11/17 18:35:21 1.19 @@ -5,6 +5,11 @@ # May 2001 # 06/19/2001,06/20,06/24 - 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: lpml_parse.pl,v 1.19 2001/11/17 18:35:21 harris41 Exp $ +### ############################################################################### ## ## @@ -14,6 +19,8 @@ ## 3. First pass through (grab distribution-specific information) ## ## 4. Second pass through (parse out what is not necessary) ## ## 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) ## ## ## ############################################################################### @@ -79,9 +86,11 @@ if (@ARGV) { $sourceroot=~s/\/$//; $targetroot=~s/\/$//; +my $logcmd='| tee -a WARNINGS'; + my $invocation; # --------------------------------------------------- Record program invocation -if ($mode eq 'install') { +if ($mode eq 'install' or $mode eq 'configinstall' or $mode eq 'build') { $invocation=(<{textify}={ build => \&format_build, status => \&format_status, dependencies => \&format_dependencies, + buildlink => \&format_buildlink, glob => \&format_glob, sourcedir => \&format_sourcedir, filenames => \&format_filenames, @@ -301,6 +312,9 @@ while ($token = $parser->get_tag('lpml') } exit; +# ---------- Functions (most all just format contents of different markup tags) + +# ------------------------ Final output at end of markup parsing and formatting sub end { if ($mode eq 'html') { return "
THE END\n"; @@ -329,11 +343,21 @@ sub format_lpml { 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 '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') { - $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 .= "\n"; + $lpml .= "\n".$invocation; $lpml .= "SHELL=\"/bin/sh\"\n\n"; } else { @@ -348,10 +372,8 @@ sub format_targetroot { if ($mode eq 'html') { return $targetroot="\n
TARGETROOT: $text"; } - elsif ($mode eq 'install') { - return '# TARGET INSTALL LOCATION is "'.$targetroot."\"\n"; - } - elsif ($mode eq 'build') { + elsif ($mode eq 'install' or $mode eq 'build' or + $mode eq 'configinstall') { return '# TARGET INSTALL LOCATION is "'.$targetroot."\"\n"; } else { @@ -366,10 +388,8 @@ sub format_sourceroot { if ($mode eq 'html') { return $sourceroot="\n
SOURCEROOT: $text"; } - elsif ($mode eq 'install') { - return '# SOURCE CODE LOCATION IS "'.$sourceroot."\"\n";; - } - elsif ($mode eq 'build') { + elsif ($mode eq 'install' or $mode eq 'build' or + $mode eq 'configinstall') { return '# SOURCE CODE LOCATION IS "'.$sourceroot."\"\n";; } else { @@ -654,7 +674,8 @@ sub format_files { elsif ($mode eq 'configinstall') { return "\n".'configfiles: '. join(' ',@configall). - "\n\n".$text; + "\n\n".$text. + "\n\nalwaysrun:\n\n"; } elsif ($mode eq 'build') { my $binfo; @@ -662,23 +683,39 @@ sub format_files { my $command2; my @deps; 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'; $command=~s/\/([^\/]*)$//; $command2="cd $command; sh ./$1;\\"; my $depstring; + my $depstring2="\t\t\@echo '';\\\n"; + my $olddep; foreach my $dep (@deps) { + unless ($olddep) { + $olddep=$deps[$#deps]; + } $depstring.="\telif !(test -r $command/$dep);\\\n"; $depstring.="\t\tthen echo ". - "\"**** LON-CAPA WARNING **** missing the file: ". - "$command/$dep\";\\\n"; + "\"**** WARNING **** missing the file: ". + "$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". "\t\@if !(echo \"\");\\\n\t\tthen echo ". - "\"**** LON-CAPA WARNING **** Strange shell. ". - "Check your path settings.\";\\\n". + "\"**** WARNING **** Strange shell. ". + "Check your path settings.\"$logcmd;\\\n". $depstring. "\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". $text. @@ -714,6 +751,7 @@ sub format_file { $file=''; $source=''; $target=''; $categoryname=''; $description=''; $note=''; $build=''; $status=''; $dependencies=''; my $text=&trim($parser->get_text('/file')); + my $buildtest; if ($source) { $parser->get_tag('/file'); if ($mode eq 'html') { @@ -723,30 +761,82 @@ sub format_file { "\nEND FILE"); } elsif ($mode eq 'install' && $categoryname ne 'conf') { - return "\t".'@test -e '.$sourceroot.'/'.$source. - ' && install '. - $categoryhash{$categoryname}.' '. - $sourceroot.'/'.$source.' '. - $targetroot.'/'.$target. - ' || echo "**** LON-CAPA WARNING '. - '**** CVS source file does not exist: '.$sourceroot.'/'. - $source.'"'."\n"; + if ($build) { + my $bi=$sourceroot.'/'.$source.';'.$build.';'. + $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.=<get_text('/buildlink')); + if ($text) { + $parser->get_tag('/buildlink'); + $buildlink=$sourceroot.'/'.$text; + } + return ''; +} # ------------------------------------------------------- Format status section sub format_status { my @tokeninfo=@_; @@ -933,3 +1034,74 @@ sub htmlsafe { sub trim { 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