Skip to content

Commit

Permalink
Retry only when the envvar is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
yutannihilation committed Feb 2, 2022
1 parent c13c80f commit 6f66e41
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ fn probe_r_paths() -> io::Result<InstallationPaths> {
})
}

// Parse an R version (e.g. "4.1.2" and "4.2.0-devel") and return the RVersionInfo.
fn parse_r_version(
r_version: String,
version_string: Option<String>,
Expand Down Expand Up @@ -287,10 +288,15 @@ fn get_r_version(
r_version_env_var: &str,
r_paths: &InstallationPaths,
) -> Result<RVersionInfo, EnvVarError> {
// Try looking for the envvar first.
match get_r_version_from_env(r_version_env_var) {
// If the envvar is found and it can be parsed as a valid RVersionInfo, use it.
Ok(v) => Ok(v),
e @ Err(EnvVarError::InvalidEnvVar(_)) => e,
Err(_) => get_r_version_from_r(r_paths),
// If the envvar is not present, then use the actual R binary to get the version.
Err(EnvVarError::EnvVarNotPresent) => get_r_version_from_r(r_paths),
// In the case of any other error than the absense of envvar, stop with
// that error because it means the envvar is set and something is wrong.
e @ Err(_) => e,
}
}

Expand Down

0 comments on commit 6f66e41

Please sign in to comment.