Skip to content

Commit 13169ea

Browse files
authored
fix(ros-z-msgs): respect both CARGO_HOME and HOME (#24)
1 parent 130c51d commit 13169ea

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

ros-z-msgs/build.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -220,29 +220,33 @@ fn discover_bundled_packages(bundled_packages: &[&str]) -> Result<Vec<PathBuf>>
220220
fn find_roslibrust_assets() -> PathBuf {
221221
// Search in cargo's git checkout directory
222222
// The path will be something like: ~/.cargo/git/checkouts/roslibrust-{hash}/{commit}/assets
223-
if let Ok(home) = env::var("CARGO_HOME").or_else(|_| env::var("HOME")) {
224-
let cargo_git = PathBuf::from(home).join(".cargo/git/checkouts");
225-
226-
if let Ok(entries) = std::fs::read_dir(&cargo_git) {
227-
for entry in entries.flatten() {
228-
let path = entry.path();
229-
if path.is_dir()
230-
&& path
231-
.file_name()
232-
.and_then(|n| n.to_str())
233-
.is_some_and(|n| n.starts_with("roslibrust-"))
234-
{
235-
// Look for the assets directory in any commit subdirectory
236-
if let Ok(commits) = std::fs::read_dir(&path) {
237-
for commit_entry in commits.flatten() {
238-
let assets_path = commit_entry.path().join("assets");
239-
if assets_path.exists() {
240-
println!(
241-
"cargo:warning=Using roslibrust git assets at {}",
242-
assets_path.display()
243-
);
244-
return assets_path;
245-
}
223+
let cargo_git = if let Ok(cargo_home) = env::var("CARGO_HOME") {
224+
PathBuf::from(cargo_home).join("git/checkouts")
225+
} else if let Ok(home) = env::var("HOME") {
226+
PathBuf::from(home).join(".cargo/git/checkouts")
227+
} else {
228+
panic!("Neither CARGO_HOME nor HOME environment variable is set");
229+
};
230+
231+
if let Ok(entries) = std::fs::read_dir(&cargo_git) {
232+
for entry in entries.flatten() {
233+
let path = entry.path();
234+
if path.is_dir()
235+
&& path
236+
.file_name()
237+
.and_then(|n| n.to_str())
238+
.is_some_and(|n| n.starts_with("roslibrust-"))
239+
{
240+
// Look for the assets directory in any commit subdirectory
241+
if let Ok(commits) = std::fs::read_dir(&path) {
242+
for commit_entry in commits.flatten() {
243+
let assets_path = commit_entry.path().join("assets");
244+
if assets_path.exists() {
245+
println!(
246+
"cargo:warning=Using roslibrust git assets at {}",
247+
assets_path.display()
248+
);
249+
return assets_path;
246250
}
247251
}
248252
}

0 commit comments

Comments
 (0)