Allow setting http-proxy settings.

Right now this will be utilized for anything needing libwww-perl
(kde_projects.xml download, tarball snapshots), and will be propagated
to subprocesses via http_proxy environment variable, unless that
variable is already set.

Tested by using a simple HTTP proxy utilizing HTTP::Proxy from CPAN.

Implements wish 305411.

BUG:305411
FIXED-IN:1.16
wilder
Michael Pyne 14 years ago
parent b6f17bdd47
commit da098bebfd
  1. 18
      doc/index.docbook
  2. 27
      kdesrc-build

@ -1832,6 +1832,24 @@ different module sets.</para></tip>
</entry>
</row>
<row id="conf-http-proxy">
<entry>http-proxy</entry>
<entry>Module setting overrides global</entry>
<entry><para>This option, if set, uses the specified URL as a proxy server to use for
any HTTP network communications (for example, when downloading snapshots for
new modules, or the <link linkend="kde-projects-module-sets">KDE project
database</link>).</para>
<para>In addition, &kdesrc-build; will try to ensure that the tools it depends
on also use that proxy server, if possible, by setting the
<envar>http_proxy</envar> environment variable to the indicated server,
<emphasis>if that environment variable is not already set</emphasis>.</para>
<para>This option was introduced with &kdesrc-build; 1.16.</para>
</entry>
</row>
<row id="conf-install-after-build">
<entry>install-after-build</entry>
<entry>Module setting overrides global</entry>

@ -833,11 +833,11 @@ EOF
#
# First parameter: URL of link to download (i.e. http://kdesrc-build.kde.org/foo.tbz2)
# Second parameter: Filename to save as (i.e. $ENV{HOME}/blah.tbz2)
# Third parameter: URL of a proxy to use (undef or empty means proxy as set in environment)
# Return value is 0 for failure, non-zero for success.
sub download_file
{
my $url = shift;
my $filename = shift;
my ($url, $filename, $proxy) = @_;
my $ua = LWP::UserAgent->new(timeout => 30);
@ -845,6 +845,15 @@ EOF
# my custom coding anymore.
$ua->agent("kdesrc-build $versionNum ");
if ($proxy) {
whisper ("Using proxy $proxy for FTP, HTTP downloads");
$ua->proxy(['http', 'ftp'], $proxy);
}
else {
whisper ("Using proxy as determined by environment");
$ua->env_proxy();
}
whisper ("Downloading g[$filename] from g[$url]");
my $response = $ua->mirror($url, $filename);
@ -1591,6 +1600,7 @@ EOF
"disable-agent-check" => 0, # If true we don't check on ssh-agent
"do-not-compile" => "",
"git-repository-base" => {}, # Base path template for use multiple times.
"http-proxy" => '', # Proxy server to use for HTTP.
"install-after-build" => 1, # Default to true
"kdedir" => "$ENV{HOME}/kde",
"kde-languages" => "",
@ -1737,6 +1747,13 @@ EOF
# Get ready for logged output.
ksb::Debug::setLogFile($self->getLogDirFor($self) . '/build-log');
# Propagate HTTP proxy through environment unless overridden.
if ((my $proxy = $self->getOption('http-proxy')) &&
!defined $ENV{'http_proxy'})
{
$self->queueEnvironmentVariable('http_proxy', $proxy);
}
}
# Clears the list of environment variables to set for log_command runs.
@ -2768,7 +2785,7 @@ EOF
my $tmpdir = File::Spec->tmpdir() // "/tmp";
$filename = "$tmpdir/$filename"; # Make absolute
if (!download_file($tarball, $filename)) {
if (!download_file($tarball, $filename, $module->getOption('http-proxy'))) {
error ("Unable to download snapshot for module r[$module]");
return 0;
}
@ -6483,7 +6500,7 @@ sub ensure_projects_xml_present
my $updating = grep { /^update$/ } (@{$ctx->phases()});
if (!pretending() && $updating) {
info (" * Downloading projects.kde.org project database...");
$result = download_file($url, $file);
$result = download_file($url, $file, $ctx->getOption('http-proxy'));
}
elsif (! -e $file) {
note (" * Downloading projects.kde.org project database (will not be saved in pretend mode)...");
@ -6493,7 +6510,7 @@ sub ensure_projects_xml_present
# file.
(undef, $file) = tempfile('kde_projectsXXXXXX',
SUFFIX=>'.xml', TMPDIR=>1, UNLINK=>0);
$result = download_file($url, $file);
$result = download_file($url, $file, $ctx->getOption('http-proxy'));
open ($fileHandleResult, '<', $file) or croak_runtime("Unable to open KDE Project database $file: $!");
}
else {

Loading…
Cancel
Save