about summary refs log tree commit diff
path: root/src/libsyntax/diagnostics/plugin.rs
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-06-20 21:40:37 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-06-20 21:40:37 +0530
commit7effb31fa201213929eb2cefc3c2b52013e307ac (patch)
tree2553c0db12d4d71d9c9de0757f1eaefb9ebc2ddd /src/libsyntax/diagnostics/plugin.rs
parent6bff14ffea5a3ca3f3b439b011954b521eb21a09 (diff)
parent634fced396f180eea18a828bdddec3deded61ab8 (diff)
downloadrust-7effb31fa201213929eb2cefc3c2b52013e307ac.tar.gz
rust-7effb31fa201213929eb2cefc3c2b52013e307ac.zip
Rollup merge of #26452 - michaelsproul:the-second-coming, r=pnkfelix
As per #26009 this PR implements a new collation system for extended-error metadata. I've tried to keep it as simple as possible for now, so there's no uniqueness checking and minimal modularity.

Although using a lint was discussed in #26009 I decided against this because it would require converting the AST output from the plugin back into an internal data-structure. Emitting the metadata from within the plugin prevents this double-handling. We also didn't identify this as the source of the failures last time, although something untoward was definitely happening... With that in mind I would like as much feedback as possible on this before it's merged, I don't want to break the bots again!

I've successfully built for my host architecture and I'm building an ARM cross-compiler now to test my assumptions about the various `CFG` variables. Despite the confusing name of `CFG_COMPILER_HOST_TRIPLE` it is actually the compile time target triple, as explained in `mk/target.mk`.

```
# This is the compile-time target-triple for the compiler. For the compiler at
# runtime, this should be considered the host-triple. More explanation for why
# this exists can be found on issue #2400
export CFG_COMPILER_HOST_TRIPLE
```

CC @pnkfelix @brson @nrc @alexcrichton 

Closes #25705, closes #26009.
Diffstat (limited to 'src/libsyntax/diagnostics/plugin.rs')
-rw-r--r--src/libsyntax/diagnostics/plugin.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs
index 2f7e4a16145..aee066807f4 100644
--- a/src/libsyntax/diagnostics/plugin.rs
+++ b/src/libsyntax/diagnostics/plugin.rs
@@ -10,6 +10,7 @@
 
 use std::cell::RefCell;
 use std::collections::BTreeMap;
+use std::env;
 
 use ast;
 use ast::{Ident, Name, TokenTree};
@@ -20,6 +21,8 @@ use parse::token;
 use ptr::P;
 use util::small_vector::SmallVector;
 
+use diagnostics::metadata::output_metadata;
+
 // Maximum width of any line in an extended error description (inclusive).
 const MAX_DESCRIPTION_WIDTH: usize = 80;
 
@@ -154,7 +157,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
                                           token_tree: &[TokenTree])
                                           -> Box<MacResult+'cx> {
     assert_eq!(token_tree.len(), 3);
-    let (_crate_name, name) = match (&token_tree[0], &token_tree[2]) {
+    let (crate_name, name) = match (&token_tree[0], &token_tree[2]) {
         (
             // Crate name.
             &ast::TtToken(_, token::Ident(ref crate_name, _)),
@@ -164,9 +167,18 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
         _ => unreachable!()
     };
 
-    // FIXME (#25705): we used to ensure error code uniqueness and
-    // output error description JSON metadata here, but the approach
-    // employed was too brittle.
+    // Output error metadata to `tmp/extended-errors/<target arch>/<crate name>.json`
+    let target_triple = env::var("CFG_COMPILER_HOST_TRIPLE")
+        .ok().expect("unable to determine target arch from $CFG_COMPILER_HOST_TRIPLE");
+
+    with_registered_diagnostics(|diagnostics| {
+        if let Err(e) = output_metadata(ecx, &target_triple, crate_name, &diagnostics) {
+            ecx.span_bug(span, &format!(
+                "error writing metadata for triple `{}` and crate `{}`, error: {}, cause: {:?}",
+                target_triple, crate_name, e.description(), e.cause()
+            ));
+        }
+    });
 
     // Construct the output expression.
     let (count, expr) =