You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2007/10/23 16:57:33 UTC
svn commit: r587529 - /spamassassin/trunk/build/preprocessor
Author: jm
Date: Tue Oct 23 07:57:33 2007
New Revision: 587529
URL: http://svn.apache.org/viewvc?rev=587529&view=rev
Log:
speed up build/preprocessor script to make builds run faster
Modified:
spamassassin/trunk/build/preprocessor
Modified: spamassassin/trunk/build/preprocessor
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/preprocessor?rev=587529&r1=587528&r2=587529&view=diff
==============================================================================
--- spamassassin/trunk/build/preprocessor (original)
+++ spamassassin/trunk/build/preprocessor Tue Oct 23 07:57:33 2007
@@ -51,9 +51,6 @@
use strict;
use warnings;
-use Config;
-use File::Spec;
-
my %modules = ();
my %defines = ();
@@ -87,6 +84,7 @@
$mode = undef unless $mode;
if (defined ($indir) && defined ($outdir) && scalar @infiles > 0) {
+ require File::Spec;
my $fname;
while ($fname = shift @infiles) {
my $in = File::Spec->catfile ($indir, $fname);
@@ -149,13 +147,17 @@
sub do_it {
# The perlpath can be overwritten via -DPERL_BIN=<perlpath>
- my $perl = $Config{'perlpath'};
+ my $perl;
if($defines{'PERL_BIN'} && ($defines{PERL_BIN} ne 'this')) {
$perl = $defines{'PERL_BIN'};
unless(-x $perl) {
warn("No such PERL_BIN: $perl");
}
}
+ else {
+ # use eval so the module is not loaded unless needed; it's slow
+ eval 'use Config; $perl = $Config{"perlpath"};';
+ }
# Warnings are enabled per default
my $perl_warn = ' -w';
@@ -178,19 +180,22 @@
$perl_version = sprintf("%i.%03i%03i", $v[0] || 0, $v[1] || 0, $v[2] || 0);
}
- # Grab active plugin list
- my @plugin_pod = ();
- if (open(INIT, "rules/init.pre")) {
- while (<INIT>) {
- if (/^loadplugin\s+(.*?)\s*$/) {
- push(@plugin_pod, " $1\n");
+ $defines{PLUGIN_POD} = sub {
+
+ # Grab active plugin list
+ my @plugin_pod = ();
+ foreach my $pre (<rules/*.pre>) {
+ if (open(INIT, $pre)) {
+ while (<INIT>) {
+ if (/^loadplugin\s+(.*?)\s*$/) { push(@plugin_pod, " $1\n"); }
+ }
+ close(INIT);
}
}
- close(INIT);
- }
- $defines{PLUGIN_POD} = join('', sort @plugin_pod);
+ return join('', sort @plugin_pod);
+ };
- my $l = 1;
+ my $towrite = '';
while (<FOOIN>) {
$_ = pack("C0A*", $_); # turn off UTF8-ness
@@ -202,21 +207,24 @@
}
}
- # Variable replacement
- if ($modules{'vars'}) {
- # Replace all @@VARS@@
- while (/\@\@([A-Z][A-Z0-9_]*)\@\@/) {
- my $d = $defines{$1} || '';
- s/\@\@$1\@\@/$d/g;
- }
- }
+ $towrite .= $_;
+ }
- # Sharpbang (#!) replacement (see also ExtUtils::MY->fixin)
- if ($modules{'sharpbang'} && ($l == 1)) {
- s/^#!.*perl.*$/#!${perl}${perl_taint}${perl_warn}/;
+ # Sharpbang (#!) replacement (see also ExtUtils::MY->fixin)
+ if ($modules{'sharpbang'}) {
+ $towrite =~ s/^#![^\n]*perl[^\n]*\n/#!${perl}${perl_taint}${perl_warn}\n/;
+ }
+
+ # Variable replacement (do in one invocation)
+ if ($modules{'vars'}) {
+ # Replace all @@VARS@@
+ while ($towrite =~ /\@\@([A-Z][A-Z0-9_]*)\@\@/) {
+ my $what = $1;
+ my $d = $defines{$what} || '';
+ if (ref($d) =~ /^CODE/) { $d = $d->(); }
+ $towrite =~ s/\@\@${what}\@\@/$d/g;
}
-
- print FOOOUT $_;
- $l++;
}
+
+ print FOOOUT $towrite;
}