Skip to content

Commit c74fadc

Browse files
committed
Enforce pkgid and sbom consistency
clarify fully qualified package ID usage in docs
1 parent 1743cb8 commit c74fadc

File tree

3 files changed

+63
-10
lines changed

3 files changed

+63
-10
lines changed

src/doc/src/reference/pkgid-spec.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ is a string which is used to uniquely refer to one package within a graph of
99
packages.
1010

1111
The specification may be fully qualified, such as
12-
`https://github.com/rust-lang/crates.io-index#regex@1.4.3` or it may be
12+
`registry+https://github.com/rust-lang/crates.io-index#regex@1.4.3` or it may be
1313
abbreviated, such as `regex`. The abbreviated form may be used as long as it
1414
uniquely identifies a single package in the dependency graph. If there is
1515
ambiguity, additional qualifiers can be added to make it unique. For example,
1616
if there are two versions of the `regex` package in the graph, then it can be
1717
qualified with a version to make it unique, such as `regex@1.4.3`.
1818

19+
Fully qualified package ID specifications are output by Cargo in:
20+
* [cargo pkgid](../commands/cargo-pkgid.md)
21+
* [cargo metadata](../commands/cargo-metadata.md)
22+
* [compiler artifact json messages](./external-tools.md#json-messages)
23+
* [SBOM pre-cursor files](./unstable.md#sbom)
24+
1925
### Specification grammar
2026

2127
The formal grammar for a Package Id Specification is:

src/doc/src/reference/unstable.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ that are uplifted into the target or artifact directories.
480480
// crate is compiled differently (different opt-level, features, etc).
481481
"crates": [
482482
{
483-
// Package ID specification
483+
// Fully qualified package ID specification
484484
"id": "path+file:///sample-package#0.1.0",
485485
// List of target kinds: bin, lib, rlib, dylib, cdylib, staticlib, proc-macro, example, test, bench, custom-build
486486
"kind": ["bin"],

tests/testsuite/pkgid.rs

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! Tests for the `cargo pkgid` command.
22
3+
use std::path::PathBuf;
4+
35
use crate::prelude::*;
6+
use cargo_test_support::basic_bin_manifest;
47
use cargo_test_support::basic_lib_manifest;
58
use cargo_test_support::compare::assert_e2e;
69
use cargo_test_support::git;
@@ -291,11 +294,12 @@ Please re-run this command with one of the following specifications:
291294
// * Package ID specifications
292295
// * machine-readable message via `--message-format=json`
293296
// * `cargo metadata` output
297+
// * SBOMs
294298
#[cargo_test]
295299
fn pkgid_json_message_metadata_consistency() {
296300
let p = project()
297-
.file("Cargo.toml", &basic_lib_manifest("foo"))
298-
.file("src/lib.rs", "fn unused() {}")
301+
.file("Cargo.toml", &basic_bin_manifest("foo"))
302+
.file("src/main.rs", "fn main() {}")
299303
.file("build.rs", "fn main() {}")
300304
.build();
301305

@@ -321,12 +325,6 @@ fn pkgid_json_message_metadata_consistency() {
321325
"reason": "build-script-executed",
322326
"...": "{...}"
323327
},
324-
{
325-
"manifest_path": "[ROOT]/foo/Cargo.toml",
326-
"package_id": "path+[ROOTURL]/foo#0.5.0",
327-
"reason": "compiler-message",
328-
"...": "{...}"
329-
},
330328
{
331329
"manifest_path": "[ROOT]/foo/Cargo.toml",
332330
"package_id": "path+[ROOTURL]/foo#0.5.0",
@@ -404,4 +402,53 @@ fn pkgid_json_message_metadata_consistency() {
404402
.is_json(),
405403
)
406404
.run();
405+
406+
p.cargo("build -Zsbom")
407+
.env("CARGO_BUILD_SBOM", "true")
408+
.masquerade_as_nightly_cargo(&["sbom"])
409+
.run();
410+
411+
let path = {
412+
let mut path = p.bin("foo").into_os_string();
413+
path.push(".cargo-sbom.json");
414+
PathBuf::from(path)
415+
};
416+
417+
assert!(path.is_file());
418+
let output = std::fs::read_to_string(&path).unwrap();
419+
assert_e2e().eq(
420+
output,
421+
snapbox::str![[r#"
422+
{
423+
"crates": [
424+
{
425+
"dependencies": [
426+
{
427+
"index": 1,
428+
"kind": "build"
429+
}
430+
],
431+
"features": [],
432+
"id": "path+[ROOTURL]/foo#0.5.0",
433+
"kind": [
434+
"bin"
435+
]
436+
},
437+
{
438+
"dependencies": [],
439+
"features": [],
440+
"id": "path+[ROOTURL]/foo#0.5.0",
441+
"kind": [
442+
"custom-build"
443+
]
444+
}
445+
],
446+
"root": 0,
447+
"rustc": "{...}",
448+
"target": "[HOST_TARGET]",
449+
"version": 1
450+
}
451+
"#]]
452+
.is_json(),
453+
);
407454
}

0 commit comments

Comments
 (0)