aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
authorDmitry <[email protected]>2020-08-09 14:35:51 +0100
committerDmitry <[email protected]>2020-08-09 14:39:32 +0100
commit8068302fefc75440b823f4bf1731a5f347d7c767 (patch)
tree251b967182e79bc82a58c2fb208c688f6152df1f /crates/ra_project_model
parent1a43a0f63e0008787225abb6fb2baef97b6a39e0 (diff)
parent8a57afe5a4bfab40072a83f7dc4ca560bf860919 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/Cargo.toml2
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs29
-rw-r--r--crates/ra_project_model/src/cfg_flag.rs4
-rw-r--r--crates/ra_project_model/src/sysroot.rs90
4 files changed, 72 insertions, 53 deletions
diff --git a/crates/ra_project_model/Cargo.toml b/crates/ra_project_model/Cargo.toml
index 827eb7e28..99adea8e4 100644
--- a/crates/ra_project_model/Cargo.toml
+++ b/crates/ra_project_model/Cargo.toml
@@ -12,7 +12,7 @@ doctest = false
12log = "0.4.8" 12log = "0.4.8"
13rustc-hash = "1.1.0" 13rustc-hash = "1.1.0"
14 14
15cargo_metadata = "0.10.0" 15cargo_metadata = "0.11.1"
16 16
17ra_arena = { path = "../ra_arena" } 17ra_arena = { path = "../ra_arena" }
18ra_cfg = { path = "../ra_cfg" } 18ra_cfg = { path = "../ra_cfg" }
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 @@
4use std::str::FromStr; 4use std::str::FromStr;
5 5
6use ra_cfg::CfgOptions; 6use ra_cfg::CfgOptions;
7use stdx::split_delim; 7use stdx::split_once;
8 8
9#[derive(Clone, Eq, PartialEq, Debug)] 9#[derive(Clone, Eq, PartialEq, Debug)]
10pub enum CfgFlag { 10pub enum CfgFlag {
@@ -15,7 +15,7 @@ pub enum CfgFlag {
15impl FromStr for CfgFlag { 15impl 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
127fn 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
116impl SysrootCrateData { 142impl SysrootCrateData {
@@ -120,42 +146,28 @@ impl SysrootCrateData {
120} 146}
121 147
122const SYSROOT_CRATES: &str = " 148const SYSROOT_CRATES: &str = "
123std
124core
125alloc 149alloc
126collections 150core
127libc
128proc_macro
129rustc_unicode
130std_unicode
131test
132alloc_jemalloc
133alloc_system
134compiler_builtins
135getopts
136panic_unwind
137panic_abort 151panic_abort
138rand 152panic_unwind
153proc_macro
154profiler_builtins
155rtstartup
156std
157stdarch
139term 158term
140unwind 159test
141build_helper 160unwind";
142rustc_asan
143rustc_lsan
144rustc_msan
145rustc_tsan
146syntax";
147 161
148const STD_DEPS: &str = " 162const STD_DEPS: &str = "
149alloc 163alloc
150alloc_jemalloc
151alloc_system
152core 164core
153panic_abort 165panic_abort
154rand 166panic_unwind
155compiler_builtins 167profiler_builtins
156unwind 168rtstartup
157rustc_asan 169proc_macro
158rustc_lsan 170stdarch
159rustc_msan 171term
160rustc_tsan 172test
161build_helper"; 173unwind";