diff --git a/crates/pixi_build_ros/src/build_script.rs b/crates/pixi_build_ros/src/build_script.rs index c5617eb45f..fe3a19633d 100644 --- a/crates/pixi_build_ros/src/build_script.rs +++ b/crates/pixi_build_ros/src/build_script.rs @@ -6,6 +6,8 @@ use miette::Diagnostic; use rattler_conda_types::Subdir; use thiserror::Error; +use crate::distro::Distro; + /// Errors that can occur during build script generation. #[derive(Debug, Error, Diagnostic)] pub enum BuildScriptError { @@ -20,7 +22,7 @@ pub enum BuildScriptError { /// variable substitution. pub fn render_build_script( build_type: &str, - distro: &str, + distro: &Distro, source_dir: &Path, ) -> Result { // Use the current (build) platform, not the host/target platform. @@ -31,7 +33,8 @@ pub fn render_build_script( let src_dir_str = source_dir.display().to_string(); let rendered = template .replace("@SRC_DIR@", &src_dir_str) - .replace("@DISTRO@", distro) + .replace("@DISTRO@", &distro.name) + .replace("@PACKAGE_PREFIX@", &distro.package_prefix()) .replace("@BUILD_DIR@", "build") .replace("@BUILD_TYPE@", "Release"); @@ -57,36 +60,13 @@ mod tests { use super::*; use std::path::PathBuf; - #[test] - fn test_render_ament_cmake() { - let script = - render_build_script("ament_cmake", "humble", &PathBuf::from("/my/source")).unwrap(); - - assert!(script.contains("/my/source")); - assert!(script.contains("Release")); - assert!(!script.contains("@SRC_DIR@")); - assert!(!script.contains("@BUILD_TYPE@")); - } - - #[test] - fn test_render_ament_python() { - let script = render_build_script("ament_python", "jazzy", &PathBuf::from("/src")).unwrap(); - - assert!(script.contains("/src")); - assert!(!script.contains("@SRC_DIR@")); - } - - #[test] - fn test_render_catkin() { - let script = render_build_script("catkin", "noetic", &PathBuf::from("/pkg")).unwrap(); - - assert!(script.contains("/pkg")); - assert!(script.contains("noetic")); - } - #[test] fn test_unsupported_build_type() { - let result = render_build_script("unknown_type", "jazzy", &PathBuf::from("/src")); + let result = render_build_script( + "unknown_type", + &Distro::new("jazzy"), + &PathBuf::from("/src"), + ); assert!(matches!( result, Err(BuildScriptError::UnsupportedBuildType { .. }) diff --git a/crates/pixi_build_ros/src/distro.rs b/crates/pixi_build_ros/src/distro.rs index 20020e0aef..203de4fe08 100644 --- a/crates/pixi_build_ros/src/distro.rs +++ b/crates/pixi_build_ros/src/distro.rs @@ -1,8 +1,9 @@ //! ROS distribution metadata. //! //! Maps a ROS distribution name to the ROS version it belongs to. That version -//! selects the distro mutex package, the `ROS_VERSION` build environment -//! variable, and whether `ros_workspace` is added as a build dependency. +//! selects the conda package names (`ros2-` / `ros-`), the distro +//! mutex package, the `ROS_VERSION` build environment variable, and whether +//! `ros_workspace` is added as a dependency. /// The ROS 1 distributions. /// @@ -78,6 +79,28 @@ impl Distro { let version = RosVersion::for_distro(&name); Self { name, version } } + + /// The prefix of the conda names of this distribution's ROS packages, as + /// RoboStack names them: `ros2` for ROS 2 (the names don't say which + /// distribution a package belongs to; the mutex does) and `ros-` + /// for ROS 1, whose channels (robostack-noetic) only have those names. + pub fn package_prefix(&self) -> String { + match self.version { + RosVersion::Ros1 => format!("ros-{}", self.name), + RosVersion::Ros2 => "ros2".to_string(), + } + } + + /// The conda name of the ROS package `ros_name`, e.g. `ros2-demo-nodes-cpp`. + pub fn conda_name(&self, ros_name: &str) -> String { + format!("{}-{}", self.package_prefix(), ros_name.replace('_', "-")) + } + + /// The distro mutex pinned to this distribution: RoboStack builds the mutex + /// of a distribution with the build string `_`. + pub fn mutex_spec(&self) -> String { + format!("{} * {}_*", self.version.mutex_package_name(), self.name) + } } #[cfg(test)] @@ -133,6 +156,26 @@ mod tests { assert_eq!(RosVersion::Ros2.mutex_package_name(), "ros2-distro-mutex"); } + #[test] + fn test_conda_names() { + assert_eq!( + Distro::new("jazzy").conda_name("demo_nodes_cpp"), + "ros2-demo-nodes-cpp" + ); + assert_eq!( + Distro::new("noetic").conda_name("roscpp"), + "ros-noetic-roscpp" + ); + assert_eq!( + Distro::new("jazzy").mutex_spec(), + "ros2-distro-mutex * jazzy_*" + ); + assert_eq!( + Distro::new("noetic").mutex_spec(), + "ros-distro-mutex * noetic_*" + ); + } + #[test] fn test_env_value() { assert_eq!(RosVersion::Ros1.as_env_value(), "1"); diff --git a/crates/pixi_build_ros/src/main.rs b/crates/pixi_build_ros/src/main.rs index dfd253021b..21639f5e36 100644 --- a/crates/pixi_build_ros/src/main.rs +++ b/crates/pixi_build_ros/src/main.rs @@ -118,7 +118,7 @@ impl GenerateRecipe for RosGenerator { let mut generated_recipe = parse_and_render( package_xml.clone(), - &distro.name, + &distro, model.clone(), extra_input_globs.clone(), package_mapping_files, @@ -180,7 +180,7 @@ impl GenerateRecipe for RosGenerator { &discovery.packages, &package_xml.name, &manifest_root, - &distro.name, + &distro, ); // Apply per-class: a manual entry in the model for the same conda @@ -279,14 +279,18 @@ impl GenerateRecipe for RosGenerator { ))); } - // Add distro mutex to host and run - let mutex_name = distro.version.mutex_package_name(); + // Pin the distribution in each independently solved environment. + let mutex = distro.mutex_spec(); + build_items.push(Item::Value(Value::new_concrete( + SerializableMatchSpec::from(mutex.as_str()), + None, + ))); host_items.push(Item::Value(Value::new_concrete( - SerializableMatchSpec::from(mutex_name), + SerializableMatchSpec::from(mutex.as_str()), None, ))); run_items.push(Item::Value(Value::new_concrete( - SerializableMatchSpec::from(mutex_name), + SerializableMatchSpec::from(mutex.as_str()), None, ))); @@ -298,7 +302,7 @@ impl GenerateRecipe for RosGenerator { // Generate build script let build_type = package_xml.build_type(); - let build_script_content = render_build_script(&build_type, &distro.name, &manifest_root)?; + let build_script_content = render_build_script(&build_type, &distro, &manifest_root)?; let mut script_env: indexmap::IndexMap> = indexmap::IndexMap::new(); script_env.insert( @@ -456,39 +460,39 @@ mod tests { package_xml_to_conda_requirements(&package_xml, &distro, Subdir::Linux64, &package_map) .unwrap(); - insta::assert_yaml_snapshot!(requirements.build, @r###" - - ros-jazzy-ament-cmake - - ros-jazzy-example-interfaces - - ros-jazzy-rcl - - ros-jazzy-rclcpp - - ros-jazzy-rclcpp-components - - ros-jazzy-rcl-interfaces - - ros-jazzy-rcpputils - - ros-jazzy-rcutils - - ros-jazzy-rmw - - ros-jazzy-std-msgs - - ros-jazzy-ament-cmake-pytest - - ros-jazzy-ament-lint-auto - - ros-jazzy-ament-lint-common - - ros-jazzy-launch - - ros-jazzy-launch-testing - - ros-jazzy-launch-testing-ament-cmake - - ros-jazzy-launch-testing-ros - - ros-jazzy-ros-workspace - "###); - insta::assert_yaml_snapshot!(requirements.run, @r###" - - ros-jazzy-example-interfaces - - ros-jazzy-launch-ros - - ros-jazzy-launch-xml - - ros-jazzy-rcl - - ros-jazzy-rclcpp - - ros-jazzy-rclcpp-components - - ros-jazzy-rcl-interfaces - - ros-jazzy-rcpputils - - ros-jazzy-rcutils - - ros-jazzy-rmw - - ros-jazzy-std-msgs - "###); + insta::assert_yaml_snapshot!(requirements.build, @" + - ros2-ament-cmake + - ros2-example-interfaces + - ros2-rcl + - ros2-rclcpp + - ros2-rclcpp-components + - ros2-rcl-interfaces + - ros2-rcpputils + - ros2-rcutils + - ros2-rmw + - ros2-std-msgs + - ros2-ament-cmake-pytest + - ros2-ament-lint-auto + - ros2-ament-lint-common + - ros2-launch + - ros2-launch-testing + - ros2-launch-testing-ament-cmake + - ros2-launch-testing-ros + - ros2-ros-workspace + "); + insta::assert_yaml_snapshot!(requirements.run, @" + - ros2-example-interfaces + - ros2-launch-ros + - ros2-launch-xml + - ros2-rcl + - ros2-rclcpp + - ros2-rclcpp-components + - ros2-rcl-interfaces + - ros2-rcpputils + - ros2-rcutils + - ros2-rmw + - ros2-std-msgs + "); } #[test] @@ -509,13 +513,13 @@ mod tests { package_xml_to_conda_requirements(&package_xml, &distro, Subdir::Linux64, &package_map) .unwrap(); - insta::assert_yaml_snapshot!(requirements.build, @r###" - - ros-jazzy-ament-cmake - - ros-jazzy-rosidl-default-generators - - ros-jazzy-ament-lint-auto - - ros-jazzy-ament-lint-common - - ros-jazzy-ros-workspace - "###); + insta::assert_yaml_snapshot!(requirements.build, @" + - ros2-ament-cmake + - ros2-rosidl-default-generators + - ros2-ament-lint-auto + - ros2-ament-lint-common + - ros2-ros-workspace + "); } #[tokio::test] @@ -563,7 +567,7 @@ mod tests { .as_concrete() .unwrap() .to_string(), - "ros-jazzy-demo-nodes-cpp" + "ros2-demo-nodes-cpp" ); assert_eq!( generated_recipe @@ -576,26 +580,26 @@ mod tests { "0.37.1" ); - insta::assert_yaml_snapshot!(generated_recipe.recipe.requirements, @r###" + insta::assert_yaml_snapshot!(generated_recipe.recipe.requirements, @r#" build: - - ros-jazzy-ament-cmake - - ros-jazzy-example-interfaces - - ros-jazzy-rcl - - ros-jazzy-rclcpp - - ros-jazzy-rclcpp-components - - ros-jazzy-rcl-interfaces - - ros-jazzy-rcpputils - - ros-jazzy-rcutils - - ros-jazzy-rmw - - ros-jazzy-std-msgs - - ros-jazzy-ament-cmake-pytest - - ros-jazzy-ament-lint-auto - - ros-jazzy-ament-lint-common - - ros-jazzy-launch - - ros-jazzy-launch-testing - - ros-jazzy-launch-testing-ament-cmake - - ros-jazzy-launch-testing-ros - - ros-jazzy-ros-workspace + - ros2-ament-cmake + - ros2-example-interfaces + - ros2-rcl + - ros2-rclcpp + - ros2-rclcpp-components + - ros2-rcl-interfaces + - ros2-rcpputils + - ros2-rcutils + - ros2-rmw + - ros2-std-msgs + - ros2-ament-cmake-pytest + - ros2-ament-lint-auto + - ros2-ament-lint-common + - ros2-launch + - ros2-launch-testing + - ros2-launch-testing-ament-cmake + - ros2-launch-testing-ros + - ros2-ros-workspace - ninja - python - setuptools @@ -610,45 +614,46 @@ mod tests { - "${{ compiler('cxx') }}" - if: build_platform != target_platform then: "cross-python_${{ target_platform }}" + - ros2-distro-mutex * jazzy_* host: - - ros-jazzy-ament-cmake - - ros-jazzy-example-interfaces - - ros-jazzy-rcl - - ros-jazzy-rclcpp - - ros-jazzy-rclcpp-components - - ros-jazzy-rcl-interfaces - - ros-jazzy-rcpputils - - ros-jazzy-rcutils - - ros-jazzy-rmw - - ros-jazzy-std-msgs - - ros-jazzy-ament-cmake-pytest - - ros-jazzy-ament-lint-auto - - ros-jazzy-ament-lint-common - - ros-jazzy-launch - - ros-jazzy-launch-testing - - ros-jazzy-launch-testing-ament-cmake - - ros-jazzy-launch-testing-ros - - ros-jazzy-ros-workspace + - ros2-ament-cmake + - ros2-example-interfaces + - ros2-rcl + - ros2-rclcpp + - ros2-rclcpp-components + - ros2-rcl-interfaces + - ros2-rcpputils + - ros2-rcutils + - ros2-rmw + - ros2-std-msgs + - ros2-ament-cmake-pytest + - ros2-ament-lint-auto + - ros2-ament-lint-common + - ros2-launch + - ros2-launch-testing + - ros2-launch-testing-ament-cmake + - ros2-launch-testing-ros + - ros2-ros-workspace - python - numpy - pip - pkg-config - setuptools - - ros2-distro-mutex + - ros2-distro-mutex * jazzy_* run: - - ros-jazzy-example-interfaces - - ros-jazzy-launch-ros - - ros-jazzy-launch-xml - - ros-jazzy-rcl - - ros-jazzy-rclcpp - - ros-jazzy-rclcpp-components - - ros-jazzy-rcl-interfaces - - ros-jazzy-rcpputils - - ros-jazzy-rcutils - - ros-jazzy-rmw - - ros-jazzy-std-msgs - - ros2-distro-mutex - "###); + - ros2-example-interfaces + - ros2-launch-ros + - ros2-launch-xml + - ros2-rcl + - ros2-rclcpp + - ros2-rclcpp-components + - ros2-rcl-interfaces + - ros2-rcpputils + - ros2-rcutils + - ros2-rmw + - ros2-std-msgs + - ros2-distro-mutex * jazzy_* + "#); } /// Helper to generate a recipe from a package.xml fixture. @@ -784,7 +789,7 @@ mod tests { /// to make the snapshot focused. fn filter_conditional_deps(generated: &GeneratedRecipe, distro: &str) -> serde_json::Value { let declared = ["ament-cmake", "catkin", "rclcpp", "roscpp"]; - let prefix = format!("ros-{distro}-"); + let prefix = format!("{}-", Distro::new(distro).package_prefix()); let filter = |list: &rattler_build_recipe::stage0::ConditionalList< SerializableMatchSpec, @@ -816,25 +821,25 @@ mod tests { #[tokio::test] async fn test_condition_evaluation_ros2_default() { let generated = generate_conditional_recipe("jazzy", None).await; - insta::assert_yaml_snapshot!(filter_conditional_deps(&generated, "jazzy"), @r###" + insta::assert_yaml_snapshot!(filter_conditional_deps(&generated, "jazzy"), @" build: - - ros-jazzy-ament-cmake - - ros-jazzy-rclcpp + - ros2-ament-cmake + - ros2-rclcpp run: - - ros-jazzy-rclcpp - "###); + - ros2-rclcpp + "); } #[tokio::test] async fn test_condition_evaluation_ros1_default() { let generated = generate_conditional_recipe("noetic", None).await; - insta::assert_yaml_snapshot!(filter_conditional_deps(&generated, "noetic"), @r###" + insta::assert_yaml_snapshot!(filter_conditional_deps(&generated, "noetic"), @" build: - ros-noetic-catkin - ros-noetic-roscpp run: - ros-noetic-roscpp - "###); + "); } #[tokio::test] @@ -844,13 +849,13 @@ mod tests { ("ROS_DISTRO".to_string(), "custom-jazzy".to_string()), ]); let generated = generate_conditional_recipe("jazzy", Some(env)).await; - insta::assert_yaml_snapshot!(filter_conditional_deps(&generated, "jazzy"), @r###" + insta::assert_yaml_snapshot!(filter_conditional_deps(&generated, "jazzy"), @" build: - - ros-jazzy-catkin - - ros-jazzy-roscpp + - ros2-catkin + - ros2-roscpp run: - - ros-jazzy-roscpp - "###); + - ros2-roscpp + "); } #[tokio::test] @@ -1047,7 +1052,7 @@ mod tests { .as_concrete() .unwrap() .to_string(), - "ros-jazzy-demo-nodes-cpp" + "ros2-demo-nodes-cpp" ); } @@ -1095,7 +1100,7 @@ mod tests { .as_concrete() .unwrap() .to_string(), - "ros-humble-demo-nodes-cpp" + "ros2-demo-nodes-cpp" ); } @@ -1361,19 +1366,18 @@ mod tests { .await .expect("generate_recipe should succeed"); - let sibling_in_build = - find_concrete(&generated.recipe.requirements.build, "ros-jazzy-pkg-b") - .expect("sibling should appear in build requirements"); + let sibling_in_build = find_concrete(&generated.recipe.requirements.build, "ros2-pkg-b") + .expect("sibling should appear in build requirements"); assert!( sibling_in_build.0.url.is_some(), - "expected ros-jazzy-pkg-b to be a source dep, got: {sibling_in_build}" + "expected ros2-pkg-b to be a source dep, got: {sibling_in_build}" ); - let sibling_in_run = find_concrete(&generated.recipe.requirements.run, "ros-jazzy-pkg-b") + let sibling_in_run = find_concrete(&generated.recipe.requirements.run, "ros2-pkg-b") .expect("sibling should also appear in run requirements"); assert!( sibling_in_run.0.url.is_some(), - "expected ros-jazzy-pkg-b in run to be source, got: {sibling_in_run}" + "expected ros2-pkg-b in run to be source, got: {sibling_in_run}" ); } @@ -1408,7 +1412,7 @@ mod tests { .await .expect("generate_recipe should succeed"); - let sibling = find_concrete(&generated.recipe.requirements.build, "ros-jazzy-pkg-b") + let sibling = find_concrete(&generated.recipe.requirements.build, "ros2-pkg-b") .expect("sibling should still be present as binary"); assert!( sibling.0.url.is_none(), @@ -1423,14 +1427,14 @@ mod tests { write_minimal_package_xml(&workspace_root.join("pkg_a"), "pkg_a", &["pkg_b"]); write_minimal_package_xml(&workspace_root.join("pkg_b"), "pkg_b", &[]); - // Model declares ros-jazzy-pkg-b in run only, with an explicit version. + // Model declares ros2-pkg-b in run only, with an explicit version. // Discovery must not override that entry, but build/host still get the // source dep because the manual entry was per-class. let model = project_fixture!({ "targets": { "defaultTarget": { "runDependencies": { - "ros-jazzy-pkg-b": { "binary": { "version": "==1.2.3" } } + "ros2-pkg-b": { "binary": { "version": "==1.2.3" } } } } } @@ -1457,14 +1461,14 @@ mod tests { .await .expect("generate_recipe should succeed"); - let in_run = find_concrete(&generated.recipe.requirements.run, "ros-jazzy-pkg-b") + let in_run = find_concrete(&generated.recipe.requirements.run, "ros2-pkg-b") .expect("run entry should remain"); assert!( in_run.0.url.is_none(), "manual model entry must stay binary, got source: {in_run}" ); - let in_build = find_concrete(&generated.recipe.requirements.build, "ros-jazzy-pkg-b") + let in_build = find_concrete(&generated.recipe.requirements.build, "ros2-pkg-b") .expect("build entry should exist"); assert!( in_build.0.url.is_some(), @@ -1566,7 +1570,7 @@ mod tests { .await .expect("generate_recipe should succeed"); - let sibling = find_concrete(&generated.recipe.requirements.build, "ros-jazzy-pkg-b") + let sibling = find_concrete(&generated.recipe.requirements.build, "ros2-pkg-b") .expect("ignored sibling should still appear via RoboStack fallback"); assert!( sibling.0.url.is_none(), @@ -1603,7 +1607,7 @@ mod tests { .await .expect("generate_recipe should succeed"); - let self_in_build = find_concrete(&generated.recipe.requirements.build, "ros-jazzy-pkg-a"); + let self_in_build = find_concrete(&generated.recipe.requirements.build, "ros2-pkg-a"); assert!( self_in_build.is_none(), "current package must not list itself as a source dep: {self_in_build:?}" diff --git a/crates/pixi_build_ros/src/metadata.rs b/crates/pixi_build_ros/src/metadata.rs index 8e7bc8e813..3e432b2082 100644 --- a/crates/pixi_build_ros/src/metadata.rs +++ b/crates/pixi_build_ros/src/metadata.rs @@ -8,6 +8,7 @@ use pixi_build_backend::generated_recipe::{GeneratedRecipe, MetadataProvider}; use pixi_build_types::ProjectModel; use rattler_conda_types::VersionWithSource; +use crate::distro::Distro; use crate::package_xml::PackageXml; /// Parse a [`PackageXml`] and render a [`GeneratedRecipe`] from the given @@ -15,14 +16,14 @@ use crate::package_xml::PackageXml; /// and collecting input globs. pub fn parse_and_render( package_xml: PackageXml, - distro_name: &str, + distro: &Distro, model: ProjectModel, extra_input_globs: Vec, package_mapping_files: Vec, ) -> miette::Result { let mut provider = RosPackageXmlMetadataProvider { package_data: package_xml, - distro_name: distro_name.to_string(), + distro: distro.clone(), extra_input_globs, package_mapping_files, }; @@ -34,12 +35,11 @@ pub fn parse_and_render( /// Metadata provider for ROS package.xml files. /// -/// Formats package names as `ros--` with underscore-to-hyphen -/// conversion. +/// Names packages as RoboStack does (see [`Distro::conda_name`]). #[derive(Debug)] struct RosPackageXmlMetadataProvider { package_data: PackageXml, - distro_name: String, + distro: Distro, extra_input_globs: Vec, package_mapping_files: Vec, } @@ -62,8 +62,7 @@ impl MetadataProvider for RosPackageXmlMetadataProvider { type Error = std::convert::Infallible; fn name(&mut self) -> Result, Self::Error> { - let formatted = self.package_data.name.replace('_', "-"); - Ok(Some(format!("ros-{}-{}", self.distro_name, formatted))) + Ok(Some(self.distro.conda_name(&self.package_data.name))) } fn version(&mut self) -> Result, Self::Error> { @@ -142,7 +141,7 @@ mod tests { let package_xml = load_package_xml("custom_ros.xml"); let mut provider = RosPackageXmlMetadataProvider { package_data: package_xml, - distro_name: "noetic".to_string(), + distro: Distro::new("noetic"), extra_input_globs: Vec::new(), package_mapping_files: Vec::new(), }; @@ -174,7 +173,7 @@ mod tests { let package_xml = load_package_xml("custom_ros.xml"); let provider = RosPackageXmlMetadataProvider { package_data: package_xml, - distro_name: "noetic".to_string(), + distro: Distro::new("noetic"), extra_input_globs: Vec::new(), package_mapping_files: vec!["/tmp/custom_mapping.yaml".to_string()], }; diff --git a/crates/pixi_build_ros/src/package_map.rs b/crates/pixi_build_ros/src/package_map.rs index d561cfdec1..6a41021f43 100644 --- a/crates/pixi_build_ros/src/package_map.rs +++ b/crates/pixi_build_ros/src/package_map.rs @@ -7,7 +7,7 @@ use std::collections::HashMap; use miette::Diagnostic; use rattler_build_recipe::stage0::{ConditionalList, Item, SerializableMatchSpec, Value}; -use rattler_conda_types::{MatchSpec, ParseStrictness, Subdir}; +use rattler_conda_types::{MatchSpec, ParseStrictness, StringMatcher, Subdir}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -62,8 +62,15 @@ pub enum PackageMapError { #[error("dependency '{dep_name}' cannot be specified by both `=` and an inequality")] EqualityWithInequality { dep_name: String }, - #[error("cannot merge version specifiers: '{spec1}' or '{spec2}' contains spaces")] - MergeSpecsWithSpaces { spec1: String, spec2: String }, + #[error("dependency '{dep_name}' cannot have both build strings `{build1}` and `{build2}`")] + ConflictingBuildStrings { + dep_name: String, + build1: String, + build2: String, + }, + + #[error("cannot merge the specifier '{spec}': it has more than a version and a build string")] + MergeSpecWithSpaces { spec: String }, #[error("rosdep '{dep_name}' resolved to an invalid conda package spec '{spec}'")] #[diagnostic(help("Map '{dep_name}' to a valid conda package via `extra-package-mappings`."))] @@ -181,9 +188,8 @@ fn resolve_rosdep_to_conda_package_spec( // Not in package map -> assume it's a ROS package let Some(entry) = package_map_data.get(&dep.name) else { let ros_name = format!( - "ros-{}-{}{}", - distro.name, - dep.name.replace('_', "-"), + "{}{}", + distro.conda_name(&dep.name), spec_str.as_deref().unwrap_or("") ); return Ok(vec![ros_name]); @@ -196,9 +202,8 @@ fn resolve_rosdep_to_conda_package_spec( .iter() .map(|name| { format!( - "ros-{}-{}{}", - distro.name, - name.replace('_', "-"), + "{}{}", + distro.conda_name(name), spec_str.as_deref().unwrap_or("") ) }) @@ -516,35 +521,93 @@ fn normalize_spec(spec: &str, package_name: &str) -> String { .to_string() } -/// Merge two version spec strings for the same package. -fn merge_specs( - spec1: Option<&str>, - spec2: Option<&str>, +/// A spec without the package name, split into its version and build string. +fn version_and_build( + spec: Option<&str>, package_name: &str, -) -> Result { - let v1 = spec1 - .map(|s| normalize_spec(s, package_name)) - .unwrap_or_default(); - let v2 = spec2 +) -> Result<(String, Option), PackageMapError> { + let spec = spec .map(|s| normalize_spec(s, package_name)) .unwrap_or_default(); - - if v1.contains(' ') || v2.contains(' ') { - return Err(PackageMapError::MergeSpecsWithSpaces { - spec1: v1, - spec2: v2, - }); + let Some((version, build)) = spec.split_once(' ') else { + return Ok((spec, None)); + }; + if build.contains(' ') { + return Err(PackageMapError::MergeSpecWithSpaces { spec }); } + Ok((version.to_string(), Some(build.to_string()))) +} - // Early out with *, empty, or == - if v1 == "*" || v1.is_empty() || v2.contains("==") || v1 == v2 { +/// Merge two specs for the same package: their version constraints, and the +/// build string that at most one of them has (e.g. the distro mutex's pin to a +/// distribution). +fn merge_specs( + spec1: Option<&str>, + spec2: Option<&str>, + package_name: &str, +) -> Result { + // A name-only requirement adds no constraint. Keep the other spec intact, + // including its channel and bracket selectors. + let unconstrained = |spec: Option<&str>| { + spec.is_none_or(|spec| { + let rest = spec.strip_prefix(package_name).unwrap_or(spec).trim(); + rest.is_empty() || rest == "*" + }) + }; + if unconstrained(spec1) { return Ok(spec2.unwrap_or("").to_string()); } - if v2 == "*" || v2.is_empty() || v1.contains("==") { + if unconstrained(spec2) { return Ok(spec1.unwrap_or("").to_string()); } - Ok(format!("{package_name} {},{}", v1, v2)) + let (v1, b1) = version_and_build(spec1, package_name)?; + let (v2, b2) = version_and_build(spec2, package_name)?; + + let build = match (b1, b2) { + (Some(b1), Some(b2)) if b1 == "*" => Some(b2), + (Some(b1), Some(b2)) if b2 == "*" => Some(b1), + (Some(b1), Some(b2)) + if matches!(b1.parse::(), Ok(StringMatcher::Exact(_))) + && b2 + .parse::() + .is_ok_and(|matcher| matcher.matches(&b1)) => + { + Some(b1) + } + (Some(b1), Some(b2)) + if matches!(b2.parse::(), Ok(StringMatcher::Exact(_))) + && b1 + .parse::() + .is_ok_and(|matcher| matcher.matches(&b2)) => + { + Some(b2) + } + (Some(b1), Some(b2)) if b1 != b2 => { + return Err(PackageMapError::ConflictingBuildStrings { + dep_name: package_name.to_string(), + build1: b1, + build2: b2, + }); + } + (b1, b2) => b1.or(b2), + }; + + let version = if v1 == "*" || v1.is_empty() || v2.contains("==") || v1 == v2 { + v2 + } else if v2 == "*" || v2.is_empty() || v1.contains("==") { + v1 + } else { + format!("{v1},{v2}") + }; + + Ok(match (version.as_str(), build) { + (_, Some(build)) if version.is_empty() => format!("{package_name} * {build}"), + (_, Some(build)) => format!("{package_name} {version} {build}"), + ("", None) if spec1.is_none() && spec2.is_none() => String::new(), + ("", None) => package_name.to_string(), + (_, None) => format!("{package_name} {version}"), + }) } /// Merge two ConditionalLists, deduplicating by package name and merging @@ -756,7 +819,7 @@ mod tests { let result = rosdep_to_conda_package_spec(&dep, &distro, Subdir::Linux64, &HashMap::new()).unwrap(); - assert_eq!(result, vec!["ros-jazzy-ament-cmake==1.2.3"]); + assert_eq!(result, vec!["ros2-ament-cmake==1.2.3"]); } #[test] @@ -771,7 +834,7 @@ mod tests { let result = rosdep_to_conda_package_spec(&dep, &distro, Subdir::Linux64, &HashMap::new()).unwrap(); - assert_eq!(result, vec!["ros-jazzy-rclcpp >=18.0.0,<20.0.0"]); + assert_eq!(result, vec!["ros2-rclcpp >=18.0.0,<20.0.0"]); } #[test] @@ -792,7 +855,7 @@ mod tests { let result = rosdep_to_conda_package_spec(&dep, &distro, Subdir::Linux64, &package_map).unwrap(); - assert_eq!(result, vec!["ros-jazzy-foo-util >=3.1"]); + assert_eq!(result, vec!["ros2-foo-util >=3.1"]); } #[test] @@ -981,23 +1044,92 @@ mod tests { } #[test] - fn test_merge_specs_with_spaces() { - let list1 = vec![Item::Value(Value::new_concrete( - SerializableMatchSpec::from("ros-noetic 2.* noetic"), - None, - ))]; - let list2 = vec![Item::Value(Value::new_concrete( - SerializableMatchSpec::from("ros-noetic <=2.0,<3.0"), - None, - ))]; + fn test_merge_specs_with_build_strings() { + let spec = |s: &str| { + vec![Item::Value(Value::new_concrete( + SerializableMatchSpec::from(s), + None, + ))] + }; + + // a version and a build string, e.g. the distro mutex's pin + let result = merge_unique_items_vec( + &spec("ros2-distro-mutex 0.5.*"), + &spec("ros2-distro-mutex * jazzy_*"), + ) + .unwrap(); + assert_eq!( + item_spec_string(&result[0]).unwrap(), + "ros2-distro-mutex 0.5.* jazzy_*" + ); + + let result = merge_unique_items_vec( + &spec("ros-noetic 2.* noetic"), + &spec("ros-noetic <=2.0,<3.0"), + ) + .unwrap(); + assert_eq!( + item_spec_string(&result[0]).unwrap(), + "ros-noetic 2.*,<=2.0,<3.0 noetic" + ); - let result = merge_unique_items_vec(&list1, &list2); + let result = merge_unique_items_vec( + &spec("ros-noetic 2.* noetic"), + &spec("ros-noetic * melodic"), + ); assert!(matches!( result, - Err(PackageMapError::MergeSpecsWithSpaces { .. }) + Err(PackageMapError::ConflictingBuildStrings { .. }) )); } + #[test] + fn test_merge_unconstrained_preserves_selectors() { + for qualified in [ + "conda-forge::python", + "conda-forge::python >=3.10", + "python[build_number='>=2']", + ] { + let spec = SerializableMatchSpec::from(qualified); + let qualified = vec![Item::Value(Value::new_concrete(spec.clone(), None))]; + let unconstrained = vec![Item::Value(Value::new_concrete( + SerializableMatchSpec::from("python"), + None, + ))]; + for (first, second) in [(&qualified, &unconstrained), (&unconstrained, &qualified)] { + let merged = merge_unique_items_vec(first, second).unwrap(); + assert_eq!( + merged, + vec![Item::Value(Value::new_concrete(spec.clone(), None))] + ); + } + } + } + + #[test] + fn test_merge_compatible_mutex_builds() { + for (build, expected) in [("*", "jazzy_*"), ("jazzy_0", "jazzy_0")] { + let explicit = format!("ros2-distro-mutex >=0.5 {build}"); + let distro = "ros2-distro-mutex * jazzy_*"; + for (first, second) in [(explicit.as_str(), distro), (distro, explicit.as_str())] { + let merged = merge_specs(Some(first), Some(second), "ros2-distro-mutex").unwrap(); + assert_eq!(merged, format!("ros2-distro-mutex >=0.5 {expected}")); + } + } + + for build in ["humble_0", "*_0"] { + let explicit = format!("ros2-distro-mutex >=0.5 {build}"); + assert!(matches!( + merge_specs( + Some(&explicit), + Some("ros2-distro-mutex * jazzy_*"), + "ros2-distro-mutex", + ), + Err(PackageMapError::ConflictingBuildStrings { .. }) + )); + } + } + #[test] fn test_merge_specs_with_none() { let list1 = vec![Item::Value(Value::new_concrete( @@ -1028,7 +1160,7 @@ mod tests { let result = rosdep_to_conda_package_spec(&dep, &distro, Subdir::Linux64, &HashMap::new()).unwrap(); - assert_eq!(result, vec!["ros-jazzy-customlib >1.0.0"]); + assert_eq!(result, vec!["ros2-customlib >1.0.0"]); } #[test] diff --git a/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_explicit_package_xml_path.snap b/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_explicit_package_xml_path.snap index 89227d9147..78e71bdb7d 100644 --- a/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_explicit_package_xml_path.snap +++ b/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_explicit_package_xml_path.snap @@ -58,6 +58,7 @@ requirements: - "${{ compiler('cxx') }}" - if: build_platform != target_platform then: "cross-python_${{ target_platform }}" + - ros-distro-mutex * noetic_* host: - ros-noetic-catkin - ros-noetic-ros-package <=2.0.0 @@ -75,7 +76,7 @@ requirements: - pip - pkg-config - setuptools - - ros-distro-mutex + - ros-distro-mutex * noetic_* run: - ros-noetic-ros-package <=2.0.0 - ros-noetic-ros-package-msgs <=2.0.0 @@ -87,7 +88,7 @@ requirements: - xorg-libxext - tinyxml2 ==10.0.0 - asio <10.0.0 - - ros-distro-mutex + - ros-distro-mutex * noetic_* about: license: Apache-2.0 summary: Demo diff --git a/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_mutex_version.snap b/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_mutex_version.snap index 8b4f345651..d9e5f78d7e 100644 --- a/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_mutex_version.snap +++ b/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_mutex_version.snap @@ -58,8 +58,9 @@ requirements: - "${{ compiler('cxx') }}" - if: build_platform != target_platform then: "cross-python_${{ target_platform }}" + - ros-distro-mutex * noetic_* host: - - ros-distro-mutex 0.5.* + - ros-distro-mutex 0.5.* noetic_* - ros-noetic-catkin - ros-noetic-ros-package <=2.0.0 - ros-noetic-ros-package-msgs <=2.0.0 @@ -88,7 +89,7 @@ requirements: - xorg-libxext - tinyxml2 ==10.0.0 - asio <10.0.0 - - ros-distro-mutex + - ros-distro-mutex * noetic_* about: license: Apache-2.0 summary: Demo diff --git a/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_versions.snap b/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_versions.snap index 89227d9147..78e71bdb7d 100644 --- a/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_versions.snap +++ b/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_versions.snap @@ -58,6 +58,7 @@ requirements: - "${{ compiler('cxx') }}" - if: build_platform != target_platform then: "cross-python_${{ target_platform }}" + - ros-distro-mutex * noetic_* host: - ros-noetic-catkin - ros-noetic-ros-package <=2.0.0 @@ -75,7 +76,7 @@ requirements: - pip - pkg-config - setuptools - - ros-distro-mutex + - ros-distro-mutex * noetic_* run: - ros-noetic-ros-package <=2.0.0 - ros-noetic-ros-package-msgs <=2.0.0 @@ -87,7 +88,7 @@ requirements: - xorg-libxext - tinyxml2 ==10.0.0 - asio <10.0.0 - - ros-distro-mutex + - ros-distro-mutex * noetic_* about: license: Apache-2.0 summary: Demo diff --git a/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_versions_in_model_and_package.snap b/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_versions_in_model_and_package.snap index d592ef9fd0..71f6206349 100644 --- a/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_versions_in_model_and_package.snap +++ b/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__generate_recipe_with_versions_in_model_and_package.snap @@ -58,6 +58,7 @@ requirements: - "${{ compiler('cxx') }}" - if: build_platform != target_platform then: "cross-python_${{ target_platform }}" + - ros-distro-mutex * noetic_* host: - ros-noetic-catkin - ros-noetic-ros-package <=2.0.0 @@ -75,7 +76,7 @@ requirements: - pip - pkg-config - setuptools - - ros-distro-mutex + - ros-distro-mutex * noetic_* run: - "asio >=9.0,<10.0.0" - ros-noetic-ros-package <=2.0.0 @@ -87,7 +88,7 @@ requirements: - xorg-libx11 - xorg-libxext - tinyxml2 ==10.0.0 - - ros-distro-mutex + - ros-distro-mutex * noetic_* about: license: Apache-2.0 summary: Demo diff --git a/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__recipe_includes_project_run_dependency.snap b/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__recipe_includes_project_run_dependency.snap index 1405812267..0737d73b55 100644 --- a/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__recipe_includes_project_run_dependency.snap +++ b/crates/pixi_build_ros/src/snapshots/pixi_build_ros__tests__recipe_includes_project_run_dependency.snap @@ -50,6 +50,7 @@ requirements: - "${{ compiler('cxx') }}" - if: build_platform != target_platform then: "cross-python_${{ target_platform }}" + - ros-distro-mutex * noetic_* host: - ros-noetic-catkin - ros-noetic-ros-package @@ -59,12 +60,12 @@ requirements: - pip - pkg-config - setuptools - - ros-distro-mutex + - ros-distro-mutex * noetic_* run: - rich >=10.0 - ros-noetic-ros-package - ros-noetic-multi-package - - ros-distro-mutex + - ros-distro-mutex * noetic_* about: homepage: "https://test.io/custom_ros" license: Apache-2.0 diff --git a/crates/pixi_build_ros/src/workspace_discovery.rs b/crates/pixi_build_ros/src/workspace_discovery.rs index dfb4fce74a..cdb0d85957 100644 --- a/crates/pixi_build_ros/src/workspace_discovery.rs +++ b/crates/pixi_build_ros/src/workspace_discovery.rs @@ -18,6 +18,7 @@ use rattler_build_recipe::stage0::{ConditionalList, Item, SerializableMatchSpec, use thiserror::Error; use url::Url; +use crate::distro::Distro; use crate::package_map::item_package_name; use crate::package_xml::{PackageXml, PackageXmlError}; @@ -174,7 +175,7 @@ fn path_to_forward_slashes(path: &Path) -> String { } /// Build a matchspec string of the form -/// `ros--[url="source://?path="]` that, when +/// `[url="source://?path="]` that, when /// parsed via `SerializableMatchSpec::from`, yields a source dependency /// pointing at the sibling package. /// @@ -200,25 +201,20 @@ pub fn sibling_source_spec( format!("{conda_name}[url=\"{url}\"]") } -/// Build the conda-formatted package name for a ROS package. -pub fn conda_name_for(distro: &str, ros_name: &str) -> String { - format!("ros-{}-{}", distro, ros_name.replace('_', "-")) -} - /// Compute the `conda-name -> source-spec-string` map for every sibling /// package discovered under the workspace, excluding the current package. pub fn sibling_source_spec_map( discovered: &HashMap, current_package_name: &str, manifest_root: &Path, - distro_name: &str, + distro: &Distro, ) -> HashMap { let mut map = HashMap::new(); for (ros_name, package_xml_path) in discovered { if ros_name == current_package_name { continue; } - let conda_name = conda_name_for(distro_name, ros_name); + let conda_name = distro.conda_name(ros_name); let spec = sibling_source_spec(&conda_name, package_xml_path, manifest_root); map.insert(conda_name, spec); } @@ -442,7 +438,7 @@ preview = ["pixi-build"] root.join("node_pkg").join("pixi.toml"), r#" [package] -name = "ros-humble-node-pkg" +name = "ros2-node-pkg" version = "0.0.0" [package.build] @@ -456,7 +452,12 @@ extra-package-mappings = [{ "my-conda-dep" = { conda = ["xtensor"] } }] let discovered = discover_ros_packages(root).unwrap().packages; let manifest_root = root.join("launch_pkg"); - let specs = sibling_source_spec_map(&discovered, "launch_pkg", &manifest_root, "humble"); + let specs = sibling_source_spec_map( + &discovered, + "launch_pkg", + &manifest_root, + &Distro::new("humble"), + ); let spec_for = |rel: &str| { let mut url = Url::from_str("source://").unwrap(); @@ -468,16 +469,16 @@ extra-package-mappings = [{ "my-conda-dep" = { conda = ["xtensor"] } }] // directory so pixi discovers that manifest, including its // [package.build.config]. assert_eq!( - specs.get("ros-humble-node-pkg").unwrap(), - &format!("ros-humble-node-pkg[url=\"{}\"]", spec_for("../node_pkg")), + specs.get("ros2-node-pkg").unwrap(), + &format!("ros2-node-pkg[url=\"{}\"]", spec_for("../node_pkg")), ); // plain_pkg is a bare ROS package: keep pointing at its package.xml, // which is the only way to select ROS discovery for it. assert_eq!( - specs.get("ros-humble-plain-pkg").unwrap(), + specs.get("ros2-plain-pkg").unwrap(), &format!( - "ros-humble-plain-pkg[url=\"{}\"]", + "ros2-plain-pkg[url=\"{}\"]", spec_for("../plain_pkg/package.xml") ), ); diff --git a/crates/pixi_build_ros/templates/bld_ament_python.bat b/crates/pixi_build_ros/templates/bld_ament_python.bat index 3303c97f8a..4056aa0a52 100644 --- a/crates/pixi_build_ros/templates/bld_ament_python.bat +++ b/crates/pixi_build_ros/templates/bld_ament_python.bat @@ -6,7 +6,7 @@ set "PYTHONPATH=%LIBRARY_PREFIX%\lib\site-packages;%SP_DIR%" set "SRC_DIR=@SRC_DIR@" pushd %SRC_DIR% -set "PKG_NAME_SHORT=%PKG_NAME:*ros-@DISTRO@-=%" +set "PKG_NAME_SHORT=%PKG_NAME:*@PACKAGE_PREFIX@-=%" set "PKG_NAME_SHORT=%PKG_NAME_SHORT:-=_%" :: The prefix is reused, so record what this build installed instead of letting diff --git a/crates/pixi_build_ros/templates/build_ament_python.sh b/crates/pixi_build_ros/templates/build_ament_python.sh index da43171a13..abeb056552 100644 --- a/crates/pixi_build_ros/templates/build_ament_python.sh +++ b/crates/pixi_build_ros/templates/build_ament_python.sh @@ -7,8 +7,8 @@ pushd $SRC_DIR # If there is a setup.cfg that contains install-scripts then we should not set it here if [ -f setup.cfg ] && grep -q "install[-_]scripts" setup.cfg; then - # Remove e.g. ros-humble- from PKG_NAME - PKG_NAME_SHORT=${PKG_NAME#*ros-@DISTRO@-} + # Strip the conda prefix to recover the ROS package name. + PKG_NAME_SHORT=${PKG_NAME#@PACKAGE_PREFIX@-} # Substitute "-" with "_" PKG_NAME_SHORT=${PKG_NAME_SHORT//-/_} INSTALL_SCRIPTS_ARG="--install-scripts=$PREFIX/lib/$PKG_NAME_SHORT" diff --git a/docs/build/backends/pixi-build-ros.md b/docs/build/backends/pixi-build-ros.md index 4f0463e864..fafe8852e5 100644 --- a/docs/build/backends/pixi-build-ros.md +++ b/docs/build/backends/pixi-build-ros.md @@ -65,11 +65,16 @@ When you want to install it into your environment, you can do so by adding the f ```toml [dependencies] -ros-jazzy-my-ros-package = { path = "." } +ros2-my-ros-package = { path = "." } # or if the package is in a separate pixi.toml -# ros-jazzy-my-ros-package = { path = "src/my_ros_package" } +# ros2-my-ros-package = { path = "src/my_ros_package" } ``` -Note that you need to specify the `ros-jazzy-` prefix when you use a distro configuration. +Note that you need to specify the `ros2-` prefix (`ros--` for ROS 1) when you use a distro configuration. + +!!! note "Migrating from `ros--` names" + Earlier versions of the backend named ROS 2 packages `ros--`, as RoboStack's compatibility aliases are named. + Rename such entries in your `pixi.toml`, e.g. `ros-jazzy-my-ros-package` becomes `ros2-my-ros-package`. + RoboStack builds its ROS 2 packages for macOS 14 or newer, so on macOS add `[system-requirements]` with `macos = "14.0"` to your workspace. ### Automatic Metadata Detection @@ -106,7 +111,7 @@ homepage = "https://github.com/user/my_ros_package" repository = "https://github.com/user/my_ros_package" ``` -The backend will automatically use the metadata from `package.xml` to generate a complete conda package named `ros-jazzy-my-ros-package`. +The backend will automatically use the metadata from `package.xml` to generate a complete conda package named `ros2-my-ros-package`. The fields in the `pixi.toml` will override the values from `package.xml` if they are explicitly set. ### Automatic Distro Detection @@ -135,15 +140,17 @@ Because the definition of a dependency in a `package.xml` file is not similar to - **Workspace siblings**: Other ROS packages in the same workspace are discovered automatically and resolved as **source** dependencies, built from their sibling directory. See [Workspace Source Discovery](#workspace-source-discovery). - **Known dependencies**: Mapped using the [`robostack.yaml`](https://github.com/prefix-dev/pixi-build-backends/blob/main/backends/pixi-build-ros/robostack.yaml). - **Custom mappings**: You can provide additional mappings in your `pixi.toml` under [`[package.build.config.extra-package-mappings]`](#extra-package-mappings) -- **Other packages**: Mapped to `ros--` format. +- **Other packages**: Mapped to RoboStack's names: `ros2-` for ROS 2 and `ros--` for ROS 1. -The `` part of the package name is automatically generated based on the `distro` configuration. +ROS 2 names don't include the distribution: the generated recipe pins the distro mutex (`ros2-distro-mutex * _*`) to the `distro` configuration in the build, host, and run environments. +An explicit mutex build constraint can be `*`, the same distro pattern, or an exact build matching that pattern (for example, `jazzy_0`). +Merging different non-exact build patterns is not supported. ### Workspace Source Discovery When a `package.xml` declares a `` (or `build_depend` / `run_depend` / `exec_depend`) on another ROS package that lives in the same workspace, the backend automatically resolves it as a source dependency. There is no need to hand-write `path = "..."` entries in `pixi.toml` for every sibling reference. -Concretely, the backend walks the workspace root looking for every `package.xml`, and for each declared dependency in the current package whose `` matches a sibling's ``, it emits `ros--` as a source dep pointing at the sibling's `package.xml` instead of mapping it through RoboStack as a binary. +Concretely, the backend walks the workspace root looking for every `package.xml`, and for each declared dependency in the current package whose `` matches a sibling's ``, it emits `ros2-` as a source dep pointing at the sibling's `package.xml` instead of mapping it through RoboStack as a binary. Discovery follows colcon conventions: directories that contain a `COLCON_IGNORE`, `AMENT_IGNORE`, or `CATKIN_IGNORE` marker file are pruned from the walk. Colcon writes these markers into its own `build/`, `install/`, and `log/` directories on first use, so those are skipped automatically once a colcon build has run. @@ -153,10 +160,10 @@ A manual entry in `pixi.toml` always wins over discovery, per requirement class. ```toml [package.run-dependencies] -ros-jazzy-pkg-b = { binary = { version = "==1.2.3" } } +ros2-pkg-b = { binary = { version = "==1.2.3" } } ``` -then `ros-jazzy-pkg-b` stays a pinned binary in the `run` class, while discovery still applies in `build` and `host` if the same sibling is referenced there. Use this to pin a single sibling against a stability baseline while still iterating on the rest of the workspace. To skip discovery entirely for a single package, set [`ignore-workspace-sources = true`](#ignore-workspace-sources) on that package. +then `ros2-pkg-b` stays a pinned binary in the `run` class, while discovery still applies in `build` and `host` if the same sibling is referenced there. Use this to pin a single sibling against a stability baseline while still iterating on the rest of the workspace. To skip discovery entirely for a single package, set [`ignore-workspace-sources = true`](#ignore-workspace-sources) on that package. ## Configuration Options @@ -169,7 +176,7 @@ You can customize the ROS backend behavior using the `[package.build.config]` se - **Target Merge Behavior**: `Overwrite` - Platform-specific distro takes precedence over base The ROS distribution to build for. This affects dependency mapping and build configuration. -If set the package name will be prefixed with `ros--` automatically, otherwise the package name from `pixi.toml` or `package.xml` is used. +If set the package name will be prefixed with `ros2-` (`ros--` for ROS 1) automatically, otherwise the package name from `pixi.toml` or `package.xml` is used. ```toml [package.build.config] @@ -283,7 +290,7 @@ package_name: # The name of the package in the package.xml package_name2: # The name of the package in the package.xml conda: [package1, package2] # Maps to a list of conda packages ros_package: # The name of the package in the package.xml - ros: ros_package # Maps to a RoboStack style package name, e.g. `ros--ros-package` + ros: ros_package # Maps to a RoboStack style package name, e.g. `ros2-ros-package` ``` diff --git a/docs/build/ros.md b/docs/build/ros.md index edf145a112..a1f0911345 100644 --- a/docs/build/ros.md +++ b/docs/build/ros.md @@ -70,9 +70,9 @@ Create a `pixi.toml` inside `src/my_python_ros_pkg` so Pixi can build it using t Notes: -- When `package.build.config.distro` is set, the produced package name is prefixed like `ros--`. +- When `package.build.config.distro` is set, the produced package name is prefixed like `ros2-` (`ros--` for ROS 1), and the distro mutex pins the distribution. - The backend automatically reads `package.xml` (name, version, license, maintainers, URLs, dependencies). Any explicitly set fields in `pixi.toml` override `package.xml`. -- Dependencies in `package.xml` are mapped to conda packages via RoboStack (for example `std_msgs` → `ros--std-msgs`). Unknown deps pass through unchanged. +- Dependencies in `package.xml` are mapped to conda packages via RoboStack (for example `std_msgs` → `ros2-std-msgs`). Unknown deps pass through unchanged. ### Add the package to the pixi workspace diff --git a/docs/source_files/pixi_workspaces/pixi_build/ros_ws/pixi.toml b/docs/source_files/pixi_workspaces/pixi_build/ros_ws/pixi.toml index 31650bb5e0..854c42149b 100644 --- a/docs/source_files/pixi_workspaces/pixi_build/ros_ws/pixi.toml +++ b/docs/source_files/pixi_workspaces/pixi_build/ros_ws/pixi.toml @@ -19,8 +19,8 @@ preview = ["pixi-build"] ros-jazzy-ros2run = ">=0.32.4,<0.33" # --8<-- [end:base] # --8<-- [start:python-pkg] -ros-jazzy-my-python-ros-pkg = { path = "src/my_python_ros_pkg" } +ros2-my-python-ros-pkg = { path = "src/my_python_ros_pkg" } # --8<-- [end:python-pkg] # --8<-- [start:cmake-pkg] -ros-jazzy-my-cmake-ros-pkg = { path = "src/my_cmake_ros_pkg" } +ros2-my-cmake-ros-pkg = { path = "src/my_cmake_ros_pkg" } # --8<-- [end:cmake-pkg] diff --git a/tests/data/pixi-build/ros-workspace/pixi.toml b/tests/data/pixi-build/ros-workspace/pixi.toml index 7912999105..b478205463 100644 --- a/tests/data/pixi-build/ros-workspace/pixi.toml +++ b/tests/data/pixi-build/ros-workspace/pixi.toml @@ -14,20 +14,24 @@ preview = ["pixi-build"] c_compiler_version = ["22"] cxx_compiler_version = ["22"] +# RoboStack's ROS 2 packages are built for macOS 14 +[system-requirements] +macos = "14.0" + [tasks] navigator = "ros2 run navigator navigator" navigator_py = "ros2 run navigator_py navigator" [dependencies] -ros-humble-navigator = { path = "src/navigator" } -ros-humble-navigator-py = { path = "src/navigator_py" } +ros2-navigator = { path = "src/navigator" } +ros2-navigator-py = { path = "src/navigator_py" } [feature.distro-less] channels = [ "https://prefix.dev/robostack-jazzy", "https://prefix.dev/conda-forge", ] -dependencies = { ros-jazzy-distro-less-package = { path = "src/distro_less_package" } } +dependencies = { ros2-distro-less-package = { path = "src/distro_less_package" } } tasks = { distro-less-task = "ros2 run distro_less_package distro_less_package" } [environments] diff --git a/tests/integration_python/pixi_build/test_ros.py b/tests/integration_python/pixi_build/test_ros.py index e14b5c127f..4c6fab6a09 100644 --- a/tests/integration_python/pixi_build/test_ros.py +++ b/tests/integration_python/pixi_build/test_ros.py @@ -14,10 +14,10 @@ ROS_PACKAGE_DIRS = ["navigator", "navigator_py", "distro_less_package"] ROS_IMPLICIT_PACKAGE_DIR = "navigator_implicit" ROS_PACKAGE_OUTPUT_NAMES = { - "navigator": "ros-humble-navigator", - "navigator_py": "ros-humble-navigator-py", + "navigator": "ros2-navigator", + "navigator_py": "ros2-navigator-py", # The `humble` distro is automatically selected from the channels in the pixi.toml - "distro_less_package": "ros-humble-distro-less-package", + "distro_less_package": "ros2-distro-less-package", } @@ -58,6 +58,13 @@ def test_ros_packages_build( built_packages = list(output_dir.glob("*.conda")) assert built_packages, f"no package artifacts produced for {expected_name}" assert any(expected_name in artifact.name for artifact in built_packages) + if package_dir == "navigator_py": + entrypoint = ( + "Library/lib/navigator_py/navigator.exe" + if CURRENT_PLATFORM == "win-64" + else "lib/navigator_py/navigator" + ) + assert entrypoint in package_files(built_packages[0]) @pytest.mark.slow