Skip to content

Commit ee40272

Browse files
committed
fix(json-msg): use pkgid spec in in JSON messages
In 12914 we stabilized pkgid spec as unique package identifier for `cargo metadata`. However, we forgot to make the same change to JSON message format[^1]. This PR does so. Note that the `package_id` field in JSON message is not clearly stated as "opaque", so it might be considered as a breaking change to some extent. [^1]: https://doc.rust-lang.org/nightly/cargo/reference/external-tools.html#compiler-messages
1 parent a383063 commit ee40272

File tree

10 files changed

+32
-30
lines changed

10 files changed

+32
-30
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,

tests/testsuite/binary_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn check_msg_format_json() {
280280
let output = r#"
281281
{
282282
"reason": "compiler-artifact",
283-
"package_id": "foo 0.0.1 [..]",
283+
"package_id": "path+file:///[..]/foo#0.0.1",
284284
"manifest_path": "[CWD]/Cargo.toml",
285285
"target": "{...}",
286286
"profile": "{...}",

tests/testsuite/build.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4160,7 +4160,7 @@ fn compiler_json_error_format() {
41604160
r#"
41614161
{
41624162
"reason":"compiler-artifact",
4163-
"package_id":"foo 0.5.0 ([..])",
4163+
"package_id":"path+file:///[..]/foo#0.5.0",
41644164
"manifest_path": "[..]",
41654165
"target":{
41664166
"kind":["custom-build"],
@@ -4187,7 +4187,7 @@ fn compiler_json_error_format() {
41874187
41884188
{
41894189
"reason":"compiler-message",
4190-
"package_id":"bar 0.5.0 ([..])",
4190+
"package_id":"path+file:///[..]/bar#0.5.0",
41914191
"manifest_path": "[..]",
41924192
"target":{
41934193
"kind":["lib"],
@@ -4213,7 +4213,7 @@ fn compiler_json_error_format() {
42134213
},
42144214
"executable": null,
42154215
"features": [],
4216-
"package_id":"bar 0.5.0 ([..])",
4216+
"package_id":"path+file:///[..]/bar#0.5.0",
42174217
"manifest_path": "[..]",
42184218
"target":{
42194219
"kind":["lib"],
@@ -4234,7 +4234,7 @@ fn compiler_json_error_format() {
42344234
42354235
{
42364236
"reason":"build-script-executed",
4237-
"package_id":"foo 0.5.0 ([..])",
4237+
"package_id":"path+file:///[..]/foo#0.5.0",
42384238
"linked_libs":[],
42394239
"linked_paths":[],
42404240
"env":[],
@@ -4244,7 +4244,7 @@ fn compiler_json_error_format() {
42444244
42454245
{
42464246
"reason":"compiler-message",
4247-
"package_id":"foo 0.5.0 ([..])",
4247+
"package_id":"path+file:///[..]/foo#0.5.0",
42484248
"manifest_path": "[..]",
42494249
"target":{
42504250
"kind":["bin"],
@@ -4261,7 +4261,7 @@ fn compiler_json_error_format() {
42614261
42624262
{
42634263
"reason":"compiler-artifact",
4264-
"package_id":"foo 0.5.0 ([..])",
4264+
"package_id":"path+file:///[..]/foo#0.5.0",
42654265
"manifest_path": "[..]",
42664266
"target":{
42674267
"kind":["bin"],
@@ -4332,7 +4332,7 @@ fn message_format_json_forward_stderr() {
43324332
r#"
43334333
{
43344334
"reason":"compiler-message",
4335-
"package_id":"foo 0.5.0 ([..])",
4335+
"package_id":"path+file:///[..]/foo#0.5.0",
43364336
"manifest_path": "[..]",
43374337
"target":{
43384338
"kind":["bin"],
@@ -4349,7 +4349,7 @@ fn message_format_json_forward_stderr() {
43494349
43504350
{
43514351
"reason":"compiler-artifact",
4352-
"package_id":"foo 0.5.0 ([..])",
4352+
"package_id":"path+file:///[..]/foo#0.5.0",
43534353
"manifest_path": "[..]",
43544354
"target":{
43554355
"kind":["bin"],

tests/testsuite/doc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ fn doc_message_format() {
17061706
"rendered": "{...}",
17071707
"spans": "{...}"
17081708
},
1709-
"package_id": "foo [..]",
1709+
"package_id": "path+file:///[..]/foo#0.0.1",
17101710
"manifest_path": "[..]",
17111711
"reason": "compiler-message",
17121712
"target": "{...}"
@@ -1729,7 +1729,7 @@ fn doc_json_artifacts() {
17291729
r#"
17301730
{
17311731
"reason": "compiler-artifact",
1732-
"package_id": "foo 0.0.1 [..]",
1732+
"package_id": "path+file:///[..]/foo#0.0.1",
17331733
"manifest_path": "[ROOT]/foo/Cargo.toml",
17341734
"target":
17351735
{
@@ -1751,7 +1751,7 @@ fn doc_json_artifacts() {
17511751
17521752
{
17531753
"reason": "compiler-artifact",
1754-
"package_id": "foo 0.0.1 [..]",
1754+
"package_id": "path+file:///[..]/foo#0.0.1",
17551755
"manifest_path": "[ROOT]/foo/Cargo.toml",
17561756
"target":
17571757
{
@@ -1773,7 +1773,7 @@ fn doc_json_artifacts() {
17731773
17741774
{
17751775
"reason": "compiler-artifact",
1776-
"package_id": "foo 0.0.1 [..]",
1776+
"package_id": "path+file:///[..]/foo#0.0.1",
17771777
"manifest_path": "[ROOT]/foo/Cargo.toml",
17781778
"target":
17791779
{

tests/testsuite/install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn simple_with_message_format() {
128128
r#"
129129
{
130130
"reason": "compiler-artifact",
131-
"package_id": "foo 0.0.1 ([..])",
131+
"package_id": "path+file:///[..]/foo#0.0.1",
132132
"manifest_path": "[..]",
133133
"target": {
134134
"kind": [
@@ -153,7 +153,7 @@ fn simple_with_message_format() {
153153
154154
{
155155
"reason": "compiler-artifact",
156-
"package_id": "foo 0.0.1 ([..])",
156+
"package_id": "path+file:///[..]/foo#0.0.1",
157157
"manifest_path": "[..]",
158158
"target": {
159159
"kind": [

tests/testsuite/metabuild.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ fn metabuild_json_artifact() {
694694
"features": [],
695695
"filenames": "{...}",
696696
"fresh": false,
697-
"package_id": "foo [..]",
697+
"package_id": "path+file:///[..]/foo#0.0.1",
698698
"manifest_path": "[..]",
699699
"profile": "{...}",
700700
"reason": "compiler-artifact",
@@ -719,7 +719,7 @@ fn metabuild_json_artifact() {
719719
"env": [],
720720
"linked_libs": [],
721721
"linked_paths": [],
722-
"package_id": "foo [..]",
722+
"package_id": "path+file:///[..]/foo#0.0.1",
723723
"out_dir": "[..]",
724724
"reason": "build-script-executed"
725725
}
@@ -748,7 +748,7 @@ fn metabuild_failed_build_json() {
748748
"rendered": "{...}",
749749
"spans": "{...}"
750750
},
751-
"package_id": "foo [..]",
751+
"package_id": "path+file:///[..]/foo#0.0.1",
752752
"manifest_path": "[..]",
753753
"reason": "compiler-message",
754754
"target": {

tests/testsuite/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3925,7 +3925,7 @@ fn json_artifact_includes_test_flag() {
39253925
},
39263926
"executable": "[..]/foo-[..]",
39273927
"features": [],
3928-
"package_id":"foo 0.0.1 ([..])",
3928+
"package_id":"path+file:///[..]/foo#0.0.1",
39293929
"manifest_path": "[..]",
39303930
"target":{
39313931
"kind":["lib"],
@@ -3962,7 +3962,7 @@ fn json_artifact_includes_executable_for_library_tests() {
39623962
"features": [],
39633963
"filenames": "{...}",
39643964
"fresh": false,
3965-
"package_id": "foo 0.0.1 ([..])",
3965+
"package_id": "path+file:///[..]/foo#0.0.1",
39663966
"manifest_path": "[..]",
39673967
"profile": "{...}",
39683968
"reason": "compiler-artifact",
@@ -4001,7 +4001,7 @@ fn json_artifact_includes_executable_for_integration_tests() {
40014001
"features": [],
40024002
"filenames": "{...}",
40034003
"fresh": false,
4004-
"package_id": "foo 0.0.1 ([..])",
4004+
"package_id": "path+file:///[..]/foo#0.0.1",
40054005
"manifest_path": "[..]",
40064006
"profile": "{...}",
40074007
"reason": "compiler-artifact",

0 commit comments

Comments
 (0)