You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Dave Rolsky <au...@urth.org> on 2001/02/01 07:09:57 UTC

Apache::test patch

This patch attempts to make the module smarter about finding a potential
httpd binary to use for the tests.

It also removes a doubled slash in a path '/foo/bar//baz' that was
occuring in the module dirs.


-dave

--- /usr/src/misc/mod_perl-1.25/lib/Apache/test.pm	Fri Dec 22 00:17:51 2000
+++ ./test.pm	Thu Feb  1 00:06:17 2001
@@ -104,11 +104,12 @@
     my $pkg = shift;

     print("\nFor testing purposes, please give the full path to an httpd\n",
-	  "with mod_perl enabled.  The path defaults to \$ENV{APACHE}, if present.");
+	  "with mod_perl enabled.  The path defaults to \$ENV{APACHE},\n",
+	  "if present (and that binary has mod_perl).");

     my %conf;

-    my $httpd = $ENV{'APACHE'} || which('apache') || which('httpd') || '/usr/lib/httpd/httpd';
+    my $httpd = $pkg->_find_mod_perl_httpd();

     $httpd = _ask("\n", $httpd, 1, '!');
     if ($httpd eq '!') {
@@ -120,15 +121,8 @@
     # Default: search for dynamic dependencies if mod_so is present, don't bother otherwise.
     my $default = (`t/httpd -l` =~ /mod_so\.c/ ? 'y' : 'n');
     if (lc _ask("Search existing config file for dynamic module dependencies?", $default) eq 'y') {
-	my %compiled;
-	for (`t/httpd -V`) {
-	    if (/([\w]+)="(.*)"/) {
-		$compiled{$1} = $2;
-	    }
-	}
-	$compiled{SERVER_CONFIG_FILE} =~ s,^,$compiled{HTTPD_ROOT}/,
-	    unless $compiled{SERVER_CONFIG_FILE} =~ m,^/,;
-
+	my %compiled = $pkg->_get_compilation_params('t/httpd');
+
 	my $file = _ask("  Config file", $compiled{SERVER_CONFIG_FILE}, 1);
 	$conf{modules} = $pkg->_read_existing_conf($file);
     }
@@ -145,6 +139,21 @@
     return %conf;
 }

+sub _get_compilation_params {
+    my ($self, $httpd) = @_;
+
+    my %compiled;
+    for (`$httpd -V`) {
+	if (/([\w]+)="(.*)"/) {
+	    $compiled{$1} = $2;
+	}
+    }
+    $compiled{SERVER_CONFIG_FILE} =~ s,^,$compiled{HTTPD_ROOT}/,
+	unless $compiled{SERVER_CONFIG_FILE} =~ m,^/,;
+
+    return %compiled;
+}
+
 sub _read_existing_conf {
     # Returns some "(Add|Load)Module" config lines, generated from the
     # existing config file and a few must-have modules.
@@ -176,7 +185,7 @@
     }

     # Directories where apache DSOs live.
-    my @module_dirs = map {m,(/\S*/),} @modules;
+    my @module_dirs = map {m,(/\S*)/,} @modules;

     # Finally compute the directives to load modules that need to be loaded.
  MODULE:
@@ -204,12 +213,43 @@
     return {map {lc($_) => 1} map /(\S+)\.c/, @l};
 }

