-
Notifications
You must be signed in to change notification settings - Fork 16
/
run
executable file
·220 lines (194 loc) · 5.94 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/perl
# Copyright (c) 2011,2012,2013,2014 SUSE Linux Products GmbH
# Copyright (c) 2015 SUSE LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
use strict;
use solv;
use Data::Dump;
my %reason_by_name = map { $_ => eval "\$solv::Solver::SOLVER_REASON_$_" } qw(
UNRELATED
UNIT_RULE
KEEP_INSTALLED
RESOLVE_JOB
UPDATE_INSTALLED
CLEANDEPS_ERASE
RESOLVE
WEAKDEP
RESOLVE_ORPHAN
RECOMMENDED
SUPPLEMENTED
);
my %reason_by_id = map { $reason_by_name{$_} => $_ } keys %reason_by_name;
use Getopt::Long;
my $exit_status;
my %options;
Getopt::Long::Configure("no_ignore_case");
GetOptions (
\%options,
"lock=s@",
"softlock=s@",
"weaken=s@",
"explain=s",
"list",
"size",
"no-recommends",
"arch=s",
"packs=s@",
"repo=s@",
) or die "invalid arguments\n";
$options{'weaken'} = [ split(/,/, join(',', @{$options{'weaken'}})) ] if $options{'weaken'};
$options{'softlock'} = [ split(/,/, join(',', @{$options{'softlock'}})) ] if $options{'softlock'};
$options{'lock'} = [ split(/,/, join(',', @{$options{'lock'}})) ] if $options{'lock'};
$options{'repo'} = [ split(/,/, join(',', @{$options{'repo'}})) ] if $options{'repo'};
$options{'packs'} = [ split(/,/, join(',', @{$options{'packs'}})) ] if $options{'packs'};
$options{'size'} = 1 unless ($options{'explain'} || $options{'list'});
unless ($options{'arch'}) {
my $arch = 'x86_64';
warn "--arch not specified, assuming $arch\n";
$options{'arch'} = $arch;
}
my $pool = solv::Pool->new();
#$pool->set_debuglevel(1);
$pool->setarch ($options{'arch'});
my %repos;
for my $name (@{$options{'repo'}}) {
my $repo = $pool->add_repo($name);
$repo->add_solv ($name.'.solv');
$repos{$name} = $repo;
}
$pool->addfileprovides();
# will segfault if you don't do that!
$pool->createwhatprovides();
# Create Solver
my $solver = $pool->Solver();
# Create Request
#my $job = $pool->create_request();
my @jobs;
for my $p (@{$options{'packs'}}) {
my ($n, $r) = split(/@/, $p, 2);
my $sel = $pool->select($n, $solv::Selection::SELECTION_NAME);
$sel->filter($repos{$r}->Selection()) if $r;
die "can't find $p\n" if $sel->isempty();
my @jj = $sel->jobs($solv::Job::SOLVER_INSTALL);
for my $j (@jj) {
push @jobs, $j;
}
}
for my $p (@{$options{'lock'}}) {
my $sel = $pool->select($p, $solv::Selection::SELECTION_NAME);
my @jj = $sel->jobs($solv::Job::SOLVER_LOCK);
for my $j (@jj) {
push @jobs, $j;
}
}
for my $p (@{$options{'softlock'}}) {
my $sel = $pool->select($p, $solv::Selection::SELECTION_NAME);
my @jj = $sel->jobs($solv::Job::SOLVER_LOCK | $solv::Job::SOLVER_WEAK);
for my $j (@jj) {
push @jobs, $j;
}
}
# XXX: doesn't seem to work
for my $p (@{$options{'weaken'}}) {
my $sel = $pool->select($p, $solv::Selection::SELECTION_NAME);
my @jj = $sel->jobs($solv::Job::SOLVER_WEAKENDEPS);
for my $j (@jj) {
push @jobs, $j;
}
}
# Solve the jobs
$solver->set_flag($solv::Solver::SOLVER_FLAG_IGNORE_RECOMMENDED, 1) if $options{'no-recommends'};
my @problems = $solver->solve(\@jobs);
if (@problems) {
print "+++ PROBLEMS: +++\n";
for my $p (@problems) {
print $p->str, "\n";
for my $sol ($p->solutions) {
print " + solution\n";
for my $elem ($sol->elements) {
print " - ", $elem->str, "\n";
}
}
}
$exit_status = 1;
}
my $trans = $solver->transaction();
sub sortbysize
{
my $sa = $a->lookup_num($solv::SOLVABLE_INSTALLSIZE) || 0;
my $sb = $b->lookup_num($solv::SOLVABLE_INSTALLSIZE) || 0;
my $ret = $sa <=> $sb;
unless ($ret) {
$sa = $a->{"name"} || "";
$sb = $b->{"name"} || "";
$ret = $sa cmp $sb;
}
return $ret;
}
sub sortbyname
{
my $sa = $a->{"name"} || "";
my $sb = $b->{"name"} || "";
$sa cmp $sb;
}
# Print packages to install
my @a = $trans->newsolvables();
if ($options{'explain'}) {
for my $s (@a) {
next if $options{'explain'} ne '__weak__' && $s->{'name'} ne $options{'explain'};
my ($type, $rule) = $solver->describe_decision($s);
if ($type == $reason_by_name{WEAKDEP}) {
eval {
my @q = $solver->describe_weakdep_decision($s);
while(my ($why, $p1, $dep) = @{shift @q||[]}) {
printf "%s %s %s via '%s'\n", $p1->{name}, $reason_by_id{$why}, $s->{name}, $dep->str;
}
};
if ($@) {
print $@;
warn "explaining weak deps doesn't work yet https://github.com/openSUSE/libsolv/issues/91";
}
} elsif ($options{'explain'} ne '__weak__') {
dd $type, $rule->info()->problemstr();
}
}
} elsif ($options{'list'}) {
for my $solvable (sort sortbyname @a) {
my $name = $solvable->{"name"};
printf "%s\n", $name;
}
} elsif ($options{'size'}) {
for my $solvable (sort sortbysize @a) {
my $name = $solvable->{"name"};
my $arch = $solvable->{"arch"};
my $ver = $solvable->{"evr"};
my $size = $solvable->lookup_num($solv::SOLVABLE_INSTALLSIZE) || 0;
printf "%8d %s\n", $size/1024, $name;
}
}
if ($options{'size'}) {
# get install size
my $size = $trans->calc_installsizechange();
printf "%8d %s\n", $size, "TOTAL";
}
# my $transaction = $solver->transaction();
# my $sizechange = $transaction->sizechange();
# print "SIZE CHANGE: $sizechange kB\n";
exit($exit_status);