aboutsummaryrefslogtreecommitdiff
path: root/crates/project_model/src/cargo_workspace.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/project_model/src/cargo_workspace.rs')
-rw-r--r--crates/project_model/src/cargo_workspace.rs47
1 files changed, 23 insertions, 24 deletions
diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs
index c8a5333c4..f47898b9b 100644
--- a/crates/project_model/src/cargo_workspace.rs
+++ b/crates/project_model/src/cargo_workspace.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use std::{convert::TryInto, ops, process::Command}; 3use std::{convert::TryInto, ops, process::Command, sync::Arc};
4 4
5use anyhow::{Context, Result}; 5use anyhow::{Context, Result};
6use base_db::Edition; 6use base_db::Edition;
@@ -9,7 +9,7 @@ use la_arena::{Arena, Idx};
9use paths::{AbsPath, AbsPathBuf}; 9use paths::{AbsPath, AbsPathBuf};
10use rustc_hash::FxHashMap; 10use rustc_hash::FxHashMap;
11 11
12use crate::build_data::{BuildData, BuildDataMap}; 12use crate::build_data::BuildDataConfig;
13use crate::utf8_stdout; 13use crate::utf8_stdout;
14 14
15/// `CargoWorkspace` represents the logical structure of, well, a Cargo 15/// `CargoWorkspace` represents the logical structure of, well, a Cargo
@@ -27,6 +27,7 @@ pub struct CargoWorkspace {
27 packages: Arena<PackageData>, 27 packages: Arena<PackageData>,
28 targets: Arena<TargetData>, 28 targets: Arena<TargetData>,
29 workspace_root: AbsPathBuf, 29 workspace_root: AbsPathBuf,
30 build_data_config: BuildDataConfig,
30} 31}
31 32
32impl ops::Index<Package> for CargoWorkspace { 33impl ops::Index<Package> for CargoWorkspace {
@@ -55,9 +56,6 @@ pub struct CargoConfig {
55 /// This will be ignored if `cargo_all_features` is true. 56 /// This will be ignored if `cargo_all_features` is true.
56 pub features: Vec<String>, 57 pub features: Vec<String>,
57 58
58 /// Runs cargo check on launch to figure out the correct values of OUT_DIR
59 pub load_out_dirs_from_check: bool,
60
61 /// rustc target 59 /// rustc target
62 pub target: Option<String>, 60 pub target: Option<String>,
63 61
@@ -94,8 +92,8 @@ pub struct PackageData {
94 pub features: FxHashMap<String, Vec<String>>, 92 pub features: FxHashMap<String, Vec<String>>,
95 /// List of features enabled on this package 93 /// List of features enabled on this package
96 pub active_features: Vec<String>, 94 pub active_features: Vec<String>,
97 /// Build script related data for this package 95 // String representation of package id
98 pub build_data: BuildData, 96 pub id: String,
99} 97}
100 98
101#[derive(Debug, Clone, Eq, PartialEq)] 99#[derive(Debug, Clone, Eq, PartialEq)]
@@ -228,12 +226,6 @@ impl CargoWorkspace {
228 ) 226 )
229 })?; 227 })?;
230 228
231 let resources = if config.load_out_dirs_from_check {
232 BuildDataMap::new(cargo_toml, config, &meta.packages, progress)?
233 } else {
234 BuildDataMap::with_cargo_env(&meta.packages)
235 };
236
237 let mut pkg_by_id = FxHashMap::default(); 229 let mut pkg_by_id = FxHashMap::default();
238 let mut packages = Arena::default(); 230 let mut packages = Arena::default();
239 let mut targets = Arena::default(); 231 let mut targets = Arena::default();
@@ -241,10 +233,7 @@ impl CargoWorkspace {
241 let ws_members = &meta.workspace_members; 233 let ws_members = &meta.workspace_members;
242 234
243 meta.packages.sort_by(|a, b| a.id.cmp(&b.id)); 235 meta.packages.sort_by(|a, b| a.id.cmp(&b.id));
244 for meta_pkg in meta.packages { 236 for meta_pkg in &meta.packages {
245 let id = meta_pkg.id.clone();
246 let build_data = resources.get(&id).cloned().unwrap_or_default();
247
248 let cargo_metadata::Package { id, edition, name, manifest_path, version, .. } = 237 let cargo_metadata::Package { id, edition, name, manifest_path, version, .. } =
249 meta_pkg; 238 meta_pkg;
250 let is_member = ws_members.contains(&id); 239 let is_member = ws_members.contains(&id);
@@ -252,24 +241,24 @@ impl CargoWorkspace {
252 .parse::<Edition>() 241 .parse::<Edition>()
253 .with_context(|| format!("Failed to parse edition {}", edition))?; 242 .with_context(|| format!("Failed to parse edition {}", edition))?;
254 let pkg = packages.alloc(PackageData { 243 let pkg = packages.alloc(PackageData {
255 name, 244 id: id.repr.clone(),
245 name: name.clone(),
256 version: version.to_string(), 246 version: version.to_string(),
257 manifest: AbsPathBuf::assert(manifest_path), 247 manifest: AbsPathBuf::assert(manifest_path.clone()),
258 targets: Vec::new(), 248 targets: Vec::new(),
259 is_member, 249 is_member,
260 edition, 250 edition,
261 dependencies: Vec::new(), 251 dependencies: Vec::new(),
262 features: meta_pkg.features.into_iter().collect(), 252 features: meta_pkg.features.clone().into_iter().collect(),
263 active_features: Vec::new(), 253 active_features: Vec::new(),
264 build_data,
265 }); 254 });
266 let pkg_data = &mut packages[pkg]; 255 let pkg_data = &mut packages[pkg];
267 pkg_by_id.insert(id, pkg); 256 pkg_by_id.insert(id, pkg);
268 for meta_tgt in meta_pkg.targets { 257 for meta_tgt in &meta_pkg.targets {
269 let is_proc_macro = meta_tgt.kind.as_slice() == ["proc-macro"]; 258 let is_proc_macro = meta_tgt.kind.as_slice() == ["proc-macro"];
270 let tgt = targets.alloc(TargetData { 259 let tgt = targets.alloc(TargetData {
271 package: pkg, 260 package: pkg,
272 name: meta_tgt.name, 261 name: meta_tgt.name.clone(),
273 root: AbsPathBuf::assert(meta_tgt.src_path.clone()), 262 root: AbsPathBuf::assert(meta_tgt.src_path.clone()),
274 kind: TargetKind::new(meta_tgt.kind.as_slice()), 263 kind: TargetKind::new(meta_tgt.kind.as_slice()),
275 is_proc_macro, 264 is_proc_macro,
@@ -308,7 +297,13 @@ impl CargoWorkspace {
308 } 297 }
309 298
310 let workspace_root = AbsPathBuf::assert(meta.workspace_root); 299 let workspace_root = AbsPathBuf::assert(meta.workspace_root);
311 Ok(CargoWorkspace { packages, targets, workspace_root: workspace_root }) 300 let build_data_config = BuildDataConfig::new(
301 cargo_toml.to_path_buf(),
302 config.clone(),
303 Arc::new(meta.packages.clone()),
304 );
305
306 Ok(CargoWorkspace { packages, targets, workspace_root, build_data_config })
312 } 307 }
313 308
314 pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + ExactSizeIterator + 'a { 309 pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + ExactSizeIterator + 'a {
@@ -334,6 +329,10 @@ impl CargoWorkspace {
334 } 329 }
335 } 330 }
336 331
332 pub(crate) fn build_data_config(&self) -> &BuildDataConfig {
333 &self.build_data_config
334 }
335
337 fn is_unique(&self, name: &str) -> bool { 336 fn is_unique(&self, name: &str) -> bool {
338 self.packages.iter().filter(|(_, v)| v.name == name).count() == 1 337 self.packages.iter().filter(|(_, v)| v.name == name).count() == 1
339 } 338 }