use std::fmt;
#[allow(unused_imports)]
use log::{error, info, warn};
#[non_exhaustive]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum RosDistro {
Galactic,
Humble,
Iron,
Jazzy,
Kilted,
Lyrical,
}
impl RosDistro {
pub const fn as_str(self) -> &'static str {
match self {
RosDistro::Galactic => "galactic",
RosDistro::Humble => "humble",
RosDistro::Iron => "iron",
RosDistro::Jazzy => "jazzy",
RosDistro::Kilted => "kilted",
RosDistro::Lyrical => "lyrical",
}
}
}
impl fmt::Display for RosDistro {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
pub const COMPILED_ROS_DISTRO: RosDistro = compiled_distro();
const fn compiled_distro() -> RosDistro {
if cfg!(feature = "lyrical") {
RosDistro::Lyrical
} else if cfg!(feature = "kilted") {
RosDistro::Kilted
} else if cfg!(feature = "jazzy") {
RosDistro::Jazzy
} else if cfg!(feature = "iron") {
RosDistro::Iron
} else if cfg!(feature = "humble") {
RosDistro::Humble
} else {
RosDistro::Galactic
}
}
pub fn verify_ros_distro_env() {
let built = COMPILED_ROS_DISTRO;
match std::env::var("ROS_DISTRO") {
Err(_) => warn!("ROS_DISTRO is not set; ros2-client was built for '{built}'."),
Ok(distro) if distro == built.as_str() => {
info!("ROS_DISTRO='{distro}' matches the ros2-client build.");
}
Ok(distro) if distro == "rolling" => {
warn!(
"ROS_DISTRO='rolling'; ros2-client was built for '{built}'. Assuming compatible, but \
rolling may have diverged."
);
}
Ok(distro) => {
error!(
"ROS_DISTRO='{distro}' but ros2-client was built for '{built}'. These may be \
incompatible (e.g. different Gid format); rebuild with --features {distro}."
);
}
}
}