Commit e54200ee authored by Michael Pyne's avatar Michael Pyne

env: Do not prepend /bin when {qt,kde}dir is blank.

This fixes #29, where kdesrc-build was aggressively prepending '/bin' to
the PATH if either kdedir or qtdir were unset (and qtdir is unset by
default). This isn't normally an issue but can conflict with user
settings.

Since the desire here is to setup Qt and/or KF5 before system packages,
only perform this prepending if Qt and/or KF5 are actually in use from
kdesrc-build. If those values aren't set then the system should already
be configured to provide in the environment so we shouldn't interfere.

It turns out that both ksb::Module and ksb::BuildContext are already
somewhat testable without a lot of orchestration needed here. I've
verified that the new tests fails without the patch applied, and pass
with this patch applied.
parent 3cc8391c
Pipeline #2966 passed with stage
in 1 minute and 16 seconds
......@@ -642,34 +642,22 @@ sub setupEnvironment
my $self = assert_isa(shift, 'ksb::Module');
my $ctx = $self->buildContext();
my $kdedir = $self->getOption('kdedir');
my $qtdir = $self->getOption('qtdir');
my $qtdir = $self->getOption('qtdir');
my $prefix = $self->installationPath();
# Add global set-envs and context
$self->buildContext()->applyUserEnvironment();
# Avoid moving /usr up in env vars
if ($qtdir ne '/usr') {
my @qt_pkg_config_dirs = ("$qtdir/lib/pkgconfig");
$ctx->prependEnvironmentValue('PKG_CONFIG_PATH', @qt_pkg_config_dirs);
# Ensure the platform libraries we're building can be found, as long as they
# are not the system's own libraries.
for my $platformDir ($qtdir, $kdedir) {
next unless $platformDir; # OK, assume system platform is usable
next if $platformDir eq '/usr'; # Don't 'fix' things if system platform
# manually set
my @qt_ld_dirs = ("$qtdir/lib");
$ctx->prependEnvironmentValue('LD_LIBRARY_PATH', @qt_ld_dirs);
my @qt_path = ("$qtdir/bin");
$ctx->prependEnvironmentValue('PATH', @qt_path);
}
# Avoid moving /usr up in env vars
if ($kdedir ne '/usr') {
my @pkg_config_dirs = ("$kdedir/lib/pkgconfig");
$ctx->prependEnvironmentValue('PKG_CONFIG_PATH', @pkg_config_dirs);
my @ld_dirs = ("$kdedir/lib", $self->getOption('libpath'));
$ctx->prependEnvironmentValue('LD_LIBRARY_PATH', @ld_dirs);
my @path = ("$kdedir/bin", $self->getOption('binpath'));
$ctx->prependEnvironmentValue('PATH', @path);
$ctx->prependEnvironmentValue('PKG_CONFIG_PATH', "$platformDir/lib/pkgconfig");
$ctx->prependEnvironmentValue('LD_LIBRARY_PATH', "$platformDir/lib");
$ctx->prependEnvironmentValue('PATH', "$platformDir/bin");
}
# Build system's environment injection
......
use 5.014;
use strict;
use warnings;
# Test that empty kdedir and/or qtdir do not cause empty /bin settings to be
# configured in environment.
use Test::More;
use ksb::DependencyResolver;
use ksb::BuildContext;
use ksb::Module;
my $ctx = ksb::BuildContext->new;
sub no_bare_bin
{
my @elem = split(':', shift);
return ! (grep { $_ eq '/bin' } @elem);
}
{
my $mod = ksb::Module->new($ctx, 'test');
my $newPath = $ENV{PATH};
$newPath =~ s(^/bin:)()g; # Remove existing bare /bin entries if present
$newPath =~ s(:/bin$)()g;
$newPath =~ s(:/bin:)()g;
local $ENV{PATH} = $newPath;
$ctx->setOption('kdedir', ''); # must be set but empty
$ctx->setOption('qtdir', '/dev/null');
$mod->setupEnvironment();
ok(exists $ctx->{env}->{PATH}, "Entry created for PATH when setting up mod env");
ok(no_bare_bin($ctx->{env}->{PATH}), "/bin wasn't prepended to PATH")
or diag explain $ctx->{env}->{PATH};
}
$ctx->resetEnvironment();
{
my $mod = ksb::Module->new($ctx, 'test');
my $newPath = $ENV{PATH};
$newPath =~ s(^/bin:)()g; # Remove existing bare /bin entries if present
$newPath =~ s(:/bin$)()g;
$newPath =~ s(:/bin:)()g;
local $ENV{PATH} = $newPath;
$ctx->setOption('qtdir', ''); # must be set but empty
$ctx->setOption('kdedir', '/dev/null');
$mod->setupEnvironment();
ok(exists $ctx->{env}->{PATH}, "Entry created for PATH when setting up mod env");
ok(no_bare_bin($ctx->{env}->{PATH}), "/bin wasn't prepended to PATH")
or diag explain $ctx->{env}->{PATH};
}
$ctx->resetEnvironment();
{
my $mod = ksb::Module->new($ctx, 'test');
my $newPath = $ENV{PATH};
$newPath =~ s(^/bin:)()g; # Remove existing bare /bin entries if present
$newPath =~ s(:/bin$)()g;
$newPath =~ s(:/bin:)()g;
local $ENV{PATH} = $newPath;
$ctx->setOption('qtdir', '/dev/null');
$ctx->setOption('kdedir', '/dev/null');
$mod->setupEnvironment();
ok(exists $ctx->{env}->{PATH}, "Entry created for PATH when setting up mod env");
ok(no_bare_bin($ctx->{env}->{PATH}), "/bin wasn't prepended to PATH")
or diag explain $ctx->{env}->{PATH};
}
done_testing();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment