Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish: Move all features to feature2 if new syntax is used #6168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,18 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
.uploader()
.upload_crate(app.http_client(), tarball_bytes, &krate, vers)?;

let (features, features2): (BTreeMap<_, _>, BTreeMap<_, _>) =
features.into_iter().partition(|(_k, vals)| {
!vals
.iter()
.any(|v| v.starts_with("dep:") || v.contains("?/"))
});
let (features2, v) = if features2.is_empty() {
(None, None)
} else {
(Some(features2), Some(2))
let uses_features2_syntax = features
.iter()
.flat_map(|(_key, values)| values)
.any(|values| values.starts_with("dep:") || values.contains("?/"));

let (features, features2) = match uses_features2_syntax {
true => (BTreeMap::new(), Some(features)),
false => (features, None),
};

let v = features2.as_ref().map(|_| 2);

// Register this crate in our local git repo.
let git_crate = cargo_registry_index::Crate {
name: name.0,
Expand Down
4 changes: 2 additions & 2 deletions src/tests/http-data/krate_publish_features_version_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
],
[
"content-length",
"323"
"324"
],
[
"content-type",
"text/plain"
]
],
"body": "eyJuYW1lIjoiZm9vIiwidmVycyI6IjEuMC4wIiwiZGVwcyI6W3sibmFtZSI6ImJhciIsInJlcSI6Ij4gMCIsImZlYXR1cmVzIjpbXSwib3B0aW9uYWwiOmZhbHNlLCJkZWZhdWx0X2ZlYXR1cmVzIjp0cnVlLCJ0YXJnZXQiOm51bGwsImtpbmQiOiJub3JtYWwifV0sImNrc3VtIjoiYWNiNTYwNGIxMjZhYzg5NGMxZWIxMWM0NTc1YmYyMDcyZmVhNjEyMzJhODg4ZTQ1Mzc3MGM3OWQ3ZWQ1NjQxOSIsImZlYXR1cmVzIjp7Im9sZF9mZWF0IjpbXX0sImZlYXR1cmVzMiI6eyJuZXdfZmVhdCI6WyJkZXA6YmFyIiwiYmFyPy9mZWF0Il19LCJ5YW5rZWQiOmZhbHNlLCJ2IjoyfQo="
"body": "eyJuYW1lIjoiZm9vIiwidmVycyI6IjEuMC4wIiwiZGVwcyI6W3sibmFtZSI6ImJhciIsInJlcSI6Ij4gMCIsImZlYXR1cmVzIjpbXSwib3B0aW9uYWwiOmZhbHNlLCJkZWZhdWx0X2ZlYXR1cmVzIjp0cnVlLCJ0YXJnZXQiOm51bGwsImtpbmQiOiJub3JtYWwifV0sImNrc3VtIjoiYWNiNTYwNGIxMjZhYzg5NGMxZWIxMWM0NTc1YmYyMDcyZmVhNjEyMzJhODg4ZTQ1Mzc3MGM3OWQ3ZWQ1NjQxOSIsImZlYXR1cmVzIjp7fSwiZmVhdHVyZXMyIjp7Im5ld19mZWF0IjpbImRlcDpiYXIiLCJiYXI/L2ZlYXQiXSwib2xkX2ZlYXQiOltdfSwieWFua2VkIjpmYWxzZSwidiI6Mn0K"
},
"response": {
"status": 200,
Expand Down
14 changes: 8 additions & 6 deletions src/tests/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,11 +987,13 @@ fn features_version_2() {
assert_eq!(crates[0].name, "foo");
assert_eq!(crates[0].deps.len(), 1);
assert_eq!(crates[0].v, Some(2));
let features = BTreeMap::from_iter([("old_feat".to_string(), vec![])]);
assert_eq!(crates[0].features, features);
let features2 = BTreeMap::from_iter([(
"new_feat".to_string(),
vec!["dep:bar".to_string(), "bar?/feat".to_string()],
)]);
assert_eq!(crates[0].features, BTreeMap::new());
let features2 = BTreeMap::from_iter([
(
"new_feat".to_string(),
vec!["dep:bar".to_string(), "bar?/feat".to_string()],
),
("old_feat".to_string(), vec![]),
]);
assert_eq!(crates[0].features2, Some(features2));
}