Skip to content

Commit dd5e47a

Browse files
committed
Auto merge of #13085 - ehuss:registry-support-more, r=epage
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).
2 parents 1ef8575 + 1aa7692 commit dd5e47a

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

crates/cargo-test-support/src/registry.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ pub struct Dependency {
557557
registry: Option<String>,
558558
package: Option<String>,
559559
optional: bool,
560+
default_features: bool,
560561
}
561562

562563
/// Entry with data that corresponds to [`tar::EntryType`].
@@ -1161,12 +1162,15 @@ fn save_new_crate(
11611162
"name": name,
11621163
"req": dep.version_req,
11631164
"features": dep.features,
1164-
"default_features": true,
1165+
"default_features": dep.default_features,
11651166
"target": dep.target,
11661167
"optional": dep.optional,
11671168
"kind": dep.kind,
11681169
"registry": dep.registry,
11691170
"package": package,
1171+
"artifact": dep.artifact,
1172+
"bindep_target": dep.bindep_target,
1173+
"lib": dep.lib,
11701174
})
11711175
})
11721176
.collect::<Vec<_>>();
@@ -1179,7 +1183,7 @@ fn save_new_crate(
11791183
new_crate.features,
11801184
false,
11811185
new_crate.links,
1182-
None,
1186+
new_crate.rust_version.as_deref(),
11831187
None,
11841188
);
11851189

@@ -1415,7 +1419,7 @@ impl Package {
14151419
"name": dep.name,
14161420
"req": dep.vers,
14171421
"features": dep.features,
1418-
"default_features": true,
1422+
"default_features": dep.default_features,
14191423
"target": dep.target,
14201424
"artifact": artifact,
14211425
"bindep_target": dep.bindep_target,
@@ -1580,6 +1584,21 @@ impl Package {
15801584
assert_eq!(registry, "alternative");
15811585
manifest.push_str(&format!("registry-index = \"{}\"", alt_registry_url()));
15821586
}
1587+
if !dep.default_features {
1588+
manifest.push_str("default-features = false\n");
1589+
}
1590+
if !dep.features.is_empty() {
1591+
let mut features = String::new();
1592+
serde::Serialize::serialize(
1593+
&dep.features,
1594+
toml::ser::ValueSerializer::new(&mut features),
1595+
)
1596+
.unwrap();
1597+
manifest.push_str(&format!("features = {}\n", features));
1598+
}
1599+
if let Some(package) = &dep.package {
1600+
manifest.push_str(&format!("package = \"{}\"\n", package));
1601+
}
15831602
}
15841603
if self.proc_macro {
15851604
manifest.push_str("[lib]\nproc-macro = true\n");
@@ -1658,6 +1677,7 @@ impl Dependency {
16581677
package: None,
16591678
optional: false,
16601679
registry: None,
1680+
default_features: true,
16611681
}
16621682
}
16631683

@@ -1710,4 +1730,10 @@ impl Dependency {
17101730
self.optional = optional;
17111731
self
17121732
}
1733+
1734+
/// Adds `default-features = false` if the argument is `false`.
1735+
pub fn default_features(&mut self, default_features: bool) -> &mut Self {
1736+
self.default_features = default_features;
1737+
self
1738+
}
17131739
}

0 commit comments

Comments
 (0)