aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model/src/lib.rs')
-rw-r--r--crates/ra_project_model/src/lib.rs57
1 files changed, 44 insertions, 13 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 897874813..081b1fec2 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -150,6 +150,29 @@ impl ProjectWorkspace {
150 } 150 }
151 } 151 }
152 152
153 pub fn out_dirs(&self) -> Vec<PathBuf> {
154 match self {
155 ProjectWorkspace::Json { project } => {
156 let mut out_dirs = Vec::with_capacity(project.crates.len());
157 for krate in &project.crates {
158 if let Some(out_dir) = &krate.out_dir {
159 out_dirs.push(out_dir.to_path_buf());
160 }
161 }
162 out_dirs
163 }
164 ProjectWorkspace::Cargo { cargo, sysroot: _sysroot } => {
165 let mut out_dirs = Vec::with_capacity(cargo.packages().len());
166 for pkg in cargo.packages() {
167 if let Some(out_dir) = pkg.out_dir(&cargo) {
168 out_dirs.push(out_dir.to_path_buf());
169 }
170 }
171 out_dirs
172 }
173 }
174 }
175
153 pub fn n_packages(&self) -> usize { 176 pub fn n_packages(&self) -> usize {
154 match self { 177 match self {
155 ProjectWorkspace::Json { project } => project.crates.len(), 178 ProjectWorkspace::Json { project } => project.crates.len(),
@@ -162,7 +185,7 @@ impl ProjectWorkspace {
162 pub fn to_crate_graph( 185 pub fn to_crate_graph(
163 &self, 186 &self,
164 default_cfg_options: &CfgOptions, 187 default_cfg_options: &CfgOptions,
165 outdirs: &FxHashMap<String, (ExternSourceId, String)>, 188 extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>,
166 load: &mut dyn FnMut(&Path) -> Option<FileId>, 189 load: &mut dyn FnMut(&Path) -> Option<FileId>,
167 ) -> CrateGraph { 190 ) -> CrateGraph {
168 let mut crate_graph = CrateGraph::default(); 191 let mut crate_graph = CrateGraph::default();
@@ -187,6 +210,16 @@ impl ProjectWorkspace {
187 opts 210 opts
188 }; 211 };
189 212
213 let mut env = Env::default();
214 let mut extern_source = ExternSource::default();
215 if let Some(out_dir) = &krate.out_dir {
216 // FIXME: We probably mangle non UTF-8 paths here, figure out a better solution
217 env.set("OUT_DIR", out_dir.to_string_lossy().to_string());
218 if let Some(&extern_source_id) = extern_source_roots.get(out_dir) {
219 extern_source.set_extern_path(&out_dir, extern_source_id);
220 }
221 }
222
190 // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env 223 // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env
191 crates.insert( 224 crates.insert(
192 crate_id, 225 crate_id,
@@ -196,8 +229,8 @@ impl ProjectWorkspace {
196 // FIXME json definitions can store the crate name 229 // FIXME json definitions can store the crate name
197 None, 230 None,
198 cfg_options, 231 cfg_options,
199 Env::default(), 232 env,
200 Default::default(), 233 extern_source,
201 ), 234 ),
202 ); 235 );
203 } 236 }
@@ -235,13 +268,8 @@ impl ProjectWorkspace {
235 opts 268 opts
236 }; 269 };
237 270
238 let mut env = Env::default(); 271 let env = Env::default();
239 let mut extern_source = ExternSource::default(); 272 let extern_source = ExternSource::default();
240 if let Some((id, path)) = outdirs.get(krate.name(&sysroot)) {
241 env.set("OUT_DIR", path.clone());
242 extern_source.set_extern_path(&path, *id);
243 }
244
245 let crate_id = crate_graph.add_crate_root( 273 let crate_id = crate_graph.add_crate_root(
246 file_id, 274 file_id,
247 Edition::Edition2018, 275 Edition::Edition2018,
@@ -292,9 +320,12 @@ impl ProjectWorkspace {
292 }; 320 };
293 let mut env = Env::default(); 321 let mut env = Env::default();
294 let mut extern_source = ExternSource::default(); 322 let mut extern_source = ExternSource::default();
295 if let Some((id, path)) = outdirs.get(pkg.name(&cargo)) { 323 if let Some(out_dir) = pkg.out_dir(cargo) {
296 env.set("OUT_DIR", path.clone()); 324 // FIXME: We probably mangle non UTF-8 paths here, figure out a better solution
297 extern_source.set_extern_path(&path, *id); 325 env.set("OUT_DIR", out_dir.to_string_lossy().to_string());
326 if let Some(&extern_source_id) = extern_source_roots.get(out_dir) {
327 extern_source.set_extern_path(&out_dir, extern_source_id);
328 }
298 } 329 }
299 let crate_id = crate_graph.add_crate_root( 330 let crate_id = crate_graph.add_crate_root(
300 file_id, 331 file_id,