#!/usr/bin/perl -w # # Simple build and uninstall for plugin packages. Resides in the plugins # submodules directory. Normally used by developers for installing, # but also has uninstall target. # # The list of files to be installed is determined from the table in # the plugin topic. # # The following targets should always exist: # 1. build - check that everything is perl # 2. test - run unit tests # 3. install - install on local installation defined by $TWIKI_HOME # 4. release - package a release zip # package Build; # THE INTERESTING STUFF IS AT THE BOTTOM use strict; use File::Copy; use vars qw( $basedir ); BEGIN { $basedir = "../../../.."; unshift @INC, $basedir; } ############################################################### # Plugin specific stuff my $plugin = "WebDAVPlugin"; ############################################################### # Fairly standard stuff chdir($basedir); $basedir = `pwd`; chop($basedir); # lib/TWiki/Plugins, where the plugin.pm file lives my $lib_plugins="lib/TWiki/Plugins"; # where the plugin sub-modules live my $plugin_libdir="${lib_plugins}/${plugin}"; # where data files live my $data_twiki="data/TWiki"; # the root of the name of data files for this plugin my $data_twiki_plugin="${data_twiki}/$plugin"; # the file list, determined from the plugin topic my $file_list = ""; open(PF, "<$basedir/$data_twiki_plugin.txt") || die "Plugin topic $basedir/$data_twiki_plugin.txt missing"; my $line; while ($line = ) { if ($line =~ /^\s+\|\s+==(.*?)==\s+\|\s*(.*?)\s*\|$/o) { my $file = $1; my $descr = $2; $file =~ s/%TOPIC%/$plugin/go; $file_list .= " $file"; } elsif ($line =~ /^\s+\|\s+\*Module\*\s+\|\s+\*Type\*\s+\|\s+\*Version\*\s+\|/o) { $line = ; while ($line =~ /^\s+\|(.*)\|(.*)\|(.*)\|(.*)\|$/) { my $mod = $1; my $type = $2; if ($type =~ /perl/o) { eval "use $mod"; if ($@) { warn "Perl module $mod not found"; } } $line = ; } } } close(PF); chdir("$basedir/$plugin_libdir"); my $test_files = `find test -name '*.pm' -print` . " " . `find test -name '*.pl' -print` . " " . `find test -name '*.c' -print`; ############################################################## # Very standard stuff my $print = 0; sub cd { my $file = shift; print "cd $file\n"; if (!$print) { chdir($file) || die "Failed to cd to $file"; } } sub rm { my $file = shift; print "rm $file\n"; unless ($print) { unlink($file) || warn "Failed to delete $file"; } } sub run_tests { my $module = shift; sys_action("perl -w -I../../../.. -I. TestRunner.pl $module"); } sub sys_action { my $cmd = shift; print "$cmd\n"; unless ($print) { system($cmd); die "Failed to $cmd\n" if ($?); } } ############################################################### # The bit that actually does the work my $n = 1; my $done = 0; while ($n <= $#ARGV) { if ($ARGV[$n] eq "-d") { $print = 1; } else { print "Execute target $ARGV[$n]\n"; eval "target_$ARGV[$n]"; $done++; } $n++; } unless ($done) { print "Execute target test\n"; target_test(); } sub target_tests_zip { target_test(); cd("$basedir/$plugin_libdir/"); rm("test.zip"); sys_action("zip -r test.zip $test_files"); } ############################################################### # The vaguely interesting stuff sub target_build { # does nothing } sub target_test { target_build(); cd("$basedir/$plugin_libdir/test"); sys_action("make"); run_tests("PermissionsTest"); } sub target_release { target_tests_zip(); cd("$basedir"); rm("$plugin.zip"); sys_action("zip $plugin.zip $file_list"); } sub target_install { target_build(); my $twiki = $ENV{TWIKI_HOME}; die "TWIKI_HOME not set" unless $twiki; foreach my $file (split(/\s+/, $file_list)) { File::Copy::copy("$basedir/$file", "$twiki/$file"); chmod(0755, "$twiki/$file"); } } sub target_uninstall { my $twiki = $ENV{TWIKI_HOME}; die "TWIKI_HOME not set" unless $twiki; foreach my $file (split(/\s+/, $file_list)) { unlink("$twiki/$file"); } } 1;