Skip to content

Commit e563b19

Browse files
authored
fix: windows path support (ros2-rust#1)
* Changes to make sure ros-env creates valid paths for windows * Temp colcon ignore to try and get past the windows build failing to build this crate as a ros package
1 parent 9bd56d6 commit e563b19

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

COLCON_IGNORE

Whitespace-only changes.

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use ament_rs::{search_paths::get_search_paths, AMENT_PREFIX_PATH_ENV_VAR};
22
use cargo_toml::Manifest;
33
use std::path::{Path, PathBuf};
4-
use std::{env, fs};
54
use std::process::Command;
5+
use std::{env, fs};
66

77
fn is_marked_for_inclusion(path: &PathBuf) -> bool {
88
Manifest::from_path(path)
@@ -125,16 +125,21 @@ fn main() {
125125
// Wrap the inclusion of each file in a module matching the file stem
126126
// so that the generated code can be imported like `ros_env::std_msgs::msgs::Bool`
127127
.filter_map(|e| {
128-
e.path()
129-
.file_stem()
128+
let path = std::path::absolute(e.path()).expect("Failed to get absolute path for idiomatic module");
129+
path.file_stem()
130130
.and_then(|stem| stem.to_str())
131131
.map(|stem| {
132-
let idiomatic_path = e.path().display().to_string();
133-
let sep = std::path::MAIN_SEPARATOR;
134-
let rmw_path = idiomatic_path
135-
.rsplit_once(std::path::MAIN_SEPARATOR)
136-
.map(|(dir, _)| format!("{dir}{sep}{stem}{sep}rmw.rs"))
137-
.unwrap_or_else(|| "rmw.rs".to_string());
132+
let idiomatic_path = path.to_string_lossy().replace('\\', "/");
133+
134+
let parent = path
135+
.parent()
136+
.expect("Failed to create rmw path");
137+
138+
let rmw_path = parent
139+
.join(stem)
140+
.join("rmw.rs")
141+
.to_string_lossy()
142+
.replace('\\', "/");
138143

139144
format!("pub mod {stem} {{ {dependencies} include!(\"{idiomatic_path}\"); pub mod rmw {{ {dependencies} include!(\"{rmw_path}\"); }} }}")
140145
})

0 commit comments

Comments
 (0)