build.rs: small cleanup

This commit is contained in:
Oystein Kristoffer Tveit 2024-08-19 02:23:49 +02:00
parent 807017ea70
commit 94e0e5d6c7
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
1 changed files with 34 additions and 30 deletions

View File

@ -3,40 +3,44 @@ use anyhow::anyhow;
#[cfg(feature = "mysql-admutils-compatibility")] #[cfg(feature = "mysql-admutils-compatibility")]
use std::{env, os::unix::fs::symlink, path::PathBuf}; use std::{env, os::unix::fs::symlink, path::PathBuf};
fn main() -> anyhow::Result<()> { fn generate_mysql_admutils_symlinks() -> anyhow::Result<()> {
#[cfg(feature = "mysql-admutils-compatibility")] // NOTE: This is slightly illegal, and depends on implementation details.
{ // But it is only here for ease of testing the compatibility layer,
// NOTE: This is slightly illegal, and depends on implementation details. // and not critical in any way. Considering the code is never going
// But it is only here for ease of testing the compatibility layer, // to be used as a library, it should be fine.
// and not critical in any way. Considering the code is never going let target_profile_dir: PathBuf = PathBuf::from(env::var("OUT_DIR")?)
// to be used as a library, it should be fine. .parent()
let target_profile_dir: PathBuf = PathBuf::from(env::var("OUT_DIR")?) .and_then(|p| p.parent())
.parent() .and_then(|p| p.parent())
.and_then(|p| p.parent()) .ok_or(anyhow!("Could not resolve target profile directory"))?
.and_then(|p| p.parent()) .to_path_buf();
.ok_or(anyhow!("Could not resolve target profile directory"))?
.to_path_buf();
if !target_profile_dir.exists() { if !target_profile_dir.exists() {
std::fs::create_dir_all(&target_profile_dir)?; std::fs::create_dir_all(&target_profile_dir)?;
} }
if !target_profile_dir.join("mysql-useradm").exists() { if !target_profile_dir.join("mysql-useradm").exists() {
symlink( symlink(
target_profile_dir.join("mysqladm"), target_profile_dir.join("mysqladm"),
target_profile_dir.join("mysql-useradm"), target_profile_dir.join("mysql-useradm"),
) )
.ok(); .ok();
} }
if !target_profile_dir.join("mysql-dbadm").exists() { if !target_profile_dir.join("mysql-dbadm").exists() {
symlink( symlink(
target_profile_dir.join("mysqladm"), target_profile_dir.join("mysqladm"),
target_profile_dir.join("mysql-dbadm"), target_profile_dir.join("mysql-dbadm"),
) )
.ok(); .ok();
}
} }
Ok(()) Ok(())
} }
fn main() -> anyhow::Result<()> {
#[cfg(feature = "mysql-admutils-compatibility")]
generate_mysql_admutils_symlinks()?;
Ok(())
}