From f101d88ebddce81f3e5cb19ad9bea4b5512bfa86 Mon Sep 17 00:00:00 2001 From: debris Date: Sun, 3 Jun 2018 17:09:44 +0200 Subject: [PATCH] fixed #5602, expose cached build script output in json output --- src/cargo/core/compiler/custom_build.rs | 16 +++++++ tests/testsuite/build.rs | 62 +++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 48588bb25..f60f3bf63 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -365,6 +365,22 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes BuildOutput::parse_file(&output_file, &pkg_name, &prev_root_output, &root_output)? } }; + + if json_messages { + let library_paths = output + .library_paths + .iter() + .map(|l| l.display().to_string()) + .collect::>(); + machine_message::emit(&machine_message::BuildScript { + package_id: &id, + linked_libs: &output.library_links, + linked_paths: &library_paths, + cfgs: &output.cfgs, + env: &output.env, + }); + } + build_state.insert(id, kind, output); Ok(()) }); diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index ff7cb083b..5026688ab 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -3976,11 +3976,13 @@ fn compiler_json_error_format() { name = "foo" version = "0.5.0" authors = ["wycats@example.com"] + build = "build.rs" [dependencies.bar] path = "bar" "#, ) + .file("build.rs", "fn main() { println!(\"cargo:rustc-cfg=xyz\") }") .file("src/main.rs", "fn main() { let unused = 92; }") .file( "bar/Cargo.toml", @@ -4035,6 +4037,36 @@ fn compiler_json_error_format() { "fresh": false } + { + "reason":"compiler-artifact", + "package_id":"foo 0.5.0 ([..])", + "target":{ + "kind":["custom-build"], + "crate_types":["bin"], + "name":"build-script-build", + "src_path":"[..]build.rs" + }, + "profile": { + "debug_assertions": true, + "debuginfo": 2, + "opt_level": "0", + "overflow_checks": true, + "test": false + }, + "features": [], + "filenames": "{...}", + "fresh": false + } + + { + "reason":"build-script-executed", + "package_id":"foo 0.5.0 ([..])", + "linked_libs":[], + "linked_paths":[], + "env":[], + "cfgs":["xyz"] + } + { "reason":"compiler-message", "package_id":"foo 0.5.0 ([..])", @@ -4080,6 +4112,27 @@ fn compiler_json_error_format() { .arg("json"), execs().with_status(0).with_json( r#" + { + "reason":"compiler-artifact", + "package_id":"foo 0.5.0 ([..])", + "target":{ + "kind":["custom-build"], + "crate_types":["bin"], + "name":"build-script-build", + "src_path":"[..]build.rs" + }, + "profile": { + "debug_assertions": true, + "debuginfo": 2, + "opt_level": "0", + "overflow_checks": true, + "test": false + }, + "features": [], + "filenames": "{...}", + "fresh": true + } + { "reason":"compiler-artifact", "profile": { @@ -4101,6 +4154,15 @@ fn compiler_json_error_format() { "fresh": true } + { + "reason":"build-script-executed", + "package_id":"foo 0.5.0 ([..])", + "linked_libs":[], + "linked_paths":[], + "env":[], + "cfgs":["xyz"] + } + { "reason":"compiler-artifact", "package_id":"foo 0.5.0 ([..])",