Artifact Content
Not logged in

Artifact 9fb5111a4c01dc9fc0edc93f04b4b96afb512435:

// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
//> or the MIT license
// <LICENSE-MIT or>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::collections::HashMap;
use std::process::Command;
use std::path::PathBuf;

use build_helper::output;
use rustc_serialize::json;

use {Build, Crate};

struct Output {
    packages: Vec<Package>,
    resolve: Resolve,

struct Package {
    id: String,
    name: String,
    version: String,
    source: Option<String>,
    manifest_path: String,

struct Resolve {
    nodes: Vec<ResolveNode>,

struct ResolveNode {
    id: String,
    dependencies: Vec<String>,

pub fn build(build: &mut Build) {
    build_krate(build, "src/libstd");
    build_krate(build, "src/libtest");
    build_krate(build, "src/rustc");

fn build_krate(build: &mut Build, krate: &str) {
    // Run `cargo metadata` to figure out what crates we're testing.
    // Down below we're going to call `cargo test`, but to test the right set
    // of packages we're going to have to know what `-p` arguments to pass it
    // to know what crates to test. Here we run `cargo metadata` to learn about
    // the dependency graph and what `-p` arguments there are.
    let mut cargo = Command::new(&build.cargo);
    let output = output(&mut cargo);
    let output: Output = json::decode(&output).unwrap();
    let mut id2name = HashMap::new();
    for package in output.packages {
        if package.source.is_none() {
            let mut path = PathBuf::from(package.manifest_path);
            build.crates.insert(, Crate {
                build_step: format!("build-crate-{}",,
                doc_step: format!("doc-crate-{}",,
                test_step: format!("test-crate-{}",,
                bench_step: format!("bench-crate-{}",,
                version: package.version,
                deps: Vec::new(),
                path: path,

    for node in output.resolve.nodes {
        let name = match id2name.get(& {
            Some(name) => name,
            None => continue,

        let krate = build.crates.get_mut(name).unwrap();
        for dep in node.dependencies.iter() {
            let dep = match id2name.get(dep) {
                Some(dep) => dep,
                None => continue,