3
3
#![ feature( set_stdio) ]
4
4
5
5
extern crate getopts;
6
+ extern crate serde;
7
+ #[ macro_use]
8
+ extern crate serde_derive;
6
9
extern crate serde_json;
7
10
8
11
use cargo:: core:: { Package , PackageId , PackageSet , Source , SourceId , SourceMap , Workspace } ;
9
12
use log:: debug;
10
- use serde_json:: Value ;
11
13
use std:: {
12
14
env,
13
15
io:: BufReader ,
@@ -19,6 +21,17 @@ use std::{
19
21
20
22
pub type Result < T > = cargo:: util:: CargoResult < T > ;
21
23
24
+ #[ derive( Debug , Deserialize ) ]
25
+ struct Invocation {
26
+ package_name : String ,
27
+ outputs : Vec < PathBuf > ,
28
+ }
29
+
30
+ #[ derive( Debug , Deserialize ) ]
31
+ struct BuildPlan {
32
+ invocations : Vec < Invocation > ,
33
+ }
34
+
22
35
/// Main entry point.
23
36
///
24
37
/// Parse CLI arguments, handle their semantics, and provide for proper error handling.
@@ -394,25 +407,13 @@ impl<'a> WorkInfo<'a> {
394
407
let compilation = cargo:: ops:: compile ( & self . workspace , & opts) ?;
395
408
env:: remove_var ( "RUSTFLAGS" ) ;
396
409
397
- let build_plan: Value =
410
+ let build_plan: BuildPlan =
398
411
serde_json:: from_reader ( BufReader :: new ( File :: open ( & outdir) ?) ) ?;
399
412
400
- // FIXME: yuck drilling
401
- if let Value :: Object ( m) = build_plan {
402
- if let Some ( Value :: Array ( v) ) = m. get ( "invocations" ) {
403
- for s in v {
404
- if let Value :: Object ( m2) = s {
405
- if let Some ( Value :: String ( s2) ) = m2. get ( "package_name" ) {
406
- if s2 != name { continue ; }
407
- }
408
-
409
- if let Some ( Value :: Array ( v2) ) = m2. get ( "outputs" ) {
410
- if let Some ( Value :: String ( s) ) = v2. get ( 0 ) {
411
- return Ok ( ( PathBuf :: from ( s) , compilation. deps_output ) ) ;
412
- }
413
- }
414
- }
415
- }
413
+ // TODO: handle multiple outputs gracefully
414
+ for i in & build_plan. invocations {
415
+ if i. package_name == name {
416
+ return Ok ( ( i. outputs [ 0 ] . clone ( ) , compilation. deps_output ) ) ;
416
417
}
417
418
}
418
419
0 commit comments