Skip to content

Commit 17ec22d

Browse files
amysparklu-zero
authored andcommitted
Implement installing dSYMs if available
1 parent 385d19d commit 17ec22d

3 files changed

Lines changed: 56 additions & 7 deletions

File tree

src/build.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22
use std::hash::{DefaultHasher, Hash, Hasher};
3-
use std::io::Read;
3+
use std::io::{ErrorKind, Read};
44
use std::path::{Path, PathBuf};
55
use std::sync::atomic::{AtomicBool, Ordering};
66
use std::sync::{Arc, Mutex};
@@ -1277,7 +1277,33 @@ pub fn cbuild(
12771277
from_build_targets.debug_info.as_ref(),
12781278
build_targets.debug_info.as_ref(),
12791279
) {
1280-
copy(from_debug_info, to_debug_info)?;
1280+
if from_debug_info.exists() {
1281+
create_dir_all(to_debug_info.parent().unwrap())?;
1282+
if from_debug_info.is_dir() {
1283+
let files =
1284+
from_debug_info.read_dir()?.collect::<Result<Vec<_>, _>>()?;
1285+
for f in files.iter() {
1286+
let src = f.path();
1287+
let file_name = src.strip_prefix(from_debug_info)?;
1288+
let dst = to_debug_info.join(file_name);
1289+
match std::fs::create_dir_all(
1290+
dst.parent().expect("Source path is not complete"),
1291+
) {
1292+
Ok(()) => Ok(()),
1293+
Err(v) => {
1294+
if v.kind() == ErrorKind::AlreadyExists {
1295+
Ok(())
1296+
} else {
1297+
Err(v)
1298+
}
1299+
}
1300+
}?;
1301+
copy(src, dst)?;
1302+
}
1303+
} else {
1304+
copy(from_debug_info, to_debug_info)?;
1305+
}
1306+
}
12811307
}
12821308
}
12831309

src/build_targets.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ impl FileNames {
171171
"macos" | "ios" | "tvos" | "visionos" => {
172172
let static_lib = targetdir.join(format!("lib{lib_name}.a"));
173173
let shared_lib = targetdir.join(format!("lib{lib_name}.dylib"));
174-
(shared_lib, static_lib, None, None, None)
174+
let pdb = Some(targetdir.join(format!("lib{lib_name}.dSYM")));
175+
(shared_lib, static_lib, None, pdb, None)
175176
}
176177
"windows" => {
177178
let shared_lib = targetdir.join(format!("{lib_name}.dll"));
@@ -194,9 +195,8 @@ impl FileNames {
194195
} else {
195196
targetdir.join(format!("{lib_name}.dll.a"))
196197
};
197-
let pdb = None;
198198

199-
(shared_lib, static_lib, Some(impl_lib), pdb, Some(def))
199+
(shared_lib, static_lib, Some(impl_lib), None, Some(def))
200200
}
201201
}
202202
_ => return None,
@@ -269,7 +269,7 @@ mod test {
269269
static_lib: PathBuf::from("/foo/bar/libferris.a"),
270270
shared_lib: PathBuf::from("/foo/bar/libferris.dylib"),
271271
impl_lib: None,
272-
debug_info: None,
272+
debug_info: Some(PathBuf::from("/foo/bar/libferris.dSYM")),
273273
def: None,
274274
};
275275

src/install.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::ArgMatches;
2+
use std::io::ErrorKind;
23
use std::path::{Component, Path, PathBuf};
34

45
use cargo::core::Workspace;
@@ -298,7 +299,29 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
298299
};
299300

300301
create_dir_all(destination_path.parent().unwrap())?;
301-
copy(ws, debug_info, destination_path)?;
302+
if debug_info.is_dir() {
303+
let files = debug_info.read_dir()?.collect::<Result<Vec<_>, _>>()?;
304+
for f in files.iter() {
305+
let src = f.path();
306+
let file_name = src.strip_prefix(debug_info)?;
307+
let dst = destination_path.join(file_name);
308+
match std::fs::create_dir_all(
309+
dst.parent().expect("Source path is not complete"),
310+
) {
311+
Ok(()) => Ok(()),
312+
Err(v) => {
313+
if v.kind() == ErrorKind::AlreadyExists {
314+
Ok(())
315+
} else {
316+
Err(v)
317+
}
318+
}
319+
}?;
320+
copy(ws, src, dst)?;
321+
}
322+
} else {
323+
copy(ws, debug_info, destination_path)?;
324+
}
302325
} else {
303326
ws.gctx()
304327
.shell()

0 commit comments

Comments
 (0)