forked from rust-lang/cargo
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit more info on --message-format=json
This adds more output on Cargo's behalf to the output of `--message-format=json`. Cargo will now emit a message when a crate is finished compiling with a list of all files that were just generated along with a message when a build script finishes executing with linked libraries and linked library paths. Closes rust-lang#3212
- Loading branch information
1 parent
71a6cc9
commit 9f6d798
Showing
6 changed files
with
144 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,60 @@ | ||
use rustc_serialize::json; | ||
use core::{PackageId, Target}; | ||
use rustc_serialize::Encodable; | ||
use rustc_serialize::json::{self, Json}; | ||
|
||
use core::{PackageId, Target, Profile}; | ||
|
||
pub trait Message: Encodable { | ||
fn reason(&self) -> &str; | ||
} | ||
|
||
pub fn emit<T: Message>(t: T) { | ||
let json = json::encode(&t).unwrap(); | ||
let mut map = match json.parse().unwrap() { | ||
Json::Object(obj) => obj, | ||
_ => panic!("not a json object"), | ||
}; | ||
map.insert("reason".to_string(), Json::String(t.reason().to_string())); | ||
println!("{}", Json::Object(map)); | ||
} | ||
|
||
#[derive(RustcEncodable)] | ||
pub struct FromCompiler<'a> { | ||
reason: &'static str, | ||
package_id: &'a PackageId, | ||
target: &'a Target, | ||
message: json::Json, | ||
} | ||
|
||
impl<'a> FromCompiler<'a> { | ||
pub fn new(package_id: &'a PackageId, | ||
target: &'a Target, | ||
message: json::Json) | ||
-> FromCompiler<'a> { | ||
FromCompiler { | ||
reason: "compiler-message", | ||
package_id: package_id, | ||
target: target, | ||
message: message, | ||
} | ||
pub package_id: &'a PackageId, | ||
pub target: &'a Target, | ||
pub message: json::Json, | ||
} | ||
|
||
impl<'a> Message for FromCompiler<'a> { | ||
fn reason(&self) -> &str { | ||
"compiler-message" | ||
} | ||
} | ||
|
||
pub fn emit(self) { | ||
let json = json::encode(&self).unwrap(); | ||
println!("{}", json); | ||
#[derive(RustcEncodable)] | ||
pub struct Artifact<'a> { | ||
pub package_id: &'a PackageId, | ||
pub target: &'a Target, | ||
pub profile: &'a Profile, | ||
pub features: Vec<String>, | ||
pub filenames: Vec<String>, | ||
} | ||
|
||
impl<'a> Message for Artifact<'a> { | ||
fn reason(&self) -> &str { | ||
"compiler-artifact" | ||
} | ||
} | ||
|
||
#[derive(RustcEncodable)] | ||
pub struct BuildScript<'a> { | ||
pub package_id: &'a PackageId, | ||
pub linked_libs: &'a [String], | ||
pub linked_paths: &'a [String], | ||
pub cfgs: &'a [String], | ||
} | ||
|
||
impl<'a> Message for BuildScript<'a> { | ||
fn reason(&self) -> &str { | ||
"build-script-executed" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters