Mailing List Archive

svn commit: r330692 - /spamassassin/trunk/build/mkrules
Author: jm
Date: Thu Nov 3 18:54:38 2005
New Revision: 330692

URL: http://svn.apache.org/viewcvs?rev=330692&view=rev
Log:
rules compiler now will not output sandbox rules if the file fails to lint

Modified:
spamassassin/trunk/build/mkrules

Modified: spamassassin/trunk/build/mkrules
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/build/mkrules?rev=330692&r1=330691&r2=330692&view=diff
==============================================================================
--- spamassassin/trunk/build/mkrules (original)
+++ spamassassin/trunk/build/mkrules Thu Nov 3 18:54:38 2005
@@ -30,6 +30,11 @@
use File::Copy;
use Getopt::Long;

+# use SpamAssassin classes directly, so we can lint rules
+# as we go
+use lib 'lib';
+use Mail::SpamAssassin;
+
use vars qw(
@opt_srcs $opt_out $opt_sandboxout $opt_manifest
$opt_manifestskip
@@ -60,6 +65,7 @@
my $needs_compile = { };
my $current_src;

+
foreach my $src (@opt_srcs) {
if (!-d $src) {
warn "WARNING: unreadable src '$src'\n";
@@ -86,10 +92,35 @@
my $renamed_rules = { };
my $output_files = { };
my $output_file_text = { };
+my $files_to_lint = { };

compile_sorted($needs_compile);
+lint_output_files();
write_output_files();

+sub lint_output_files {
+ foreach my $file (keys %{$files_to_lint}) {
+ my $text = $output_file_text->{file};
+ if (lint_rule_text($text) != 0) {
+ warn "\nERROR: LINT FAILED, suppressing output: $file\n\n";
+ delete $output_file_text->{$file};
+ }
+ }
+}
+
+sub lint_rule_text {
+ my ($text) = @_;
+ my $mailsa = Mail::SpamAssassin->new({
+ rules_filename => "./rules",
+ # debug => 1,
+ local_tests_only => 1,
+ dont_copy_prefs => 1,
+ config_text => $text
+ });
+ my $res = $mailsa->lint_rules();
+ return $res; # 0 means good
+}
+
exit;

sub wanted {
@@ -343,9 +374,10 @@
$output_file_text->{$pubfile} .= $text;
}

+ $files_to_lint->{$pubfile} = 1;
+
$copied++;
}
-
print "$f: $copied sandbox rules copied\n";

# ok; file complete. now mark all those rules as "seen"; future
@@ -428,7 +460,7 @@
open (OUT, ">".$pubfile) or die "cannot write to output file '$pubfile'";
print OUT $output_file_text->{$pubfile};
close OUT or die "cannot close output file '$pubfile'";
- print "$pubfile: written\n";
+ # print "$pubfile: written\n"; # too noisy
}
else {
print "$pubfile: no rules promoted\n";