Skip to content

Commit 4e50712

Browse files
committed
test(trim-paths): verify trim-paths=object works on windows-msvc
1 parent 11e40ae commit 4e50712

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

tests/testsuite/profile_trim_paths.rs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,32 @@ mod object_works {
503503
}
504504
}
505505

506-
#[cfg(unix)]
507-
fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) -> Vec<u8>) {
508-
use std::os::unix::ffi::OsStrExt;
506+
#[cfg(target_env = "msvc")]
507+
mod object_works {
508+
use super::*;
509+
510+
fn inspect_debuginfo(path: &std::path::Path) -> Vec<u8> {
511+
std::process::Command::new("strings")
512+
.arg(path)
513+
.output()
514+
.expect("strings works")
515+
.stdout
516+
}
509517

518+
// windows-msvc supports split-debuginfo=packed only
519+
#[cargo_test(
520+
requires = "strings",
521+
nightly,
522+
reason = "-Zremap-path-scope is unstable"
523+
)]
524+
fn with_split_debuginfo_packed() {
525+
object_works_helper("packed", inspect_debuginfo);
526+
}
527+
}
528+
529+
fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) -> Vec<u8>) {
510530
let registry_src = paths::home().join(".cargo/registry/src");
511-
let registry_src_bytes = registry_src.as_os_str().as_bytes();
531+
let registry_src_bytes = registry_src.as_os_str().as_encoded_bytes();
512532
let rust_src = "/lib/rustc/src/rust".as_bytes();
513533

514534
Package::new("bar", "0.0.1")
@@ -538,19 +558,27 @@ fn object_works_helper(split_debuginfo: &str, run: impl Fn(&std::path::Path) ->
538558
.build();
539559

540560
let pkg_root = p.root();
541-
let pkg_root = pkg_root.as_os_str().as_bytes();
561+
let pkg_root = pkg_root.as_os_str().as_encoded_bytes();
542562

543563
p.cargo("build").run();
544564

545565
let bin_path = p.bin("foo");
546566
assert!(bin_path.is_file());
547567
let stdout = run(&bin_path);
548-
// TODO: re-enable this check when rustc bootstrap disables remapping
549-
// <https://github.com/rust-lang/cargo/pull/12625#discussion_r1371714791>
550-
// assert!(memchr::memmem::find(&stdout, rust_src).is_some());
551-
assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_some());
552-
assert!(memchr::memmem::find(&stdout, pkg_root).is_some());
553-
568+
// On windows-msvc every debuginfo is in pdb file, so can't find anything here.
569+
if cfg!(target_env = "msvc") {
570+
// TODO: re-enable this check when rustc bootstrap disables remapping
571+
// <https://github.com/rust-lang/cargo/pull/12625#discussion_r1371714791>
572+
// assert!(memchr::memmem::find(&stdout, rust_src).is_some());
573+
assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_none());
574+
assert!(memchr::memmem::find(&stdout, pkg_root).is_none());
575+
} else {
576+
// TODO: re-enable this check when rustc bootstrap disables remapping
577+
// <https://github.com/rust-lang/cargo/pull/12625#discussion_r1371714791>
578+
// assert!(memchr::memmem::find(&stdout, rust_src).is_some());
579+
assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_some());
580+
assert!(memchr::memmem::find(&stdout, pkg_root).is_some());
581+
}
554582
p.cargo("clean").run();
555583

556584
p.cargo("build --verbose -Ztrim-paths")

0 commit comments

Comments
 (0)