Skip to content

Commit 51766fb

Browse files
committed
features: Differ optional dependencies and features
Store in database if feature comes from optional dependency. At the same time resolve rename as optional dependency might use same package multiple times under different name.
1 parent 6a81b64 commit 51766fb

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

src/db/add_package.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,16 @@ fn get_optional_dependencies(pkg: &MetadataPackage) -> Vec<Feature> {
237237
pkg.dependencies
238238
.iter()
239239
.filter(|dep| dep.optional)
240-
.map(|dep| Feature::new(dep.name.clone(), Vec::new()))
240+
.map(|dep| {
241+
let name = if let Some(rename) = &dep.rename {
242+
rename.clone()
243+
} else {
244+
dep.name.clone()
245+
};
246+
let mut feature = Feature::new(name, Vec::new());
247+
feature.set_optional_dependency(true);
248+
feature
249+
})
241250
.collect()
242251
}
243252

src/db/migrate.rs

+14
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,20 @@ pub fn migrate(version: Option<Version>, conn: &mut Client) -> CratesfyiResult<(
488488
"
489489
ALTER TABLE queue DROP COLUMN registry;
490490
"
491+
),
492+
migration!(
493+
context,
494+
21,
495+
// description
496+
"Add mark for features that are derived from optional dependencies",
497+
// upgrade query
498+
"
499+
ALTER TYPE feature ADD ATTRIBUTE optional_dependency BOOL;
500+
",
501+
// downgrade query
502+
"
503+
ALTER TYPE feature DROP ATTRIBUTE optional_dependency;
504+
"
491505
)
492506
];
493507

src/db/types.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@ use serde::Serialize;
66
pub struct Feature {
77
pub(crate) name: String,
88
pub(crate) subfeatures: Vec<String>,
9+
pub(crate) optional_dependency: bool,
910
}
1011

1112
impl Feature {
1213
pub fn new(name: String, subfeatures: Vec<String>) -> Self {
13-
Feature { name, subfeatures }
14+
Feature {
15+
name,
16+
subfeatures,
17+
optional_dependency: false,
18+
}
19+
}
20+
21+
pub fn set_optional_dependency(&mut self, optional_dependency: bool) {
22+
self.optional_dependency = optional_dependency
1423
}
1524

1625
pub fn is_private(&self) -> bool {

src/test/fakes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl<'a> FakeRelease<'a> {
4949
name: "fake-dependency".into(),
5050
req: "^1.0.0".into(),
5151
kind: None,
52+
rename: None,
5253
optional: false,
5354
}],
5455
targets: vec![Target::dummy_lib("fake_package".into(), None)],

src/utils/cargo_metadata.rs

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub(crate) struct Dependency {
132132
pub(crate) name: String,
133133
pub(crate) req: String,
134134
pub(crate) kind: Option<String>,
135+
pub(crate) rename: Option<String>,
135136
pub(crate) optional: bool,
136137
}
137138

0 commit comments

Comments
 (0)