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.
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.
11 use std::collections::HashMap;
12 use std::process::Command;
13 use std::path::PathBuf;
15 use build_helper::output;
16 use rustc_serialize::json;
20 #[derive(RustcDecodable)]
22 packages: Vec<Package>,
26 #[derive(RustcDecodable)]
30 source: Option<String>,
31 manifest_path: String,
34 #[derive(RustcDecodable)]
36 nodes: Vec<ResolveNode>,
39 #[derive(RustcDecodable)]
42 dependencies: Vec<String>,
45 pub fn build(build: &mut Build) {
46 build_krate(build, "src/libstd");
47 build_krate(build, "src/libtest");
48 build_krate(build, "src/rustc");
51 fn build_krate(build: &mut Build, krate: &str) {
52 // Run `cargo metadata` to figure out what crates we're testing.
54 // Down below we're going to call `cargo test`, but to test the right set
55 // of packages we're going to have to know what `-p` arguments to pass it
56 // to know what crates to test. Here we run `cargo metadata` to learn about
57 // the dependency graph and what `-p` arguments there are.
58 let mut cargo = Command::new(&build.cargo);
60 .arg("--manifest-path").arg(build.src.join(krate).join("Cargo.toml"));
61 let output = output(&mut cargo);
62 let output: Output = json::decode(&output).unwrap();
63 let mut id2name = HashMap::new();
64 for package in output.packages {
65 if package.source.is_none() {
66 id2name.insert(package.id, package.name.clone());
67 let mut path = PathBuf::from(package.manifest_path);
69 build.crates.insert(package.name.clone(), Crate {
70 build_step: format!("build-crate-{}", package.name),
71 doc_step: format!("doc-crate-{}", package.name),
72 test_step: format!("test-crate-{}", package.name),
73 bench_step: format!("bench-crate-{}", package.name),
81 for node in output.resolve.nodes {
82 let name = match id2name.get(&node.id) {
87 let krate = build.crates.get_mut(name).unwrap();
88 for dep in node.dependencies.iter() {
89 let dep = match id2name.get(dep) {
93 krate.deps.push(dep.clone());