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
//! Utilities for converting a list of packages into a list with the correct build behaviour.
use inquire::Confirm;
use lux_lib::package;
use lux_lib::{
build::BuildBehaviour,
config::Config,
lockfile::{OptState, PinnedState},
operations::install,
tree::{self, InstallTree, Tree},
};
use miette::Result;
pub fn apply_build_behaviour(
package_reqs: Vec<package::Req>,
pin: PinnedState,
force: bool,
tree: &Tree,
config: &Config,
) -> Result<Vec<install::Spec>> {
let lockfile = tree.lockfile()?;
Ok(package_reqs
.into_iter()
.filter_map(|req| {
// Look up any existing entrypoint by name, regardless of version.
let build_behaviour = match lockfile.entrypoint(req.name()) {
Some(existing) => {
let overwrite = force
|| (!config.no_prompt()
&& Confirm::new(&format!(
"Package {}@{} already exists. Overwrite?",
existing.name(),
existing.version()
))
.with_default(false)
.prompt()
.is_ok_and(|overwrite_confirmed| overwrite_confirmed));
overwrite.then_some(BuildBehaviour::Force)
}
// No entrypoint exists, so always force install. This will force dependencies
// designated as entrypoints to be rebuilt, since their layouts may change during
// reinstall.
None => Some(BuildBehaviour::Force),
};
build_behaviour.map(|build_behaviour| {
install::Spec::new(req, tree::EntryType::Entrypoint)
.build_behaviour(build_behaviour)
.pin(pin)
.opt(OptState::Required)
.build()
})
})
.collect())
}