]>
git.proxmox.com Git - rustc.git/blob - src/bootstrap/metadata.rs
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
;
14 use std
::collections
::HashSet
;
16 use build_helper
::output
;
22 #[derive(Deserialize)]
24 packages
: Vec
<Package
>,
28 #[derive(Deserialize)]
33 source
: Option
<String
>,
34 manifest_path
: String
,
37 #[derive(Deserialize)]
39 nodes
: Vec
<ResolveNode
>,
42 #[derive(Deserialize)]
45 dependencies
: Vec
<String
>,
48 pub fn build(build
: &mut Build
) {
49 let mut resolves
= Vec
::new();
50 build_krate(&build
.std_features(), build
, &mut resolves
, "src/libstd");
51 build_krate("", build
, &mut resolves
, "src/libtest");
52 build_krate(&build
.rustc_features(), build
, &mut resolves
, "src/rustc");
54 let mut id2name
= HashMap
::with_capacity(build
.crates
.len());
55 for (name
, krate
) in build
.crates
.iter() {
56 id2name
.insert(krate
.id
.clone(), name
.clone());
59 for node
in resolves
{
60 let name
= match id2name
.get(&node
.id
) {
65 let krate
= build
.crates
.get_mut(name
).unwrap();
66 for dep
in node
.dependencies
.iter() {
67 let dep
= match id2name
.get(dep
) {
71 krate
.deps
.insert(*dep
);
76 fn build_krate(features
: &str, build
: &mut Build
, resolves
: &mut Vec
<ResolveNode
>, krate
: &str) {
77 // Run `cargo metadata` to figure out what crates we're testing.
79 // Down below we're going to call `cargo test`, but to test the right set
80 // of packages we're going to have to know what `-p` arguments to pass it
81 // to know what crates to test. Here we run `cargo metadata` to learn about
82 // the dependency graph and what `-p` arguments there are.
83 let mut cargo
= Command
::new(&build
.initial_cargo
);
85 .arg("--format-version").arg("1")
86 .arg("--features").arg(features
)
87 .arg("--manifest-path").arg(build
.src
.join(krate
).join("Cargo.toml"));
88 let output
= output(&mut cargo
);
89 let output
: Output
= serde_json
::from_str(&output
).unwrap();
90 for package
in output
.packages
{
91 if package
.source
.is_none() {
92 let name
= INTERNER
.intern_string(package
.name
);
93 let mut path
= PathBuf
::from(package
.manifest_path
);
95 build
.crates
.insert(name
, Crate
{
96 build_step
: format
!("build-crate-{}", name
),
97 doc_step
: format
!("doc-crate-{}", name
),
98 test_step
: format
!("test-crate-{}", name
),
99 bench_step
: format
!("bench-crate-{}", name
),
101 version
: package
.version
,
103 deps
: HashSet
::new(),
108 resolves
.extend(output
.resolve
.nodes
);