1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
use crate::{
cargo_config::TargetTriple,
helpers::convert_rel_path_to_main_sep,
list::{BinaryListState, TestListState},
reuse_build::PathMapper,
};
use camino::Utf8PathBuf;
use nextest_metadata::{RustBuildMetaSummary, RustNonTestBinarySummary};
use std::{
collections::{BTreeMap, BTreeSet},
marker::PhantomData,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RustBuildMeta<State> {
pub target_directory: Utf8PathBuf,
pub base_output_directories: BTreeSet<Utf8PathBuf>,
pub non_test_binaries: BTreeMap<String, BTreeSet<RustNonTestBinarySummary>>,
pub linked_paths: BTreeMap<Utf8PathBuf, BTreeSet<String>>,
pub target_triple: Option<TargetTriple>,
state: PhantomData<State>,
}
impl RustBuildMeta<BinaryListState> {
pub fn new(
target_directory: impl Into<Utf8PathBuf>,
target_triple: Option<TargetTriple>,
) -> Self {
Self {
target_directory: target_directory.into(),
base_output_directories: BTreeSet::new(),
non_test_binaries: BTreeMap::new(),
linked_paths: BTreeMap::new(),
state: PhantomData,
target_triple,
}
}
pub fn map_paths(&self, path_mapper: &PathMapper) -> RustBuildMeta<TestListState> {
RustBuildMeta {
target_directory: path_mapper
.new_target_dir()
.unwrap_or(&self.target_directory)
.to_path_buf(),
base_output_directories: self.base_output_directories.clone(),
non_test_binaries: self.non_test_binaries.clone(),
linked_paths: self.linked_paths.clone(),
state: PhantomData,
target_triple: self.target_triple.clone(),
}
}
}
impl RustBuildMeta<TestListState> {
#[cfg(test)]
pub(crate) fn empty() -> Self {
Self {
target_directory: Utf8PathBuf::new(),
base_output_directories: BTreeSet::new(),
non_test_binaries: BTreeMap::new(),
linked_paths: BTreeMap::new(),
state: PhantomData,
target_triple: None,
}
}
pub fn dylib_paths(&self) -> Vec<Utf8PathBuf> {
self.linked_paths
.keys()
.filter_map(|rel_path| {
let join_path = self
.target_directory
.join(convert_rel_path_to_main_sep(rel_path));
join_path.exists().then_some(join_path)
})
.chain(self.base_output_directories.iter().flat_map(|base_output| {
let abs_base = self
.target_directory
.join(convert_rel_path_to_main_sep(base_output));
let with_deps = abs_base.join("deps");
[with_deps, abs_base]
}))
.collect()
}
}
impl<State> RustBuildMeta<State> {
pub fn from_summary(summary: RustBuildMetaSummary) -> Self {
Self {
target_directory: summary.target_directory,
base_output_directories: summary.base_output_directories,
non_test_binaries: summary.non_test_binaries,
linked_paths: summary
.linked_paths
.into_iter()
.map(|linked_path| (linked_path, BTreeSet::new()))
.collect(),
state: PhantomData,
target_triple: TargetTriple::deserialize(summary.target_platform),
}
}
pub fn to_summary(&self) -> RustBuildMetaSummary {
RustBuildMetaSummary {
target_directory: self.target_directory.clone(),
base_output_directories: self.base_output_directories.clone(),
non_test_binaries: self.non_test_binaries.clone(),
linked_paths: self.linked_paths.keys().cloned().collect(),
target_platform: TargetTriple::serialize(self.target_triple.as_ref()),
}
}
}