Skip to content

Commit

Permalink
[backend] add overwriteconstraints to repserver
Browse files Browse the repository at this point in the history
Add overwriteconstraints call to bs_repserver function checkconstraints.

As this is used by bs_repserver and bs_dispatcher move the
function to BSDispatcher/Constraints.pm
  • Loading branch information
lethliel authored and M0ses committed Jul 26, 2021
1 parent efe8d39 commit b19183d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 36 deletions.
37 changes: 37 additions & 0 deletions src/backend/BSDispatcher/Constraints.pm
Expand Up @@ -160,6 +160,41 @@ sub mergeconstraints {
return $con;
}

sub overwrite {
my ($dst, $src) = @_;
for my $k (sort keys %$src) {
next if $k eq "conditions";
my $d = $src->{$k};
if (!exists($dst->{$k}) || !ref($d) || ref($d) ne 'HASH') {
$dst->{$k} = $d;
} else {
overwrite($dst->{$k}, $d);
}
}
}

sub overwriteconstraints {
my ($info, $constraints) = @_;
# use condition specific constraints to merge it properly
for my $o (@{$constraints->{'overwrite'}||[]}) {
next unless $o && $o->{'conditions'};
if ($o->{'conditions'}->{'arch'}) {
next unless grep {$_ eq $info->{'arch'}} @{$o->{'conditions'}->{'arch'}};
}
if ($o->{'conditions'}->{'package'}) {
my $packagename = $info->{'package'};
my $shortpackagename = $info->{'package'};
$shortpackagename =~ s/\..*//;
next unless grep {$_ eq $packagename or $_ eq $shortpackagename} @{$o->{'conditions'}->{'package'}};
}
# conditions are matching, overwrite...
$constraints = BSUtil::clone($constraints);
overwrite($constraints, $o);
}
return $constraints;
}


# constructs a data object from a list and a XML::Structured dtd
sub list2struct {
my ($dtd, $list, $job) = @_;
Expand Down Expand Up @@ -243,4 +278,6 @@ sub list2struct {
return $top;
}



1;
38 changes: 2 additions & 36 deletions src/backend/bs_dispatch
Expand Up @@ -118,7 +118,7 @@ if ($options->{'testconstraints'}) {
my $constraints;
if ($constraints_file) {
$constraints = readxml($constraints_file, $BSXML::constraints);
$constraints = overwriteconstraints($jobinfo, $constraints);
$constraints = BSDispatcher::Constraints::overwriteconstraints($jobinfo, $constraints);
}
if ($constraintsprj_file) {
my @lines = map { [ split(' ', $_) ] } split("\n", readstr($constraintsprj_file));
Expand Down Expand Up @@ -402,40 +402,6 @@ sub staleness {
return $ret;
}

sub overwrite {
my ($dst, $src) = @_;
for my $k (sort keys %$src) {
next if $k eq "conditions";
my $d = $src->{$k};
if (!exists($dst->{$k}) || !ref($d) || ref($d) ne 'HASH') {
$dst->{$k} = $d;
} else {
overwrite($dst->{$k}, $d);
}
}
}

sub overwriteconstraints {
my ($info, $constraints) = @_;
# use condition specific constraints to merge it properly
for my $o (@{$constraints->{'overwrite'}||[]}) {
next unless $o && $o->{'conditions'};
if ($o->{'conditions'}->{'arch'}) {
next unless grep {$_ eq $info->{'arch'}} @{$o->{'conditions'}->{'arch'}};
}
if ($o->{'conditions'}->{'package'}) {
my $packagename = $info->{'package'};
my $shortpackagename = $info->{'package'};
$shortpackagename =~ s/\..*//;
next unless grep {$_ eq $packagename or $_ eq $shortpackagename} @{$o->{'conditions'}->{'package'}};
}
# conditions are matching, overwrite...
$constraints = BSUtil::clone($constraints);
overwrite($constraints, $o);
}
return $constraints;
}

sub getconstraints {
my ($info, $constraintsmd5) = @_;
my $param = {
Expand Down Expand Up @@ -1276,7 +1242,7 @@ while (1) {
delete($constraintscache{$constraintsmd5}) if $constraints->[0] < $now;
next;
}
$constraints = overwriteconstraints($info, $constraints) if $constraints->{'overwrite'};
$constraints = BSDispatcher::Constraints::overwriteconstraints($info, $constraints) if $constraints->{'overwrite'};
}
if ($info->{'prjconfconstraint'}) {
my @l = map { [ split(' ', $_) ] } @{$info->{'prjconfconstraint'}};
Expand Down
4 changes: 4 additions & 0 deletions src/backend/bs_repserver
Expand Up @@ -4066,6 +4066,10 @@ sub checkconstraints {
$constraints = readxml("$uploaddir/$$", $BSXML::constraints);
unlink("$uploaddir/$$");
}
my $info;
$info->{'package'} = $packid;
$info->{'arch'} = $arch;
$constraints = BSDispatcher::Constraints::overwriteconstraints($info, $constraints) if $constraints->{'overwrite'};
my $pconf = BSRPC::rpc("$BSConfig::srcserver/getconfig", undef, "project=$projid", "repository=$repoid");
my $bconf = Build::read_config($arch, [ split("\n", $pconf)] );
my @list = map { [ split(' ', $_) ] } @{$bconf->{'constraint'}};
Expand Down

0 comments on commit b19183d

Please sign in to comment.