Skip to content

Commit 1cacf9d

Browse files
committed
Handle basic build from source cases
Signed-off-by: J Robert Ray <[email protected]>
1 parent e3502b0 commit 1cacf9d

File tree

4 files changed

+247
-29
lines changed

4 files changed

+247
-29
lines changed

crates/spk-solve/src/cdcl_solver/mod.rs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ mod pkg_request_version_set;
66
mod spk_provider;
77

88
use std::borrow::Cow;
9-
use std::collections::{BTreeMap, BTreeSet, HashMap};
9+
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
1010
use std::sync::Arc;
1111

1212
use pkg_request_version_set::{SpkSolvable, SyntheticComponent};
1313
use spk_provider::SpkProvider;
14-
use spk_schema::ident::{InclusionPolicy, PinPolicy, PkgRequest, RangeIdent};
14+
use spk_schema::ident::{InclusionPolicy, LocatedBuildIdent, PinPolicy, PkgRequest, RangeIdent};
1515
use spk_schema::ident_component::Component;
1616
use spk_schema::prelude::{HasVersion, Named, Versioned};
1717
use spk_schema::version_range::VersionFilter;
@@ -31,17 +31,25 @@ mod cdcl_solver_tests;
3131
pub struct Solver {
3232
repos: Vec<Arc<RepositoryHandle>>,
3333
requests: Vec<Request>,
34+
binary_only: bool,
3435
_validators: Cow<'static, [Validators]>,
36+
build_from_source_trail: HashSet<LocatedBuildIdent>,
3537
}
3638

3739
impl Solver {
3840
pub fn new(repos: Vec<Arc<RepositoryHandle>>, validators: Cow<'static, [Validators]>) -> Self {
3941
Self {
4042
repos,
4143
requests: Vec::new(),
44+
binary_only: true,
4245
_validators: validators,
46+
build_from_source_trail: HashSet::new(),
4347
}
4448
}
49+
50+
pub(crate) fn set_build_from_source_trail(&mut self, trail: HashSet<LocatedBuildIdent>) {
51+
self.build_from_source_trail = trail;
52+
}
4553
}
4654

4755
impl AbstractSolver for Solver {
@@ -62,16 +70,22 @@ impl AbstractSolver for Solver {
6270
self._validators = Cow::from(default_validators());
6371
}
6472

65-
fn set_binary_only(&mut self, _binary_only: bool) {
66-
// TODO
73+
fn set_binary_only(&mut self, binary_only: bool) {
74+
self.binary_only = binary_only;
6775
}
6876

6977
async fn solve(&mut self) -> Result<Solution> {
7078
let repos = self.repos.clone();
7179
let requests = self.requests.clone();
80+
let binary_only = self.binary_only;
81+
let build_from_source_trail = self.build_from_source_trail.clone();
7282
// Use a blocking thread so resolvo can call `block_on` on the runtime.
7383
let solvables = tokio::task::spawn_blocking(move || {
74-
let mut provider = Some(SpkProvider::new(repos.clone()));
84+
let mut provider = Some(SpkProvider::new(
85+
repos.clone(),
86+
binary_only,
87+
build_from_source_trail,
88+
));
7589
let (solver, solved) = loop {
7690
let mut this_iter_provider = provider.take().expect("provider is always Some");
7791
let pkg_requirements = this_iter_provider.pkg_requirements(&requests);
@@ -216,17 +230,25 @@ impl AbstractSolver for Solver {
216230
located_build_ident_with_component.ident.name().to_owned(),
217231
next_index,
218232
);
219-
solution_adds.push((
220-
pkg_request,
221-
package,
222-
PackageSource::Repository {
223-
repo: Arc::clone(&repo),
224-
// XXX: Why is this needed?
225-
components: repo
226-
.read_components(located_build_ident_with_component.ident.target())
227-
.await?,
228-
},
229-
));
233+
solution_adds.push((pkg_request, package, {
234+
if located_build_ident_with_component.requires_build_from_source {
235+
PackageSource::BuildFromSource {
236+
recipe: repo
237+
.read_recipe(
238+
&located_build_ident_with_component.ident.to_version_ident(),
239+
)
240+
.await?,
241+
}
242+
} else {
243+
PackageSource::Repository {
244+
repo: Arc::clone(&repo),
245+
// XXX: Why is this needed?
246+
components: repo
247+
.read_components(located_build_ident_with_component.ident.target())
248+
.await?,
249+
}
250+
}
251+
}));
230252
}
231253
let mut solution = Solution::new(solution_options);
232254
for (pkg_request, package, source) in solution_adds {

crates/spk-solve/src/cdcl_solver/pkg_request_version_set.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,28 @@ impl SyntheticComponent {
104104
}
105105
}
106106

107-
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
107+
// The `requires_build_from_source` field is ignored for hashing and equality
108+
// purposes.
109+
#[derive(Clone, Debug)]
108110
pub(crate) struct LocatedBuildIdentWithComponent {
109111
pub(crate) ident: LocatedBuildIdent,
110112
pub(crate) component: SyntheticComponent,
113+
pub(crate) requires_build_from_source: bool,
114+
}
115+
116+
impl std::hash::Hash for LocatedBuildIdentWithComponent {
117+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
118+
self.ident.hash(state);
119+
self.component.hash(state);
120+
}
121+
}
122+
123+
impl Eq for LocatedBuildIdentWithComponent {}
124+
125+
impl PartialEq for LocatedBuildIdentWithComponent {
126+
fn eq(&self, other: &Self) -> bool {
127+
self.ident == other.ident && self.component == other.component
128+
}
111129
}
112130

113131
impl LocatedBuildIdentWithComponent {

0 commit comments

Comments
 (0)