-# Find an executable in the PATH.
-sub which {
-    foreach (map { "$_/$_[0]" } split /:/, $ENV{PATH}) {
-	next unless m,^/,;
-	return $_ if -x;
+sub _find_mod_perl_httpd {
+    my ($self) = @_;
+
+    foreach ( $ENV{'APACHE'},
+	      '/usr/local/apache/bin/httpd',
+	      '/usr/local/apache_mp/bin/httpd',
+	      '/opt/apache/bin/httpd',
+	      $self->_which('httpd'),
+	      $self->_which('apache'),
+	    ) {
+	return $_ if -x $_ && $self->_has_mod_perl($_);
     }
+}
+
+sub _has_mod_perl {
+    my ($self, $httpd) = @_;
+
+    foreach ( `$httpd -l` )  {
+	return 1 if /mod_perl\.c/;
+    }
+
+    my %compiled = $self->_get_compilation_params($httpd);
+
+    if ($compiled{SERVER_CONFIG_FILE}) {
+	local *SERVER_CONF;
+	open SERVER_CONF, $compiled{SERVER_CONFIG_FILE} or die "Couldn't open $compiled{SERVER_CONFIG_FILE}: $!";
+	my @lines = grep {!m/^\s*\#/} <SERVER_CONF>;
+	close SERVER_CONF;
+
+	return 1 if grep { /mod_perl/ } grep /^\s*(Add|Load)Module/, @lines;
+    }
+
+    return 0;
+}
+
+sub _which {
+    return grep {-x $_} map { "$_/$_[1]" } split /:/, $ENV{PATH};
 }

 sub test {



Re: Apache::test patch

Posted by Dave Rolsky <au...@urth.org>.
On Thu, 1 Feb 2001, Ken Williams wrote:

> I kind of feel like we should blindly use $ENV{APACHE} if it's there,
> because I just made up the variable for this purpose, and if the user
> sets it, we shouldn't argue.  It would be mysterious if you set APACHE
> to something, and then Makefile.PL defaults to use something else
> without telling you why.

That's fine with me.

> But I don't feel very strongly about it.
>
> What *would* be nice, though, is to check the user-typed response for
> the presence of mod_perl, and give an appropriate error message if it's
> missing.

Doh, I meant to add that too.  I'll add that (and the other change you
suggested) and resend the patch.


-dave

/*==================
www.urth.org
We await the New Sun
==================*/


Re: Apache::test patch

Posted by Dave Rolsky <au...@urth.org>.
On Thu, 1 Feb 2001, Ken Williams wrote:

> I kind of feel like we should blindly use $ENV{APACHE} if it's there,
> because I just made up the variable for this purpose, and if the user
> sets it, we shouldn't argue.  It would be mysterious if you set APACHE
> to something, and then Makefile.PL defaults to use something else
> without telling you why.

Ok, now it does respect this, but only the first time through.  If you
stick with your choice and it turns out to not have mod_perl it'll poke
through the filesystem a bit to try to find something.  Seems like the
best of all worlds to me.

> What *would* be nice, though, is to check the user-typed response for
> the presence of mod_perl, and give an appropriate error message if it's
> missing.

Added this.

>   sub _has_mod_perl {
>       my ($self, $httpd) = @_;
>
>       return 1 if `$httpd -l` =~ /mod_perl\.c/;

Added this too


--- /usr/src/misc/mod_perl-1.25/lib/Apache/test.pm	Fri Dec 22 00:17:51 2000
+++ ./test.pm	Thu Feb  1 00:47:54 2001
@@ -108,27 +108,32 @@

     my %conf;

-    my $httpd = $ENV{'APACHE'} || which('apache') || which('httpd') || '/usr/lib/httpd/httpd';
+    my $httpd = $pkg->_find_mod_perl_httpd(1);

-    $httpd = _ask("\n", $httpd, 1, '!');
-    if ($httpd eq '!') {
-	print "Skipping.\n";
-	return;
-    }
+    my $found;
+    do
+    {
+	$httpd = _ask("\n", $httpd, 1, '!');
+	if ($httpd eq '!') {
+	    print "Skipping.\n";
+	    return;
+	}
+
+	if ($pkg->_httpd_has_mod_perl($httpd)) {
+	    $found = 1;
+	} else {
+	    warn("$httpd does not appear to have been compiled with\n",
+		 "mod_perl as a static or dynamic module\n");
+	    $httpd = $pkg->_find_mod_perl_httpd(0);
+	}
+    } until ($found);
     system "$Config{lns} $httpd t/httpd";

     # Default: search for dynamic dependencies if mod_so is present, don't bother otherwise.
     my $default = (`t/httpd -l` =~ /mod_so\.c/ ? 'y' : 'n');
     if (lc _ask("Search existing config file for dynamic module dependencies?", $default) eq 'y') {
-	my %compiled;
-	for (`t/httpd -V`) {
-	    if (/([\w]+)="(.*)"/) {
-		$compiled{$1} = $2;
-	    }
-	}
-	$compiled{SERVER_CONFIG_FILE} =~ s,^,$compiled{HTTPD_ROOT}/,
-	    unless $compiled{SERVER_CONFIG_FILE} =~ m,^/,;
-
+	my %compiled = $pkg->_get_compilation_params('t/httpd');
+
 	my $file = _ask("  Config file", $compiled{SERVER_CONFIG_FILE}, 1);
 	$conf{modules} = $pkg->_read_existing_conf($file);
     }
@@ -145,6 +150,21 @@
     return %conf;
 }

+sub _get_compilation_params {
+    my ($self, $httpd) = @_;
+
+    my %compiled;
+    for (`$httpd -V`) {
+	if (/([\w]+)="(.*)"/) {
+	    $compiled{$1} = $2;
+	}
+    }
+    $compiled{SERVER_CONFIG_FILE} =~ s,^,$compiled{HTTPD_ROOT}/,
+	unless $compiled{SERVER_CONFIG_FILE} =~ m,^/,;
+
+    return %compiled;
+}
+
 sub _read_existing_conf {
     # Returns some "(Add|Load)Module" config lines, generated from the
     # existing config file and a few must-have modules.
@@ -176,7 +196,7 @@
     }

     # Directories where apache DSOs live.
-    my @module_dirs = map {m,(/\S*/),} @modules;
+    my @module_dirs = map {m,(/\S*)/,} @modules;

     # Finally compute the directives to load modules that need to be loaded.
  MODULE:
@@ -204,12 +224,42 @@
     return {map {lc($_) => 1} map /(\S+)\.c/, @l};
 }

-# Find an executable in the PATH.
-sub which {
-    foreach (map { "$_/$_[0]" } split /:/, $ENV{PATH}) {
-	next unless m,^/,;
-	return $_ if -x;
+sub _find_mod_perl_httpd {
+    my ($self, $respect_env) = @_;
+
+    return $ENV{'APACHE'} if $ENV{'APACHE'} && $respect_env;
+
+    foreach ( '/usr/local/apache/bin/httpd',
+	      '/usr/local/apache_mp/bin/httpd',
+	      '/opt/apache/bin/httpd',
+	      $self->_which('httpd'),
+	      $self->_which('apache'),
+	    ) {
+	return $_ if -x $_ && $self->_httpd_has_mod_perl($_);
     }
+}
+
+sub _httpd_has_mod_perl {
+    my ($self, $httpd) = @_;
+
+    return 1 if `$httpd -l` =~ /mod_perl\.c/;
+
+    my %compiled = $self->_get_compilation_params($httpd);
+
+    if ($compiled{SERVER_CONFIG_FILE}) {
+	local *SERVER_CONF;
+	open SERVER_CONF, $compiled{SERVER_CONFIG_FILE} or die "Couldn't open $compiled{SERVER_CONFIG_FILE}: $!";
+	my @lines = grep {!m/^\s*\#/} <SERVER_CONF>;
+	close SERVER_CONF;
+
+	return 1 if grep { /mod_perl/ } grep /^\s*(Add|Load)Module/, @lines;
+    }
+
+    return 0;
+}
+
+sub _which {
+    return grep {-x $_} map { "$_/$_[1]" } split /:/, $ENV{PATH};
 }

 sub test {


Re: Apache::test patch

Posted by Ken Williams <ke...@forum.swarthmore.edu>.
Looks good to me in general.  Below are some nitpicks (I'm probably
getting notorious for these).

autarch@urth.org (Dave Rolsky) wrote:
>     print("\nFor testing purposes, please give the full path to an httpd\n",
>-	  "with mod_perl enabled.  The path defaults to \$ENV{APACHE}, if present.");
>+	  "with mod_perl enabled.  The path defaults to \$ENV{APACHE},\n",
>+	  "if present (and that binary has mod_perl).");

I kind of feel like we should blindly use $ENV{APACHE} if it's there,
because I just made up the variable for this purpose, and if the user
sets it, we shouldn't argue.  It would be mysterious if you set APACHE
to something, and then Makefile.PL defaults to use something else
without telling you why.

But I don't feel very strongly about it.

What *would* be nice, though, is to check the user-typed response for
the presence of mod_perl, and give an appropriate error message if it's
missing.


>+sub _has_mod_perl {
>+    my ($self, $httpd) = @_;
>+
>+    foreach ( `$httpd -l` )  {
>+	return 1 if /mod_perl\.c/;
>+    }

Might as well just do:

  sub _has_mod_perl {
      my ($self, $httpd) = @_;

      return 1 if `$httpd -l` =~ /mod_perl\.c/;



  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  ken@forum.swarthmore.edu                            The Math Forum