diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-11 10:51:07 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-11 10:51:07 +0000 |
commit | c48dcf74118b6e0df747f036a9b66701037f3fc7 (patch) | |
tree | bc047c31d43d2e16428c56bf7cdf305f4a30fa66 /crates/ra_project_model | |
parent | 7b323b45a15809a20052f13d5a8f073aaa274a86 (diff) | |
parent | 6ea7c319154f9ec10721f4041afc9d07d6b2476b (diff) |
Merge #3549
3549: Implement env! macro r=matklad a=edwin0cheng
This PR implements `env!` macro by adding following things:
1. Added `additional_outdirs` settings in vscode. (naming to be bikeshed)
2. Added `ExternSourceId` which is a wrapping for SourceRootId but only used in extern sources. It is because `OUT_DIR` is not belonged to any crate and we have to access it behind an `AstDatabase`.
3. This PR does not implement the `OUT_DIR` parsing from `cargo check`. I don't have general design about this, @kiljacken could we reuse some cargo watch code for that ?
~~Block on [#3536]~~
PS: After this PR , we (kind of) completed the `include!(concat!(env!('OUT_DIR'), "foo.rs")` macro call combo. [Exodia Obliterate!](https://www.youtube.com/watch?v=RfqNH3FoGi0)
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 37845ca56..a6274709d 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -14,7 +14,7 @@ use std::{ | |||
14 | 14 | ||
15 | use anyhow::{bail, Context, Result}; | 15 | use anyhow::{bail, Context, Result}; |
16 | use ra_cfg::CfgOptions; | 16 | use ra_cfg::CfgOptions; |
17 | use ra_db::{CrateGraph, CrateName, Edition, Env, FileId}; | 17 | use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; |
18 | use rustc_hash::FxHashMap; | 18 | use rustc_hash::FxHashMap; |
19 | use serde_json::from_reader; | 19 | use serde_json::from_reader; |
20 | 20 | ||
@@ -162,6 +162,7 @@ impl ProjectWorkspace { | |||
162 | pub fn to_crate_graph( | 162 | pub fn to_crate_graph( |
163 | &self, | 163 | &self, |
164 | default_cfg_options: &CfgOptions, | 164 | default_cfg_options: &CfgOptions, |
165 | outdirs: &FxHashMap<String, (ExternSourceId, String)>, | ||
165 | load: &mut dyn FnMut(&Path) -> Option<FileId>, | 166 | load: &mut dyn FnMut(&Path) -> Option<FileId>, |
166 | ) -> CrateGraph { | 167 | ) -> CrateGraph { |
167 | let mut crate_graph = CrateGraph::default(); | 168 | let mut crate_graph = CrateGraph::default(); |
@@ -185,6 +186,8 @@ impl ProjectWorkspace { | |||
185 | } | 186 | } |
186 | opts | 187 | opts |
187 | }; | 188 | }; |
189 | |||
190 | // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env | ||
188 | crates.insert( | 191 | crates.insert( |
189 | crate_id, | 192 | crate_id, |
190 | crate_graph.add_crate_root( | 193 | crate_graph.add_crate_root( |
@@ -194,6 +197,7 @@ impl ProjectWorkspace { | |||
194 | None, | 197 | None, |
195 | cfg_options, | 198 | cfg_options, |
196 | Env::default(), | 199 | Env::default(), |
200 | Default::default(), | ||
197 | ), | 201 | ), |
198 | ); | 202 | ); |
199 | } | 203 | } |
@@ -231,12 +235,20 @@ impl ProjectWorkspace { | |||
231 | opts | 235 | opts |
232 | }; | 236 | }; |
233 | 237 | ||
238 | let mut env = Env::default(); | ||
239 | let mut 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 | |||
234 | let crate_id = crate_graph.add_crate_root( | 245 | let crate_id = crate_graph.add_crate_root( |
235 | file_id, | 246 | file_id, |
236 | Edition::Edition2018, | 247 | Edition::Edition2018, |
237 | Some(krate.name(&sysroot).to_string()), | 248 | Some(krate.name(&sysroot).to_string()), |
238 | cfg_options, | 249 | cfg_options, |
239 | Env::default(), | 250 | env, |
251 | extern_source, | ||
240 | ); | 252 | ); |
241 | sysroot_crates.insert(krate, crate_id); | 253 | sysroot_crates.insert(krate, crate_id); |
242 | } | 254 | } |
@@ -275,12 +287,19 @@ impl ProjectWorkspace { | |||
275 | opts.insert_features(pkg.features(&cargo).iter().map(Into::into)); | 287 | opts.insert_features(pkg.features(&cargo).iter().map(Into::into)); |
276 | opts | 288 | opts |
277 | }; | 289 | }; |
290 | let mut env = Env::default(); | ||
291 | let mut extern_source = ExternSource::default(); | ||
292 | if let Some((id, path)) = outdirs.get(pkg.name(&cargo)) { | ||
293 | env.set("OUT_DIR", path.clone()); | ||
294 | extern_source.set_extern_path(&path, *id); | ||
295 | } | ||
278 | let crate_id = crate_graph.add_crate_root( | 296 | let crate_id = crate_graph.add_crate_root( |
279 | file_id, | 297 | file_id, |
280 | edition, | 298 | edition, |
281 | Some(pkg.name(&cargo).to_string()), | 299 | Some(pkg.name(&cargo).to_string()), |
282 | cfg_options, | 300 | cfg_options, |
283 | Env::default(), | 301 | env, |
302 | extern_source, | ||
284 | ); | 303 | ); |
285 | if tgt.kind(&cargo) == TargetKind::Lib { | 304 | if tgt.kind(&cargo) == TargetKind::Lib { |
286 | lib_tgt = Some(crate_id); | 305 | lib_tgt = Some(crate_id); |