]>
Commit | Line | Data |
---|---|---|
c30ab7b3 SL |
1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | use std::collections::HashMap; | |
12 | use std::process::Command; | |
13 | use std::path::PathBuf; | |
14 | ||
15 | use build_helper::output; | |
16 | use rustc_serialize::json; | |
17 | ||
18 | use {Build, Crate}; | |
19 | ||
20 | #[derive(RustcDecodable)] | |
21 | struct Output { | |
22 | packages: Vec<Package>, | |
23 | resolve: Resolve, | |
24 | } | |
25 | ||
26 | #[derive(RustcDecodable)] | |
27 | struct Package { | |
28 | id: String, | |
29 | name: String, | |
8bb4bdeb | 30 | version: String, |
c30ab7b3 SL |
31 | source: Option<String>, |
32 | manifest_path: String, | |
33 | } | |
34 | ||
35 | #[derive(RustcDecodable)] | |
36 | struct Resolve { | |
37 | nodes: Vec<ResolveNode>, | |
38 | } | |
39 | ||
40 | #[derive(RustcDecodable)] | |
41 | struct ResolveNode { | |
42 | id: String, | |
43 | dependencies: Vec<String>, | |
44 | } | |
45 | ||
46 | pub fn build(build: &mut Build) { | |
8bb4bdeb XL |
47 | build_krate(build, "src/libstd"); |
48 | build_krate(build, "src/libtest"); | |
c30ab7b3 SL |
49 | build_krate(build, "src/rustc"); |
50 | } | |
51 | ||
52 | fn build_krate(build: &mut Build, krate: &str) { | |
53 | // Run `cargo metadata` to figure out what crates we're testing. | |
54 | // | |
55 | // Down below we're going to call `cargo test`, but to test the right set | |
56 | // of packages we're going to have to know what `-p` arguments to pass it | |
57 | // to know what crates to test. Here we run `cargo metadata` to learn about | |
58 | // the dependency graph and what `-p` arguments there are. | |
041b39d2 | 59 | let mut cargo = Command::new(&build.initial_cargo); |
c30ab7b3 | 60 | cargo.arg("metadata") |
7cac9316 | 61 | .arg("--format-version").arg("1") |
c30ab7b3 SL |
62 | .arg("--manifest-path").arg(build.src.join(krate).join("Cargo.toml")); |
63 | let output = output(&mut cargo); | |
64 | let output: Output = json::decode(&output).unwrap(); | |
65 | let mut id2name = HashMap::new(); | |
66 | for package in output.packages { | |
67 | if package.source.is_none() { | |
68 | id2name.insert(package.id, package.name.clone()); | |
69 | let mut path = PathBuf::from(package.manifest_path); | |
70 | path.pop(); | |
71 | build.crates.insert(package.name.clone(), Crate { | |
72 | build_step: format!("build-crate-{}", package.name), | |
73 | doc_step: format!("doc-crate-{}", package.name), | |
74 | test_step: format!("test-crate-{}", package.name), | |
476ff2be | 75 | bench_step: format!("bench-crate-{}", package.name), |
c30ab7b3 | 76 | name: package.name, |
8bb4bdeb | 77 | version: package.version, |
c30ab7b3 SL |
78 | deps: Vec::new(), |
79 | path: path, | |
80 | }); | |
81 | } | |
82 | } | |
83 | ||
84 | for node in output.resolve.nodes { | |
85 | let name = match id2name.get(&node.id) { | |
86 | Some(name) => name, | |
87 | None => continue, | |
88 | }; | |
89 | ||
90 | let krate = build.crates.get_mut(name).unwrap(); | |
91 | for dep in node.dependencies.iter() { | |
92 | let dep = match id2name.get(dep) { | |
93 | Some(dep) => dep, | |
94 | None => continue, | |
95 | }; | |
96 | krate.deps.push(dep.clone()); | |
97 | } | |
98 | } | |
99 | } |