diff options
author | Dmitry <[email protected]> | 2020-08-09 14:35:51 +0100 |
---|---|---|
committer | Dmitry <[email protected]> | 2020-08-09 14:39:32 +0100 |
commit | 8068302fefc75440b823f4bf1731a5f347d7c767 (patch) | |
tree | 251b967182e79bc82a58c2fb208c688f6152df1f /crates/ra_project_model/src | |
parent | 1a43a0f63e0008787225abb6fb2baef97b6a39e0 (diff) | |
parent | 8a57afe5a4bfab40072a83f7dc4ca560bf860919 (diff) |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 29 | ||||
-rw-r--r-- | crates/ra_project_model/src/cfg_flag.rs | 4 | ||||
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 90 |
3 files changed, 71 insertions, 52 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index fb88e0f06..10513542e 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -144,12 +144,15 @@ impl CargoWorkspace { | |||
144 | meta.manifest_path(cargo_toml.to_path_buf()); | 144 | meta.manifest_path(cargo_toml.to_path_buf()); |
145 | if cargo_features.all_features { | 145 | if cargo_features.all_features { |
146 | meta.features(CargoOpt::AllFeatures); | 146 | meta.features(CargoOpt::AllFeatures); |
147 | } else if cargo_features.no_default_features { | 147 | } else { |
148 | // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` | 148 | if cargo_features.no_default_features { |
149 | // https://github.com/oli-obk/cargo_metadata/issues/79 | 149 | // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` |
150 | meta.features(CargoOpt::NoDefaultFeatures); | 150 | // https://github.com/oli-obk/cargo_metadata/issues/79 |
151 | } else if !cargo_features.features.is_empty() { | 151 | meta.features(CargoOpt::NoDefaultFeatures); |
152 | meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone())); | 152 | } |
153 | if !cargo_features.features.is_empty() { | ||
154 | meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone())); | ||
155 | } | ||
153 | } | 156 | } |
154 | if let Some(parent) = cargo_toml.parent() { | 157 | if let Some(parent) = cargo_toml.parent() { |
155 | meta.current_dir(parent.to_path_buf()); | 158 | meta.current_dir(parent.to_path_buf()); |
@@ -289,12 +292,16 @@ pub fn load_extern_resources( | |||
289 | cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml); | 292 | cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml); |
290 | if cargo_features.all_features { | 293 | if cargo_features.all_features { |
291 | cmd.arg("--all-features"); | 294 | cmd.arg("--all-features"); |
292 | } else if cargo_features.no_default_features { | ||
293 | // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` | ||
294 | // https://github.com/oli-obk/cargo_metadata/issues/79 | ||
295 | cmd.arg("--no-default-features"); | ||
296 | } else { | 295 | } else { |
297 | cmd.args(&cargo_features.features); | 296 | if cargo_features.no_default_features { |
297 | // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` | ||
298 | // https://github.com/oli-obk/cargo_metadata/issues/79 | ||
299 | cmd.arg("--no-default-features"); | ||
300 | } | ||
301 | if !cargo_features.features.is_empty() { | ||
302 | cmd.arg("--features"); | ||
303 | cmd.arg(cargo_features.features.join(" ")); | ||
304 | } | ||
298 | } | 305 | } |
299 | 306 | ||
300 | let output = cmd.output()?; | 307 | let output = cmd.output()?; |
diff --git a/crates/ra_project_model/src/cfg_flag.rs b/crates/ra_project_model/src/cfg_flag.rs index 1bc5d4832..bd50056c6 100644 --- a/crates/ra_project_model/src/cfg_flag.rs +++ b/crates/ra_project_model/src/cfg_flag.rs | |||
@@ -4,7 +4,7 @@ | |||
4 | use std::str::FromStr; | 4 | use std::str::FromStr; |
5 | 5 | ||
6 | use ra_cfg::CfgOptions; | 6 | use ra_cfg::CfgOptions; |
7 | use stdx::split_delim; | 7 | use stdx::split_once; |
8 | 8 | ||
9 | #[derive(Clone, Eq, PartialEq, Debug)] | 9 | #[derive(Clone, Eq, PartialEq, Debug)] |
10 | pub enum CfgFlag { | 10 | pub enum CfgFlag { |
@@ -15,7 +15,7 @@ pub enum CfgFlag { | |||
15 | impl FromStr for CfgFlag { | 15 | impl FromStr for CfgFlag { |
16 | type Err = String; | 16 | type Err = String; |
17 | fn from_str(s: &str) -> Result<Self, Self::Err> { | 17 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
18 | let res = match split_delim(s, '=') { | 18 | let res = match split_once(s, '=') { |
19 | Some((key, value)) => { | 19 | Some((key, value)) => { |
20 | if !(value.starts_with('"') && value.ends_with('"')) { | 20 | if !(value.starts_with('"') && value.ends_with('"')) { |
21 | return Err(format!("Invalid cfg ({:?}), value should be in quotes", s)); | 21 | return Err(format!("Invalid cfg ({:?}), value should be in quotes", s)); |
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 8a92acea5..a10ade375 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -54,6 +54,8 @@ impl Sysroot { | |||
54 | let src = get_or_install_rust_src(cargo_toml)?; | 54 | let src = get_or_install_rust_src(cargo_toml)?; |
55 | let mut sysroot = Sysroot { crates: Arena::default() }; | 55 | let mut sysroot = Sysroot { crates: Arena::default() }; |
56 | for name in SYSROOT_CRATES.trim().lines() { | 56 | for name in SYSROOT_CRATES.trim().lines() { |
57 | // FIXME: remove this path when 1.47 comes out | ||
58 | // https://github.com/rust-lang/rust/pull/73265 | ||
57 | let root = src.join(format!("lib{}", name)).join("lib.rs"); | 59 | let root = src.join(format!("lib{}", name)).join("lib.rs"); |
58 | if root.exists() { | 60 | if root.exists() { |
59 | sysroot.crates.alloc(SysrootCrateData { | 61 | sysroot.crates.alloc(SysrootCrateData { |
@@ -61,6 +63,15 @@ impl Sysroot { | |||
61 | root, | 63 | root, |
62 | deps: Vec::new(), | 64 | deps: Vec::new(), |
63 | }); | 65 | }); |
66 | } else { | ||
67 | let root = src.join(name).join("src/lib.rs"); | ||
68 | if root.exists() { | ||
69 | sysroot.crates.alloc(SysrootCrateData { | ||
70 | name: name.into(), | ||
71 | root, | ||
72 | deps: Vec::new(), | ||
73 | }); | ||
74 | } | ||
64 | } | 75 | } |
65 | } | 76 | } |
66 | if let Some(std) = sysroot.std() { | 77 | if let Some(std) = sysroot.std() { |
@@ -94,23 +105,38 @@ fn get_or_install_rust_src(cargo_toml: &AbsPath) -> Result<AbsPathBuf> { | |||
94 | rustc.current_dir(current_dir).args(&["--print", "sysroot"]); | 105 | rustc.current_dir(current_dir).args(&["--print", "sysroot"]); |
95 | let stdout = utf8_stdout(rustc)?; | 106 | let stdout = utf8_stdout(rustc)?; |
96 | let sysroot_path = AbsPath::assert(Path::new(stdout.trim())); | 107 | let sysroot_path = AbsPath::assert(Path::new(stdout.trim())); |
97 | let src_path = sysroot_path.join("lib/rustlib/src/rust/src"); | 108 | let mut src = get_rust_src(sysroot_path); |
98 | 109 | if src.is_none() { | |
99 | if !src_path.exists() { | ||
100 | let mut rustup = Command::new(ra_toolchain::rustup()); | 110 | let mut rustup = Command::new(ra_toolchain::rustup()); |
101 | rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]); | 111 | rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]); |
102 | utf8_stdout(rustup)?; | 112 | utf8_stdout(rustup)?; |
113 | src = get_rust_src(sysroot_path); | ||
103 | } | 114 | } |
104 | if !src_path.exists() { | 115 | match src { |
105 | bail!( | 116 | Some(r) => Ok(r), |
117 | None => bail!( | ||
106 | "can't load standard library from sysroot\n\ | 118 | "can't load standard library from sysroot\n\ |
107 | {}\n\ | 119 | {}\n\ |
108 | (discovered via `rustc --print sysroot`)\n\ | 120 | (discovered via `rustc --print sysroot`)\n\ |
109 | try running `rustup component add rust-src` or set `RUST_SRC_PATH`", | 121 | try running `rustup component add rust-src` or set `RUST_SRC_PATH`", |
110 | src_path.display(), | 122 | sysroot_path.display(), |
111 | ) | 123 | ), |
124 | } | ||
125 | } | ||
126 | |||
127 | fn get_rust_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> { | ||
128 | // try the new path first since the old one still exists | ||
129 | let mut src_path = sysroot_path.join("lib/rustlib/src/rust/library"); | ||
130 | if !src_path.exists() { | ||
131 | // FIXME: remove this path when 1.47 comes out | ||
132 | // https://github.com/rust-lang/rust/pull/73265 | ||
133 | src_path = sysroot_path.join("lib/rustlib/src/rust/src"); | ||
134 | } | ||
135 | if src_path.exists() { | ||
136 | Some(src_path) | ||
137 | } else { | ||
138 | None | ||
112 | } | 139 | } |
113 | Ok(src_path) | ||
114 | } | 140 | } |
115 | 141 | ||
116 | impl SysrootCrateData { | 142 | impl SysrootCrateData { |
@@ -120,42 +146,28 @@ impl SysrootCrateData { | |||
120 | } | 146 | } |
121 | 147 | ||
122 | const SYSROOT_CRATES: &str = " | 148 | const SYSROOT_CRATES: &str = " |
123 | std | ||
124 | core | ||
125 | alloc | 149 | alloc |
126 | collections | 150 | core |
127 | libc | ||
128 | proc_macro | ||
129 | rustc_unicode | ||
130 | std_unicode | ||
131 | test | ||
132 | alloc_jemalloc | ||
133 | alloc_system | ||
134 | compiler_builtins | ||
135 | getopts | ||
136 | panic_unwind | ||
137 | panic_abort | 151 | panic_abort |
138 | rand | 152 | panic_unwind |
153 | proc_macro | ||
154 | profiler_builtins | ||
155 | rtstartup | ||
156 | std | ||
157 | stdarch | ||
139 | term | 158 | term |
140 | unwind | 159 | test |
141 | build_helper | 160 | unwind"; |
142 | rustc_asan | ||
143 | rustc_lsan | ||
144 | rustc_msan | ||
145 | rustc_tsan | ||
146 | syntax"; | ||
147 | 161 | ||
148 | const STD_DEPS: &str = " | 162 | const STD_DEPS: &str = " |
149 | alloc | 163 | alloc |
150 | alloc_jemalloc | ||
151 | alloc_system | ||
152 | core | 164 | core |
153 | panic_abort | 165 | panic_abort |
154 | rand | 166 | panic_unwind |
155 | compiler_builtins | 167 | profiler_builtins |
156 | unwind | 168 | rtstartup |
157 | rustc_asan | 169 | proc_macro |
158 | rustc_lsan | 170 | stdarch |
159 | rustc_msan | 171 | term |
160 | rustc_tsan | 172 | test |
161 | build_helper"; | 173 | unwind"; |