diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-01 18:29:09 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-01 18:29:09 +0100 |
commit | f39b51d025c080682a35706ffcb86c2aeb28044b (patch) | |
tree | e7304aecbf57fbcbf5cc31bcc29d7b0df729786f /crates/ra_project_model/src/cargo_workspace.rs | |
parent | aaf100fcab2ef6fb398547330bd5dfb068b5c90f (diff) | |
parent | 1225f719fe920587ebbe4170fc5aee1d87eadc22 (diff) |
Merge #3809
3809: Less config r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_project_model/src/cargo_workspace.rs')
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index f4fd6ad28..c1b6e1ddc 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -13,7 +13,6 @@ use cargo_metadata::{BuildScript, CargoOpt, Message, MetadataCommand, PackageId} | |||
13 | use ra_arena::{Arena, Idx}; | 13 | use ra_arena::{Arena, Idx}; |
14 | use ra_db::Edition; | 14 | use ra_db::Edition; |
15 | use rustc_hash::FxHashMap; | 15 | use rustc_hash::FxHashMap; |
16 | use serde::Deserialize; | ||
17 | 16 | ||
18 | /// `CargoWorkspace` represents the logical structure of, well, a Cargo | 17 | /// `CargoWorkspace` represents the logical structure of, well, a Cargo |
19 | /// workspace. It pretty closely mirrors `cargo metadata` output. | 18 | /// workspace. It pretty closely mirrors `cargo metadata` output. |
@@ -43,9 +42,8 @@ impl ops::Index<Target> for CargoWorkspace { | |||
43 | } | 42 | } |
44 | } | 43 | } |
45 | 44 | ||
46 | #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] | 45 | #[derive(Clone, Debug, PartialEq, Eq)] |
47 | #[serde(rename_all = "camelCase", default)] | 46 | pub struct CargoConfig { |
48 | pub struct CargoFeatures { | ||
49 | /// Do not activate the `default` feature. | 47 | /// Do not activate the `default` feature. |
50 | pub no_default_features: bool, | 48 | pub no_default_features: bool, |
51 | 49 | ||
@@ -60,9 +58,9 @@ pub struct CargoFeatures { | |||
60 | pub load_out_dirs_from_check: bool, | 58 | pub load_out_dirs_from_check: bool, |
61 | } | 59 | } |
62 | 60 | ||
63 | impl Default for CargoFeatures { | 61 | impl Default for CargoConfig { |
64 | fn default() -> Self { | 62 | fn default() -> Self { |
65 | CargoFeatures { | 63 | CargoConfig { |
66 | no_default_features: false, | 64 | no_default_features: false, |
67 | all_features: true, | 65 | all_features: true, |
68 | features: Vec::new(), | 66 | features: Vec::new(), |
@@ -141,7 +139,7 @@ impl PackageData { | |||
141 | impl CargoWorkspace { | 139 | impl CargoWorkspace { |
142 | pub fn from_cargo_metadata( | 140 | pub fn from_cargo_metadata( |
143 | cargo_toml: &Path, | 141 | cargo_toml: &Path, |
144 | cargo_features: &CargoFeatures, | 142 | cargo_features: &CargoConfig, |
145 | ) -> Result<CargoWorkspace> { | 143 | ) -> Result<CargoWorkspace> { |
146 | let mut meta = MetadataCommand::new(); | 144 | let mut meta = MetadataCommand::new(); |
147 | meta.manifest_path(cargo_toml); | 145 | meta.manifest_path(cargo_toml); |
@@ -275,7 +273,7 @@ pub struct ExternResources { | |||
275 | 273 | ||
276 | pub fn load_extern_resources( | 274 | pub fn load_extern_resources( |
277 | cargo_toml: &Path, | 275 | cargo_toml: &Path, |
278 | cargo_features: &CargoFeatures, | 276 | cargo_features: &CargoConfig, |
279 | ) -> Result<ExternResources> { | 277 | ) -> Result<ExternResources> { |
280 | let mut cmd = Command::new(cargo_binary()); | 278 | let mut cmd = Command::new(cargo_binary()); |
281 | cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml); | 279 | cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml); |
@@ -293,9 +291,8 @@ pub fn load_extern_resources( | |||
293 | 291 | ||
294 | let mut res = ExternResources::default(); | 292 | let mut res = ExternResources::default(); |
295 | 293 | ||
296 | let stdout = String::from_utf8(output.stdout)?; | 294 | for message in cargo_metadata::parse_messages(output.stdout.as_slice()) { |
297 | for line in stdout.lines() { | 295 | if let Ok(message) = message { |
298 | if let Ok(message) = serde_json::from_str::<cargo_metadata::Message>(&line) { | ||
299 | match message { | 296 | match message { |
300 | Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => { | 297 | Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => { |
301 | res.out_dirs.insert(package_id, out_dir); | 298 | res.out_dirs.insert(package_id, out_dir); |