Skip to content

Commit f73f174

Browse files
committed
fix: check sourceId and generate warning accordingly
1 parent fdc4f95 commit f73f174

File tree

4 files changed

+28
-40
lines changed

4 files changed

+28
-40
lines changed

src/cargo/ops/cargo_package/mod.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ fn prepare_archive(
483483
src.load()?;
484484

485485
if opts.check_metadata {
486-
check_metadata(pkg, gctx)?;
486+
check_metadata(pkg, opts.reg_or_index.as_ref(), gctx)?;
487487
}
488488

489489
if !pkg.manifest().exclude().is_empty() && !pkg.manifest().include().is_empty() {
@@ -808,7 +808,11 @@ fn build_lock(
808808

809809
// Checks that the package has some piece of metadata that a human can
810810
// use to tell what the package is about.
811-
fn check_metadata(pkg: &Package, gctx: &GlobalContext) -> CargoResult<()> {
811+
fn check_metadata(
812+
pkg: &Package,
813+
reg_or_index: Option<&RegistryOrIndex>,
814+
gctx: &GlobalContext,
815+
) -> CargoResult<()> {
812816
let md = pkg.manifest().metadata();
813817

814818
let mut missing = vec![];
@@ -829,20 +833,29 @@ fn check_metadata(pkg: &Package, gctx: &GlobalContext) -> CargoResult<()> {
829833
);
830834

831835
if !missing.is_empty() {
832-
let mut things = missing[..missing.len() - 1].join(", ");
833-
// `things` will be empty if and only if its length is 1 (i.e., the only case
834-
// to have no `or`).
835-
if !things.is_empty() {
836-
things.push_str(" or ");
836+
// Only warn if publishing to crates.io based on resolved registry
837+
let should_warn = match reg_or_index {
838+
Some(RegistryOrIndex::Registry(reg_name)) => reg_name == CRATES_IO_REGISTRY,
839+
None => true, // Default is crates.io
840+
Some(RegistryOrIndex::Index(_)) => false, // Custom index, not crates.io
841+
};
842+
843+
if should_warn {
844+
let mut things = missing[..missing.len() - 1].join(", ");
845+
// `things` will be empty if and only if its length is 1 (i.e., the only case
846+
// to have no `or`).
847+
if !things.is_empty() {
848+
things.push_str(" or ");
849+
}
850+
things.push_str(missing.last().unwrap());
851+
852+
gctx.shell().print_report(&[
853+
Level::WARNING.secondary_title(format!("manifest has no {things}"))
854+
.element(Level::NOTE.message("see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info"))
855+
],
856+
false
857+
)?
837858
}
838-
things.push_str(missing.last().unwrap());
839-
840-
gctx.shell().print_report(&[
841-
Level::WARNING.secondary_title(format!("manifest has no {things}"))
842-
.element(Level::NOTE.message("see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info"))
843-
],
844-
false
845-
)?
846859
}
847860

848861
Ok(())

tests/testsuite/alt_registry.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,6 @@ fn publish_with_registry_dependency() {
350350
p.cargo("publish --registry alternative")
351351
.with_stderr_data(str![[r#"
352352
[UPDATING] `alternative` index
353-
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository
354-
|
355-
= [NOTE] see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
356353
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
357354
[UPDATING] `alternative` index
358355
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
@@ -518,9 +515,6 @@ fn publish_to_alt_registry() {
518515
p.cargo("publish --registry alternative")
519516
.with_stderr_data(str![[r#"
520517
[UPDATING] `alternative` index
521-
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository
522-
|
523-
= [NOTE] see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
524518
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
525519
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
526520
[VERIFYING] foo v0.0.1 ([ROOT]/foo)
@@ -597,9 +591,6 @@ fn publish_with_crates_io_dep() {
597591
p.cargo("publish --registry alternative")
598592
.with_stderr_data(str![[r#"
599593
[UPDATING] `alternative` index
600-
[WARNING] manifest has no documentation, homepage or repository
601-
|
602-
= [NOTE] see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
603594
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
604595
[UPDATING] `dummy-registry` index
605596
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)

tests/testsuite/package.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7793,13 +7793,9 @@ fn publish_to_alt_registry_warns() {
77937793
.file("src/main.rs", "fn main() {}")
77947794
.build();
77957795

7796-
// There will be no warnings for alternative registry in the next commit
77977796
p.cargo("publish --dry-run --registry alternative")
77987797
.with_stderr_data(str![[r#"
77997798
[UPDATING] `alternative` index
7800-
[WARNING] manifest has no license, license-file, documentation, homepage or repository
7801-
|
7802-
= [NOTE] see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
78037799
[PACKAGING] foo v0.1.0 ([ROOT]/foo)
78047800
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
78057801
[VERIFYING] foo v0.1.0 ([ROOT]/foo)

tests/testsuite/publish.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,6 @@ fn simple_publish_with_http() {
211211
.with_stderr_data(str![[r#"
212212
[WARNING] `cargo publish --token` is deprecated in favor of using `cargo login` and environment variables
213213
[UPDATING] `dummy-registry` index
214-
[WARNING] manifest has no documentation, homepage or repository
215-
|
216-
= [NOTE] see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
217214
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
218215
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
219216
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
@@ -255,9 +252,6 @@ fn simple_publish_with_asymmetric() {
255252
.masquerade_as_nightly_cargo(&["asymmetric-token"])
256253
.with_stderr_data(str![[r#"
257254
[UPDATING] `dummy-registry` index
258-
[WARNING] manifest has no documentation, homepage or repository
259-
|
260-
= [NOTE] see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
261255
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
262256
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
263257
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
@@ -359,9 +353,6 @@ fn simple_with_index() {
359353
.with_stderr_data(str![[r#"
360354
[WARNING] `cargo publish --token` is deprecated in favor of using `cargo login` and environment variables
361355
[UPDATING] `[ROOT]/registry` index
362-
[WARNING] manifest has no documentation, homepage or repository
363-
|
364-
= [NOTE] see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
365356
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
366357
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
367358
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
@@ -789,9 +780,6 @@ fn dry_run() {
789780
.arg(registry.index_url().as_str())
790781
.with_stderr_data(str![[r#"
791782
[UPDATING] `[ROOT]/registry` index
792-
[WARNING] manifest has no documentation, homepage or repository
793-
|
794-
= [NOTE] see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
795783
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
796784
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
797785
[VERIFYING] foo v0.0.1 ([ROOT]/foo)

0 commit comments

Comments
 (0)