Skip to content

Commit df0efb2

Browse files
committed
Auto merge of #13311 - weihanglo:pkgid-json-message, r=epage
fix(json-msg): use pkgid spec in in JSON messages
2 parents a383063 + 273168c commit df0efb2

File tree

19 files changed

+82
-55
lines changed

19 files changed

+82
-55
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ fn emit_build_output(
229229
.collect::<Vec<_>>();
230230

231231
let msg = machine_message::BuildScript {
232-
package_id,
232+
package_id: package_id.to_spec(),
233233
linked_libs: &output.library_links,
234234
linked_paths: &library_paths,
235235
cfgs: &output.cfgs,

src/cargo/core/compiler/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ fn link_targets(cx: &mut Context<'_, '_>, unit: &Unit, fresh: bool) -> CargoResu
578578
};
579579

580580
let msg = machine_message::Artifact {
581-
package_id,
581+
package_id: package_id.to_spec(),
582582
manifest_path,
583583
target: &target,
584584
profile: art_profile,
@@ -1766,7 +1766,7 @@ fn on_stderr_line_inner(
17661766
}
17671767

17681768
let msg = machine_message::FromCompiler {
1769-
package_id,
1769+
package_id: package_id.to_spec(),
17701770
manifest_path,
17711771
target,
17721772
message: compiler_message,

src/cargo/core/compiler/timings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'cfg> Timings<'cfg> {
222222
.extend(unlocked.iter().cloned().cloned());
223223
if self.report_json {
224224
let msg = machine_message::TimingInfo {
225-
package_id: unit_time.unit.pkg.package_id(),
225+
package_id: unit_time.unit.pkg.package_id().to_spec(),
226226
target: &unit_time.unit.target,
227227
mode: unit_time.unit.mode,
228228
duration: unit_time.duration,

src/cargo/util/machine_message.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use std::path::{Path, PathBuf};
22

3+
use cargo_util_schemas::core::PackageIdSpec;
34
use serde::ser;
45
use serde::Serialize;
56
use serde_json::{self, json, value::RawValue};
67

7-
use crate::core::{compiler::CompileMode, PackageId, Target};
8+
use crate::core::compiler::CompileMode;
9+
use crate::core::Target;
810

911
pub trait Message: ser::Serialize {
1012
fn reason(&self) -> &str;
@@ -19,7 +21,7 @@ pub trait Message: ser::Serialize {
1921

2022
#[derive(Serialize)]
2123
pub struct FromCompiler<'a> {
22-
pub package_id: PackageId,
24+
pub package_id: PackageIdSpec,
2325
pub manifest_path: &'a Path,
2426
pub target: &'a Target,
2527
pub message: Box<RawValue>,
@@ -33,7 +35,7 @@ impl<'a> Message for FromCompiler<'a> {
3335

3436
#[derive(Serialize)]
3537
pub struct Artifact<'a> {
36-
pub package_id: PackageId,
38+
pub package_id: PackageIdSpec,
3739
pub manifest_path: PathBuf,
3840
pub target: &'a Target,
3941
pub profile: ArtifactProfile,
@@ -71,7 +73,7 @@ pub enum ArtifactDebuginfo {
7173

7274
#[derive(Serialize)]
7375
pub struct BuildScript<'a> {
74-
pub package_id: PackageId,
76+
pub package_id: PackageIdSpec,
7577
pub linked_libs: &'a [String],
7678
pub linked_paths: &'a [String],
7779
pub cfgs: &'a [String],
@@ -87,7 +89,7 @@ impl<'a> Message for BuildScript<'a> {
8789

8890
#[derive(Serialize)]
8991
pub struct TimingInfo<'a> {
90-
pub package_id: PackageId,
92+
pub package_id: PackageIdSpec,
9193
pub target: &'a Target,
9294
pub mode: CompileMode,
9395
pub duration: f64,

src/doc/man/cargo-metadata.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ The JSON output has the following format:
334334
Notes:
335335
- For `"id"` field syntax, see [Package ID Specifications] in the reference.
336336

337-
[Package ID Specifications]: ../reference/pkgid-spec.html
338-
339337
## OPTIONS
340338

341339
### Output Options
@@ -393,6 +391,8 @@ reproduction of the information within `Cargo.toml`.
393391
cargo metadata --format-version=1
394392
395393
## SEE ALSO
396-
{{man "cargo" 1}}, {{man "cargo-pkgid" 1}}, [Package ID Specifications]
394+
395+
{{man "cargo" 1}}, {{man "cargo-pkgid" 1}}, [Package ID Specifications], [JSON messages]
397396
398397
[Package ID Specifications]: ../reference/pkgid-spec.html
398+
[JSON messages]: ../reference/external-tools.html#json-messages

src/doc/man/cargo-pkgid.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ fetched.
2121

2222
A package specifier consists of a name, version, and source URL. You are
2323
allowed to use partial specifiers to succinctly match a specific package as
24-
long as it matches only one package. The format of a _spec_ can be one of the
25-
following:
24+
long as it matches only one package. This specifier is also used by other parts
25+
in Cargo, such as {{man "cargo-metadata" 1}} and [JSON messages] emitted by Cargo.
26+
27+
The format of a _spec_ can be one of the following:
2628

2729
SPEC Structure | Example SPEC
2830
---------------------------|--------------
@@ -88,6 +90,9 @@ Get the package ID for the given package instead of the current package.
8890
cargo pkgid file:///path/to/local/package#foo
8991

9092
## SEE ALSO
91-
{{man "cargo" 1}}, {{man "cargo-generate-lockfile" 1}}, {{man "cargo-metadata" 1}}, [Package ID Specifications]
93+
94+
{{man "cargo" 1}}, {{man "cargo-generate-lockfile" 1}}, {{man "cargo-metadata" 1}},
95+
[Package ID Specifications], [JSON messages]
9296

9397
[Package ID Specifications]: ../reference/pkgid-spec.html
98+
[JSON messages]: ../reference/external-tools.html#json-messages

src/doc/man/generated_txt/cargo-metadata.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,5 +483,7 @@ EXAMPLES
483483

484484
SEE ALSO
485485
cargo(1), cargo-pkgid(1), Package ID Specifications
486-
<https://doc.rust-lang.org/cargo/reference/pkgid-spec.html>
486+
<https://doc.rust-lang.org/cargo/reference/pkgid-spec.html>, JSON
487+
messages
488+
<https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
487489

src/doc/man/generated_txt/cargo-pkgid.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ DESCRIPTION
1818

1919
A package specifier consists of a name, version, and source URL. You are
2020
allowed to use partial specifiers to succinctly match a specific package
21-
as long as it matches only one package. The format of a spec can be one
22-
of the following:
21+
as long as it matches only one package. This specifier is also used by
22+
other parts in Cargo, such as cargo-metadata(1) and JSON messages
23+
<https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
24+
emitted by Cargo.
25+
26+
The format of a spec can be one of the following:
2327

2428
+-----------------+--------------------------------------------------+
2529
| SPEC Structure | Example SPEC |
@@ -172,5 +176,7 @@ EXAMPLES
172176
SEE ALSO
173177
cargo(1), cargo-generate-lockfile(1), cargo-metadata(1), Package ID
174178
Specifications
175-
<https://doc.rust-lang.org/cargo/reference/pkgid-spec.html>
179+
<https://doc.rust-lang.org/cargo/reference/pkgid-spec.html>, JSON
180+
messages
181+
<https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
176182

src/doc/src/commands/cargo-metadata.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ The JSON output has the following format:
334334
Notes:
335335
- For `"id"` field syntax, see [Package ID Specifications] in the reference.
336336

337-
[Package ID Specifications]: ../reference/pkgid-spec.html
338-
339337
## OPTIONS
340338

341339
### Output Options
@@ -512,6 +510,8 @@ details on environment variables that Cargo reads.
512510
cargo metadata --format-version=1
513511

514512
## SEE ALSO
515-
[cargo(1)](cargo.html), [cargo-pkgid(1)](cargo-pkgid.html), [Package ID Specifications]
513+
514+
[cargo(1)](cargo.html), [cargo-pkgid(1)](cargo-pkgid.html), [Package ID Specifications], [JSON messages]
516515

517516
[Package ID Specifications]: ../reference/pkgid-spec.html
517+
[JSON messages]: ../reference/external-tools.html#json-messages

src/doc/src/commands/cargo-pkgid.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ fetched.
2121

2222
A package specifier consists of a name, version, and source URL. You are
2323
allowed to use partial specifiers to succinctly match a specific package as
24-
long as it matches only one package. The format of a _spec_ can be one of the
25-
following:
24+
long as it matches only one package. This specifier is also used by other parts
25+
in Cargo, such as [cargo-metadata(1)](cargo-metadata.html) and [JSON messages] emitted by Cargo.
26+
27+
The format of a _spec_ can be one of the following:
2628

2729
SPEC Structure | Example SPEC
2830
---------------------------|--------------
@@ -183,6 +185,9 @@ details on environment variables that Cargo reads.
183185
cargo pkgid file:///path/to/local/package#foo
184186

185187
## SEE ALSO
186-
[cargo(1)](cargo.html), [cargo-generate-lockfile(1)](cargo-generate-lockfile.html), [cargo-metadata(1)](cargo-metadata.html), [Package ID Specifications]
188+
189+
[cargo(1)](cargo.html), [cargo-generate-lockfile(1)](cargo-generate-lockfile.html), [cargo-metadata(1)](cargo-metadata.html),
190+
[Package ID Specifications], [JSON messages]
187191

188192
[Package ID Specifications]: ../reference/pkgid-spec.html
193+
[JSON messages]: ../reference/external-tools.html#json-messages

0 commit comments

Comments
 (0)