fixed #5602, expose cached build script output in json output
authordebris <marek.kotewicz@gmail.com>
Sun, 3 Jun 2018 15:09:44 +0000 (17:09 +0200)
committerdebris <marek.kotewicz@gmail.com>
Sun, 3 Jun 2018 15:09:44 +0000 (17:09 +0200)
src/cargo/core/compiler/custom_build.rs
tests/testsuite/build.rs

index 48588bb25ac2cab64beada346a8c05d8083b9154..f60f3bf6350ec90edcd15e794d317beb834465ac 100644 (file)
@@ -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::<Vec<_>>();
+            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(())
     });
index ff7cb083b78dfc815d4dc17d50604bbd94121e9c..5026688ab3b989f1832e6ee75a16f6301adaff76 100644 (file)
@@ -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 ([..])",