Skip to content

Commit e9c290b

Browse files
committed
Make detection more robust
1 parent 8e37948 commit e9c290b

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/windows_registry.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ mod impl_ {
181181
use std::fs::File;
182182
use std::io::Read;
183183
use std::mem;
184+
use std::iter;
184185
use std::path::{Path, PathBuf};
185186

186187
use Tool;
@@ -217,28 +218,35 @@ mod impl_ {
217218
}
218219
}
219220

220-
fn vs16_instance() -> Option<PathBuf> {
221-
vs15_instances()?.find_map(|instance| {
221+
fn vs16_instances() -> Box<Iterator<Item=PathBuf>> {
222+
let instances = if let Some(instances) = vs15_instances() {
223+
instances
224+
} else {
225+
return Box::new(iter::empty());
226+
};
227+
Box::new(instances.filter_map(|instance| {
222228
let instance = instance.ok()?;
223-
let installation_name = instance.installation_name().ok()?;;
229+
let installation_name = instance.installation_name().ok()?;
224230
if installation_name.to_str()?.starts_with("VisualStudio/16.") {
225231
Some(PathBuf::from(instance.installation_path().ok()?))
226232
} else {
227233
None
228234
}
229-
})
235+
}))
230236
}
231237

232238
fn find_tool_in_vs16_path(tool: &str, target: &str) -> Option<Tool> {
233-
let path = vs16_instance()?.join(tool);
234-
if !path.is_file() {
235-
return None;
236-
}
237-
let mut tool = Tool::new(path);
238-
if target.contains("x86_64") {
239-
tool.env.push(("Platform".into(), "X64".into()));
240-
}
241-
Some(tool)
239+
vs16_instances().find_map(|path| {
240+
let path = path.join(tool);
241+
if !path.is_file() {
242+
return None;
243+
}
244+
let mut tool = Tool::new(path);
245+
if target.contains("x86_64") {
246+
tool.env.push(("Platform".into(), "X64".into()));
247+
}
248+
Some(tool)
249+
})
242250
}
243251

244252
fn find_msbuild_vs16(target: &str) -> Option<Tool> {

0 commit comments

Comments
 (0)