|
11 | 11 | use std::collections::HashMap;
|
12 | 12 | use std::fmt;
|
13 | 13 |
|
14 |
| -use cargo::core::{PackageId, Profile, Target}; |
| 14 | +use cargo::core::{PackageId, Profile, Target, TargetKind}; |
15 | 15 | use cargo::ops::{Kind, Unit, Context};
|
16 |
| -use cargo::util::{CargoResult}; |
| 16 | +use cargo::util::{CargoResult, ProcessBuilder}; |
17 | 17 |
|
| 18 | +pub type DependencyGraph = HashMap<OwnedUnit, Vec<OwnedUnit>>; |
18 | 19 | /// Holds the information how exactly the build will be performed for a given
|
19 | 20 | /// workspace with given, specified features.
|
20 | 21 | /// **TODO:** Use it to schedule an analysis build instead of relying on Cargo
|
21 | 22 | /// invocations.
|
22 |
| -pub type DependencyGraph = HashMap<OwnedUnit, Vec<OwnedUnit>>; |
23 | 23 | pub struct Plan {
|
24 |
| - pub dep_graph: DependencyGraph |
| 24 | + pub dep_graph: DependencyGraph, |
| 25 | + /// We don't make a distinction between Units with different Profiles, |
| 26 | + /// as we're practically interested in bin, lib and (built, not run) |
| 27 | + /// build scripts for each package, because for these we can run `rustc` job |
| 28 | + pub compiler_jobs: HashMap<(PackageId, TargetKind), ProcessBuilder>, |
25 | 29 | }
|
26 | 30 |
|
27 | 31 | impl Plan {
|
28 | 32 | pub fn new() -> Plan {
|
29 | 33 | Plan {
|
30 |
| - dep_graph: HashMap::new() |
| 34 | + dep_graph: HashMap::new(), |
| 35 | + compiler_jobs: HashMap::new(), |
31 | 36 | }
|
32 | 37 | }
|
33 | 38 |
|
| 39 | + |
| 40 | + /// Cache a given compiler invocation in `ProcessBuilder` for a given `PackageId` |
| 41 | + /// and `TargetKind` in `Target`, to be used when processing cached build plan |
| 42 | + pub fn cache_compiler_job(&mut self, id: &PackageId, target: &Target, cmd: &ProcessBuilder) { |
| 43 | + let pkg_key = (id.clone(), target.kind().clone()); |
| 44 | + self.compiler_jobs.insert(pkg_key, cmd.clone()); |
| 45 | + } |
| 46 | + |
34 | 47 | /// Emplace a given `Unit`, along with its `Unit` dependencies (recursively)
|
35 | 48 | /// into dependency graph
|
36 | 49 | #[allow(dead_code)]
|
@@ -71,18 +84,21 @@ impl Plan {
|
71 | 84 | }
|
72 | 85 |
|
73 | 86 | pub fn clear(&mut self) {
|
74 |
| - self.dep_graph.clear() |
| 87 | + self.dep_graph.clear(); |
| 88 | + self.compiler_jobs.clear(); |
75 | 89 | }
|
76 | 90 | }
|
77 | 91 |
|
78 | 92 | impl fmt::Debug for Plan {
|
79 | 93 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
| 94 | + f.write_str("Dep graph:\n")?; |
80 | 95 | for (key, deps) in &self.dep_graph {
|
81 | 96 | f.write_str(&format!("{:?}\n", key))?;
|
82 | 97 | for dep in deps {
|
83 | 98 | f.write_str(&format!("- {:?}\n", dep))?;
|
84 | 99 | }
|
85 | 100 | }
|
| 101 | + f.write_str(&format!("Compiler jobs: {:?}\n", self.compiler_jobs))?; |
86 | 102 | Ok(())
|
87 | 103 | }
|
88 | 104 | }
|
|
0 commit comments