Skip to content

Commit cee2fd0

Browse files
committed
Use openblas_build::error::Error in FromStr of Target #78
1 parent 677ff02 commit cee2fd0

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

openblas-build/src/build.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::{check::*, error::*};
44
use std::{
5-
fmt, fs,
5+
fs,
66
os::unix::io::*,
77
path::*,
88
process::{Command, Stdio},
@@ -118,7 +118,7 @@ pub enum Target {
118118
}
119119

120120
impl FromStr for Target {
121-
type Err = ParseTargetError;
121+
type Err = Error;
122122

123123
fn from_str(s: &str) -> Result<Self, Self::Err> {
124124
let target = match s.to_ascii_lowercase().as_str() {
@@ -195,21 +195,16 @@ impl FromStr for Target {
195195
"zarch_generic" => Self::ZARCH_GENERIC,
196196
"z13" => Self::Z13,
197197
"z14" => Self::Z14,
198-
_ => return Err(ParseTargetError::default()),
198+
_ => {
199+
return Err(Error::UnsupportedTarget {
200+
target: s.to_string(),
201+
})
202+
}
199203
};
200204
Ok(target)
201205
}
202206
}
203207

204-
#[derive(Debug, Clone, PartialEq, Eq, Default)]
205-
pub struct ParseTargetError;
206-
207-
impl fmt::Display for ParseTargetError {
208-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
209-
"provided string was not a valid target".fmt(f)
210-
}
211-
}
212-
213208
/// make option generator
214209
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
215210
pub struct Configure {
@@ -408,6 +403,15 @@ impl Configure {
408403
mod tests {
409404
use super::*;
410405

406+
#[test]
407+
fn target_from_str() {
408+
assert_eq!(Target::from_str("p2").unwrap(), Target::P2);
409+
assert!(matches!(
410+
Target::from_str("p3").unwrap_err(),
411+
crate::error::Error::UnsupportedTarget { .. }
412+
));
413+
}
414+
411415
#[ignore]
412416
#[test]
413417
fn build_default() {

openblas-build/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pub enum Error {
2121
#[error("Library file does not exist: {}", path.display())]
2222
LibraryNotExist { path: PathBuf },
2323

24+
#[error("Target {} is unsupported", target)]
25+
UnsupportedTarget { target: String },
26+
2427
#[error("Other IO errors: {0:?}")]
2528
IOError(#[from] io::Error),
2629
}

0 commit comments

Comments
 (0)