Skip to content

Commit 04b2cd9

Browse files
committed
Auto merge of #5604 - debris:issue_5602, r=matklad
fixed 5602, expose cached build script output in json output fixes #5602
2 parents 92b5106 + 66aa9bf commit 04b2cd9

File tree

2 files changed

+83
-12
lines changed

2 files changed

+83
-12
lines changed

src/cargo/core/compiler/custom_build.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ pub fn prepare<'a, 'cfg>(
105105
}
106106
}
107107

108+
fn emit_build_output(output: &BuildOutput, id: &PackageId) {
109+
let library_paths = output
110+
.library_paths
111+
.iter()
112+
.map(|l| l.display().to_string())
113+
.collect::<Vec<_>>();
114+
115+
machine_message::emit(&machine_message::BuildScript {
116+
package_id: id,
117+
linked_libs: &output.library_links,
118+
linked_paths: &library_paths,
119+
cfgs: &output.cfgs,
120+
env: &output.env,
121+
});
122+
}
123+
108124
fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult<(Work, Work)> {
109125
assert!(unit.mode.is_run_custom_build());
110126
let bcx = &cx.bcx;
@@ -336,18 +352,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
336352
BuildOutput::parse(&output.stdout, &pkg_name, &root_output, &root_output)?;
337353

338354
if json_messages {
339-
let library_paths = parsed_output
340-
.library_paths
341-
.iter()
342-
.map(|l| l.display().to_string())
343-
.collect::<Vec<_>>();
344-
machine_message::emit(&machine_message::BuildScript {
345-
package_id: &id,
346-
linked_libs: &parsed_output.library_links,
347-
linked_paths: &library_paths,
348-
cfgs: &parsed_output.cfgs,
349-
env: &parsed_output.env,
350-
});
355+
emit_build_output(&parsed_output, &id);
351356
}
352357
build_state.insert(id, kind, parsed_output);
353358
}
@@ -365,6 +370,11 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
365370
BuildOutput::parse_file(&output_file, &pkg_name, &prev_root_output, &root_output)?
366371
}
367372
};
373+
374+
if json_messages {
375+
emit_build_output(&output, &id);
376+
}
377+
368378
build_state.insert(id, kind, output);
369379
Ok(())
370380
});

tests/testsuite/build.rs

+61
Original file line numberDiff line numberDiff line change
@@ -3981,6 +3981,7 @@ fn compiler_json_error_format() {
39813981
path = "bar"
39823982
"#,
39833983
)
3984+
.file("build.rs", "fn main() { println!(\"cargo:rustc-cfg=xyz\") }")
39843985
.file("src/main.rs", "fn main() { let unused = 92; }")
39853986
.file(
39863987
"bar/Cargo.toml",
@@ -4035,6 +4036,36 @@ fn compiler_json_error_format() {
40354036
"fresh": false
40364037
}
40374038
4039+
{
4040+
"reason":"compiler-artifact",
4041+
"package_id":"foo 0.5.0 ([..])",
4042+
"target":{
4043+
"kind":["custom-build"],
4044+
"crate_types":["bin"],
4045+
"name":"build-script-build",
4046+
"src_path":"[..]build.rs"
4047+
},
4048+
"profile": {
4049+
"debug_assertions": true,
4050+
"debuginfo": 2,
4051+
"opt_level": "0",
4052+
"overflow_checks": true,
4053+
"test": false
4054+
},
4055+
"features": [],
4056+
"filenames": "{...}",
4057+
"fresh": false
4058+
}
4059+
4060+
{
4061+
"reason":"build-script-executed",
4062+
"package_id":"foo 0.5.0 ([..])",
4063+
"linked_libs":[],
4064+
"linked_paths":[],
4065+
"env":[],
4066+
"cfgs":["xyz"]
4067+
}
4068+
40384069
{
40394070
"reason":"compiler-message",
40404071
"package_id":"foo 0.5.0 ([..])",
@@ -4080,6 +4111,27 @@ fn compiler_json_error_format() {
40804111
.arg("json"),
40814112
execs().with_status(0).with_json(
40824113
r#"
4114+
{
4115+
"reason":"compiler-artifact",
4116+
"package_id":"foo 0.5.0 ([..])",
4117+
"target":{
4118+
"kind":["custom-build"],
4119+
"crate_types":["bin"],
4120+
"name":"build-script-build",
4121+
"src_path":"[..]build.rs"
4122+
},
4123+
"profile": {
4124+
"debug_assertions": true,
4125+
"debuginfo": 2,
4126+
"opt_level": "0",
4127+
"overflow_checks": true,
4128+
"test": false
4129+
},
4130+
"features": [],
4131+
"filenames": "{...}",
4132+
"fresh": true
4133+
}
4134+
40834135
{
40844136
"reason":"compiler-artifact",
40854137
"profile": {
@@ -4101,6 +4153,15 @@ fn compiler_json_error_format() {
41014153
"fresh": true
41024154
}
41034155
4156+
{
4157+
"reason":"build-script-executed",
4158+
"package_id":"foo 0.5.0 ([..])",
4159+
"linked_libs":[],
4160+
"linked_paths":[],
4161+
"env":[],
4162+
"cfgs":["xyz"]
4163+
}
4164+
41044165
{
41054166
"reason":"compiler-artifact",
41064167
"package_id":"foo 0.5.0 ([..])",

0 commit comments

Comments
 (0)