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
use std::sync::Arc;
use async_recursion::async_recursion;
use futures::future::join_all;
use itertools::Itertools;
use tokio::sync::mpsc::UnboundedSender;
use crate::{
build::BuildBehaviour,
config::Config,
lockfile::{
LocalPackageId, LocalPackageSpec, Lockfile, LockfilePermissions, OptState, PinnedState,
},
progress::{MultiProgress, Progress},
remote_package_db::RemotePackageDB,
rockspec::Rockspec,
tree,
};
use super::{Download, PackageInstallSpec, RemoteRockDownload, SearchAndDownloadError};
#[derive(Clone, Debug)]
pub(crate) struct PackageInstallData {
pub build_behaviour: BuildBehaviour,
pub pin: PinnedState,
pub opt: OptState,
pub downloaded_rock: RemoteRockDownload,
pub spec: LocalPackageSpec,
pub entry_type: tree::EntryType,
}
#[async_recursion]
pub(crate) async fn get_all_dependencies<P>(
tx: UnboundedSender<PackageInstallData>,
packages: Vec<PackageInstallSpec>,
package_db: Arc<RemotePackageDB>,
lockfile: Arc<Lockfile<P>>,
config: &Config,
progress: Arc<Progress<MultiProgress>>,
) -> Result<Vec<LocalPackageId>, SearchAndDownloadError>
where
P: LockfilePermissions + Send + Sync + 'static,
{
join_all(
packages
.into_iter()
// Exclude packages that are already installed
.filter(
|PackageInstallSpec {
package,
build_behaviour,
..
}| {
*build_behaviour == BuildBehaviour::Force
|| lockfile.has_rock(package, None).is_none()
},
)
.map(
// NOTE: we propagate build_behaviour, pin and opt to all dependencies
|PackageInstallSpec {
package,
build_behaviour,
pin,
opt,
entry_type,
constraint,
source,
}| {
let config = config.clone();
let tx = tx.clone();
let package_db = Arc::clone(&package_db);
let progress = Arc::clone(&progress);
let lockfile = Arc::clone(&lockfile);
tokio::spawn(async move {
let bar = progress.map(|p| p.new_bar());
let downloaded_rock = if let Some(source) = source {
RemoteRockDownload::from_package_req_and_source_spec(
package.clone(),
source,
)?
} else {
Download::new(&package, &config, &bar)
.package_db(&package_db)
.download_remote_rock()
.await?
};
let constraint = constraint.unwrap_or(package.version_req().clone().into());
let dependencies = downloaded_rock
.rockspec()
.dependencies()
.current_platform()
.iter()
.map(|dep| {
// If we're forcing a rebuild, retain the `EntryType`
// of existing dependencies
let entry_type = if build_behaviour == BuildBehaviour::Force
&& lockfile.has_rock(dep.package_req(), None).is_some_and(
|installed_rock| {
lockfile.is_entrypoint(&installed_rock.id())
},
) {
tree::EntryType::Entrypoint
} else {
tree::EntryType::DependencyOnly
};
PackageInstallSpec::new(dep.package_req().clone(), entry_type)
.build_behaviour(build_behaviour)
.pin(pin)
.opt(opt)
.maybe_source(dep.source().clone())
.build()
})
.collect_vec();
let dependencies = get_all_dependencies(
tx.clone(),
dependencies,
package_db,
lockfile,
&config,
progress,
)
.await?;
let rockspec = downloaded_rock.rockspec();
let local_spec = LocalPackageSpec::new(
rockspec.package(),
rockspec.version(),
constraint,
dependencies,
&pin,
&opt,
rockspec.binaries(),
);
let install_spec = PackageInstallData {
build_behaviour,
pin,
opt,
spec: local_spec.clone(),
downloaded_rock,
entry_type,
};
tx.send(install_spec).unwrap();
Ok::<_, SearchAndDownloadError>(local_spec.id())
})
},
),
)
.await
.into_iter()
.flatten()
.try_collect()
}