forked from Morganamilo/paru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolver.rs
157 lines (138 loc) · 4.8 KB
/
resolver.rs
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
use crate::config::{Alpm, Config, LocalRepos, YesNoAll, YesNoAllTree};
use crate::fmt::color_repo;
use crate::util::{get_provider, NumberMenu};
use crate::RaurHandle;
use std::io::{stdin, stdout, BufRead, Write};
use aur_depends::{Flags, PkgbuildRepo, Resolver};
use raur::Cache;
use tr::tr;
pub fn flags(config: &mut Config) -> aur_depends::Flags {
let mut flags = Flags::new();
if config.args.has_arg("needed", "needed") {
flags |= Flags::NEEDED;
}
if config.args.count("u", "sysupgrade") > 1 {
flags |= Flags::ENABLE_DOWNGRADE;
}
if config.args.count("d", "nodeps") > 0 {
flags |= Flags::NO_DEP_VERSION;
config.mflags.push("-d".to_string());
}
if config.args.count("d", "nodeps") > 1 {
flags |= Flags::NO_DEPS;
}
if config.no_check {
flags.remove(Flags::CHECK_DEPENDS);
}
if !config.mode.pkgbuild() {
flags &= !Flags::PKGBUILDS;
}
if !config.mode.aur() {
flags &= !Flags::AUR;
}
if !config.mode.repo() {
flags &= !Flags::REPO;
}
match config.provides {
YesNoAll::Yes => flags |= Flags::TARGET_PROVIDES | Flags::MISSING_PROVIDES,
YesNoAll::No => flags.remove(
Flags::PROVIDES
| Flags::MISSING_PROVIDES
| Flags::TARGET_PROVIDES
| Flags::NON_TARGET_PROVIDES,
),
YesNoAll::All => flags |= Flags::PROVIDES,
}
if config.interactive {
flags.remove(Flags::TARGET_PROVIDES);
}
if config.repos != LocalRepos::None || config.rebuild == YesNoAllTree::Tree || config.chroot {
flags |= Flags::RESOLVE_SATISFIED_PKGBUILDS;
}
log::debug!("AUR depends flags: {:?}", flags);
flags
}
pub fn resolver<'a, 'b>(
config: &Config,
alpm: &'a Alpm,
raur: &'b RaurHandle,
cache: &'b mut Cache,
pkgbuild_repos: Vec<PkgbuildRepo<'a>>,
flags: Flags,
) -> Resolver<'a, 'b, RaurHandle> {
let devel_suffixes = config.devel_suffixes.clone();
let c = config.color;
let no_confirm = config.no_confirm;
let mut resolver = aur_depends::Resolver::new(alpm, cache, raur, flags)
.pkgbuild_repos(pkgbuild_repos)
.custom_aur_namespace(Some(config.aur_namespace().to_string()))
.is_devel(move |pkg| devel_suffixes.iter().any(|suff| pkg.ends_with(suff)))
.group_callback(move |groups| {
let total: usize = groups.iter().map(|g| g.group.packages().len()).sum();
let mut pkgs = Vec::new();
println!(
"{} {} {}:",
c.action.paint("::"),
c.bold.paint(tr!("There are {} members in group", total)),
c.group.paint(groups[0].group.name()),
);
let mut repo = String::new();
for group in groups {
if group.db.name() != repo {
repo = group.db.name().to_string();
println!(
"{} {} {}",
c.action.paint("::"),
c.bold.paint(tr!("Repository")),
color_repo(c.enabled, group.db.name())
);
print!(" ");
}
let mut n = 1;
for pkg in group.group.packages() {
print!("{}) {} ", n, pkg.name());
n += 1;
}
}
print!("{}", tr!("\n\nEnter a selection (default=all): "));
let _ = stdout().lock().flush();
let stdin = stdin();
let mut stdin = stdin.lock();
let mut input = String::new();
input.clear();
if !no_confirm {
let _ = stdin.read_line(&mut input);
}
let menu = NumberMenu::new(input.trim());
let mut n = 1;
for pkg in groups.iter().flat_map(|g| g.group.packages()) {
if menu.contains(n, "") {
pkgs.push(pkg);
}
n += 1;
}
pkgs
});
if !config.args.has_arg("u", "sysupgrade") {
resolver = resolver.provider_callback(move |dep, pkgs| {
let prompt = tr!(
"There are {n} providers available for {pkg}:",
n = pkgs.len(),
pkg = dep
);
println!("{} {}", c.action.paint("::"), c.bold.paint(prompt));
println!(
"{} {} {}:",
c.action.paint("::"),
c.bold.paint(tr!("Repository")),
color_repo(c.enabled, "AUR")
);
print!(" ");
for (n, pkg) in pkgs.iter().enumerate() {
print!("{}) {} ", n + 1, pkg);
}
get_provider(pkgs.len(), no_confirm)
});
}
resolver
}