Skip to content

Commit

Permalink
Auto merge of #13085 - ehuss:registry-support-more, r=epage
Browse files Browse the repository at this point in the history
Add more options to registry test support.

This adds a few things that are missing in the registry test support code. These aren't immediately necessary, since no tests rely on them. However, I wrote it for something else that I ended up not needing, but I think it is still helpful for future work.

The additions are:

- Ability to specify `default-features=false` for a registry dependency.
- Include binary dependencies in the index for the `cargo publish` HTTTP server (current `cargo publish` tests use `file:///` upload, and don't verify the index).
- Include `rust-version` in the `cargo publish` HTTP server (current `cargo publish` tests don't verify the index).
- Include the `features=[…]` field for dependencies in the published `Cargo.toml` (cargo doesn't read features from `Cargo.toml`, it only uses the registry, but it is probably best to keep it in sync).
- Include the `package="…"` field for dependencies (for renamed dependencies) in the published `Cargo.toml` (similarly, cargo only uses the index, but it is probably good to keep in sync).
  • Loading branch information
bors committed Dec 1, 2023
2 parents 1ef8575 + 1aa7692 commit dd5e47a
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ pub struct Dependency {
registry: Option<String>,
package: Option<String>,
optional: bool,
default_features: bool,
}

/// Entry with data that corresponds to [`tar::EntryType`].
Expand Down Expand Up @@ -1161,12 +1162,15 @@ fn save_new_crate(
"name": name,
"req": dep.version_req,
"features": dep.features,
"default_features": true,
"default_features": dep.default_features,
"target": dep.target,
"optional": dep.optional,
"kind": dep.kind,
"registry": dep.registry,
"package": package,
"artifact": dep.artifact,
"bindep_target": dep.bindep_target,
"lib": dep.lib,
})
})
.collect::<Vec<_>>();
Expand All @@ -1179,7 +1183,7 @@ fn save_new_crate(
new_crate.features,
false,
new_crate.links,
None,
new_crate.rust_version.as_deref(),
None,
);

Expand Down Expand Up @@ -1415,7 +1419,7 @@ impl Package {
"name": dep.name,
"req": dep.vers,
"features": dep.features,
"default_features": true,
"default_features": dep.default_features,
"target": dep.target,
"artifact": artifact,
"bindep_target": dep.bindep_target,
Expand Down Expand Up @@ -1580,6 +1584,21 @@ impl Package {
assert_eq!(registry, "alternative");
manifest.push_str(&format!("registry-index = \"{}\"", alt_registry_url()));
}
if !dep.default_features {
manifest.push_str("default-features = false\n");
}
if !dep.features.is_empty() {
let mut features = String::new();
serde::Serialize::serialize(
&dep.features,
toml::ser::ValueSerializer::new(&mut features),
)
.unwrap();
manifest.push_str(&format!("features = {}\n", features));
}
if let Some(package) = &dep.package {
manifest.push_str(&format!("package = \"{}\"\n", package));
}
}
if self.proc_macro {
manifest.push_str("[lib]\nproc-macro = true\n");
Expand Down Expand Up @@ -1658,6 +1677,7 @@ impl Dependency {
package: None,
optional: false,
registry: None,
default_features: true,
}
}

Expand Down Expand Up @@ -1710,4 +1730,10 @@ impl Dependency {
self.optional = optional;
self
}

/// Adds `default-features = false` if the argument is `false`.
pub fn default_features(&mut self, default_features: bool) -> &mut Self {
self.default_features = default_features;
self
}
}

0 comments on commit dd5e47a

Please sign in to comment.