diff options
author | Aleksey Kladov <[email protected]> | 2020-11-13 16:38:26 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-11-13 16:38:26 +0000 |
commit | 4dfda64b39cc47ac75280461f46e121958990fca (patch) | |
tree | d6baa54c962334f627d143837b52183cea829bff /crates/project_model/src | |
parent | aeda30e301d74e40fc1eb992fad581afb627126f (diff) |
Cleanup workspace loading a tiny bit
Diffstat (limited to 'crates/project_model/src')
-rw-r--r-- | crates/project_model/src/cargo_workspace.rs | 20 | ||||
-rw-r--r-- | crates/project_model/src/workspace.rs | 34 |
2 files changed, 28 insertions, 26 deletions
diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs index 608a031d4..540b57ae4 100644 --- a/crates/project_model/src/cargo_workspace.rs +++ b/crates/project_model/src/cargo_workspace.rs | |||
@@ -65,6 +65,10 @@ pub struct CargoConfig { | |||
65 | /// rustc target | 65 | /// rustc target |
66 | pub target: Option<String>, | 66 | pub target: Option<String>, |
67 | 67 | ||
68 | /// Don't load sysroot crates (`std`, `core` & friends). Might be useful | ||
69 | /// when debugging isolated issues. | ||
70 | pub no_sysroot: bool, | ||
71 | |||
68 | /// rustc private crate source | 72 | /// rustc private crate source |
69 | pub rustc_source: Option<AbsPathBuf>, | 73 | pub rustc_source: Option<AbsPathBuf>, |
70 | } | 74 | } |
@@ -140,27 +144,27 @@ impl PackageData { | |||
140 | impl CargoWorkspace { | 144 | impl CargoWorkspace { |
141 | pub fn from_cargo_metadata( | 145 | pub fn from_cargo_metadata( |
142 | cargo_toml: &AbsPath, | 146 | cargo_toml: &AbsPath, |
143 | cargo_features: &CargoConfig, | 147 | config: &CargoConfig, |
144 | ) -> Result<CargoWorkspace> { | 148 | ) -> Result<CargoWorkspace> { |
145 | let mut meta = MetadataCommand::new(); | 149 | let mut meta = MetadataCommand::new(); |
146 | meta.cargo_path(toolchain::cargo()); | 150 | meta.cargo_path(toolchain::cargo()); |
147 | meta.manifest_path(cargo_toml.to_path_buf()); | 151 | meta.manifest_path(cargo_toml.to_path_buf()); |
148 | if cargo_features.all_features { | 152 | if config.all_features { |
149 | meta.features(CargoOpt::AllFeatures); | 153 | meta.features(CargoOpt::AllFeatures); |
150 | } else { | 154 | } else { |
151 | if cargo_features.no_default_features { | 155 | if config.no_default_features { |
152 | // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` | 156 | // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` |
153 | // https://github.com/oli-obk/cargo_metadata/issues/79 | 157 | // https://github.com/oli-obk/cargo_metadata/issues/79 |
154 | meta.features(CargoOpt::NoDefaultFeatures); | 158 | meta.features(CargoOpt::NoDefaultFeatures); |
155 | } | 159 | } |
156 | if !cargo_features.features.is_empty() { | 160 | if !config.features.is_empty() { |
157 | meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone())); | 161 | meta.features(CargoOpt::SomeFeatures(config.features.clone())); |
158 | } | 162 | } |
159 | } | 163 | } |
160 | if let Some(parent) = cargo_toml.parent() { | 164 | if let Some(parent) = cargo_toml.parent() { |
161 | meta.current_dir(parent.to_path_buf()); | 165 | meta.current_dir(parent.to_path_buf()); |
162 | } | 166 | } |
163 | if let Some(target) = cargo_features.target.as_ref() { | 167 | if let Some(target) = config.target.as_ref() { |
164 | meta.other_options(vec![String::from("--filter-platform"), target.clone()]); | 168 | meta.other_options(vec![String::from("--filter-platform"), target.clone()]); |
165 | } | 169 | } |
166 | let mut meta = meta.exec().with_context(|| { | 170 | let mut meta = meta.exec().with_context(|| { |
@@ -170,8 +174,8 @@ impl CargoWorkspace { | |||
170 | let mut out_dir_by_id = FxHashMap::default(); | 174 | let mut out_dir_by_id = FxHashMap::default(); |
171 | let mut cfgs = FxHashMap::default(); | 175 | let mut cfgs = FxHashMap::default(); |
172 | let mut proc_macro_dylib_paths = FxHashMap::default(); | 176 | let mut proc_macro_dylib_paths = FxHashMap::default(); |
173 | if cargo_features.load_out_dirs_from_check { | 177 | if config.load_out_dirs_from_check { |
174 | let resources = load_extern_resources(cargo_toml, cargo_features)?; | 178 | let resources = load_extern_resources(cargo_toml, config)?; |
175 | out_dir_by_id = resources.out_dirs; | 179 | out_dir_by_id = resources.out_dirs; |
176 | cfgs = resources.cfgs; | 180 | cfgs = resources.cfgs; |
177 | proc_macro_dylib_paths = resources.proc_dylib_paths; | 181 | proc_macro_dylib_paths = resources.proc_dylib_paths; |
diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index 43ea351d1..8a1a60e0e 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs | |||
@@ -1,3 +1,7 @@ | |||
1 | //! Handles lowering of build-system specific workspace information (`cargo | ||
2 | //! metadata` or `rust-project.json`) into representation stored in the salsa | ||
3 | //! database -- `CrateGraph`. | ||
4 | |||
1 | use std::{fmt, fs, path::Component, process::Command}; | 5 | use std::{fmt, fs, path::Component, process::Command}; |
2 | 6 | ||
3 | use anyhow::{Context, Result}; | 7 | use anyhow::{Context, Result}; |
@@ -56,11 +60,7 @@ impl fmt::Debug for ProjectWorkspace { | |||
56 | } | 60 | } |
57 | 61 | ||
58 | impl ProjectWorkspace { | 62 | impl ProjectWorkspace { |
59 | pub fn load( | 63 | pub fn load(manifest: ProjectManifest, config: &CargoConfig) -> Result<ProjectWorkspace> { |
60 | manifest: ProjectManifest, | ||
61 | cargo_config: &CargoConfig, | ||
62 | with_sysroot: bool, | ||
63 | ) -> Result<ProjectWorkspace> { | ||
64 | let res = match manifest { | 64 | let res = match manifest { |
65 | ProjectManifest::ProjectJson(project_json) => { | 65 | ProjectManifest::ProjectJson(project_json) => { |
66 | let file = fs::read_to_string(&project_json).with_context(|| { | 66 | let file = fs::read_to_string(&project_json).with_context(|| { |
@@ -84,32 +84,30 @@ impl ProjectWorkspace { | |||
84 | cmd | 84 | cmd |
85 | })?; | 85 | })?; |
86 | 86 | ||
87 | let cargo = CargoWorkspace::from_cargo_metadata(&cargo_toml, cargo_config) | 87 | let cargo = CargoWorkspace::from_cargo_metadata(&cargo_toml, config).with_context( |
88 | .with_context(|| { | 88 | || { |
89 | format!( | 89 | format!( |
90 | "Failed to read Cargo metadata from Cargo.toml file {}, {}", | 90 | "Failed to read Cargo metadata from Cargo.toml file {}, {}", |
91 | cargo_toml.display(), | 91 | cargo_toml.display(), |
92 | cargo_version | 92 | cargo_version |
93 | ) | 93 | ) |
94 | })?; | 94 | }, |
95 | let sysroot = if with_sysroot { | 95 | )?; |
96 | let sysroot = if config.no_sysroot { | ||
97 | Sysroot::default() | ||
98 | } else { | ||
96 | Sysroot::discover(&cargo_toml).with_context(|| { | 99 | Sysroot::discover(&cargo_toml).with_context(|| { |
97 | format!( | 100 | format!( |
98 | "Failed to find sysroot for Cargo.toml file {}. Is rust-src installed?", | 101 | "Failed to find sysroot for Cargo.toml file {}. Is rust-src installed?", |
99 | cargo_toml.display() | 102 | cargo_toml.display() |
100 | ) | 103 | ) |
101 | })? | 104 | })? |
102 | } else { | ||
103 | Sysroot::default() | ||
104 | }; | 105 | }; |
105 | 106 | ||
106 | let rustc = if let Some(rustc_dir) = &cargo_config.rustc_source { | 107 | let rustc = if let Some(rustc_dir) = &config.rustc_source { |
107 | Some( | 108 | Some(CargoWorkspace::from_cargo_metadata(&rustc_dir, config).with_context( |
108 | CargoWorkspace::from_cargo_metadata(&rustc_dir, cargo_config) | 109 | || format!("Failed to read Cargo metadata for Rust sources"), |
109 | .with_context(|| { | 110 | )?) |
110 | format!("Failed to read Cargo metadata for Rust sources") | ||
111 | })?, | ||
112 | ) | ||
113 | } else { | 111 | } else { |
114 | None | 112 | None |
115 | }; | 113 | }; |