From 94e0e5d6c73c33057629864189ffac6eb182394a Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 19 Aug 2024 02:23:49 +0200 Subject: [PATCH] build.rs: small cleanup --- build.rs | 64 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/build.rs b/build.rs index f5bce0e..1507125 100644 --- a/build.rs +++ b/build.rs @@ -3,40 +3,44 @@ use anyhow::anyhow; #[cfg(feature = "mysql-admutils-compatibility")] use std::{env, os::unix::fs::symlink, path::PathBuf}; -fn main() -> 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, - // and not critical in any way. Considering the code is never going - // to be used as a library, it should be fine. - let target_profile_dir: PathBuf = PathBuf::from(env::var("OUT_DIR")?) - .parent() - .and_then(|p| p.parent()) - .and_then(|p| p.parent()) - .ok_or(anyhow!("Could not resolve target profile directory"))? - .to_path_buf(); +fn generate_mysql_admutils_symlinks() -> anyhow::Result<()> { + // NOTE: This is slightly illegal, and depends on implementation details. + // But it is only here for ease of testing the compatibility layer, + // and not critical in any way. Considering the code is never going + // to be used as a library, it should be fine. + let target_profile_dir: PathBuf = PathBuf::from(env::var("OUT_DIR")?) + .parent() + .and_then(|p| p.parent()) + .and_then(|p| p.parent()) + .ok_or(anyhow!("Could not resolve target profile directory"))? + .to_path_buf(); - if !target_profile_dir.exists() { - std::fs::create_dir_all(&target_profile_dir)?; - } + if !target_profile_dir.exists() { + std::fs::create_dir_all(&target_profile_dir)?; + } - if !target_profile_dir.join("mysql-useradm").exists() { - symlink( - target_profile_dir.join("mysqladm"), - target_profile_dir.join("mysql-useradm"), - ) - .ok(); - } + if !target_profile_dir.join("mysql-useradm").exists() { + symlink( + target_profile_dir.join("mysqladm"), + target_profile_dir.join("mysql-useradm"), + ) + .ok(); + } - if !target_profile_dir.join("mysql-dbadm").exists() { - symlink( - target_profile_dir.join("mysqladm"), - target_profile_dir.join("mysql-dbadm"), - ) - .ok(); - } + if !target_profile_dir.join("mysql-dbadm").exists() { + symlink( + target_profile_dir.join("mysqladm"), + target_profile_dir.join("mysql-dbadm"), + ) + .ok(); } Ok(()) } + +fn main() -> anyhow::Result<()> { + #[cfg(feature = "mysql-admutils-compatibility")] + generate_mysql_admutils_symlinks()?; + + Ok(()) +}