ros2_client/
distributions.rs1use std::fmt;
13
14#[allow(unused_imports)]
15use log::{error, info, warn};
16
17#[non_exhaustive]
23#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
24pub enum RosDistro {
25 Galactic,
26 Humble,
27 Iron,
28 Jazzy,
29 Kilted,
30 Lyrical,
31}
32
33impl RosDistro {
34 pub const fn as_str(self) -> &'static str {
37 match self {
38 RosDistro::Galactic => "galactic",
39 RosDistro::Humble => "humble",
40 RosDistro::Iron => "iron",
41 RosDistro::Jazzy => "jazzy",
42 RosDistro::Kilted => "kilted",
43 RosDistro::Lyrical => "lyrical",
44 }
45 }
46}
47
48impl fmt::Display for RosDistro {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 f.write_str(self.as_str())
51 }
52}
53
54pub const COMPILED_ROS_DISTRO: RosDistro = compiled_distro();
57
58const fn compiled_distro() -> RosDistro {
59 if cfg!(feature = "lyrical") {
62 RosDistro::Lyrical
63 } else if cfg!(feature = "kilted") {
64 RosDistro::Kilted
65 } else if cfg!(feature = "jazzy") {
66 RosDistro::Jazzy
67 } else if cfg!(feature = "iron") {
68 RosDistro::Iron
69 } else if cfg!(feature = "humble") {
70 RosDistro::Humble
71 } else {
72 RosDistro::Galactic
73 }
74}
75
76pub fn verify_ros_distro_env() {
84 let built = COMPILED_ROS_DISTRO;
85 match std::env::var("ROS_DISTRO") {
86 Err(_) => warn!("ROS_DISTRO is not set; ros2-client was built for '{built}'."),
87 Ok(distro) if distro == built.as_str() => {
88 info!("ROS_DISTRO='{distro}' matches the ros2-client build.");
89 }
90 Ok(distro) if distro == "rolling" => {
91 warn!(
92 "ROS_DISTRO='rolling'; ros2-client was built for '{built}'. Assuming compatible, but \
93 rolling may have diverged."
94 );
95 }
96 Ok(distro) => {
97 error!(
98 "ROS_DISTRO='{distro}' but ros2-client was built for '{built}'. These may be \
99 incompatible (e.g. different Gid format); rebuild with --features {distro}."
100 );
101 }
102 }
103}