Skip to content

Commit c780df0

Browse files
committed
hack: in libc-test/build.rs, copy src to src-hotfix and replace crate:: with ::
This is needed because ctest2 cannot parse `crate::` in paths
1 parent 0a8f04a commit c780df0

File tree

3 files changed

+48
-21
lines changed

3 files changed

+48
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ target
22
Cargo.lock
33
*~
44
style
5+
/src-hotfix

libc-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ libc = { path = "..", version = "1.0.0-alpha.1", default-features = false }
1919
cc = "1.0.83"
2020
# FIXME: Use fork ctest until the maintainer gets back.
2121
ctest2 = "0.4.3"
22+
regex = "1.11.1"
2223

2324
[features]
2425
default = ["std"]

libc-test/build.rs

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,36 @@ fn main() {
145145
// Avoid unnecessary re-building.
146146
println!("cargo:rerun-if-changed=build.rs");
147147

148+
if std::fs::exists("../src-hotfix").unwrap() {
149+
std::fs::remove_dir_all("../src-hotfix").unwrap();
150+
}
151+
152+
// ctest2 cannot parse `crate::` in paths, so replace them with `::`
153+
let re = regex::bytes::Regex::new(r"(?-u:\b)crate::").unwrap();
154+
copy_dir_hotfix(Path::new("../src"), Path::new("../src-hotfix"), &re, b"::");
155+
148156
do_cc();
149157
do_ctest();
150158
do_semver();
151159
}
152160

161+
fn copy_dir_hotfix(src: &Path, dst: &Path, regex: &regex::bytes::Regex, replace: &[u8]) {
162+
std::fs::create_dir(&dst).unwrap();
163+
for entry in src.read_dir().unwrap() {
164+
let entry = entry.unwrap();
165+
let src_path = entry.path();
166+
let dst_path = dst.join(entry.file_name());
167+
if entry.file_type().unwrap().is_dir() {
168+
copy_dir_hotfix(&src_path, &dst_path, regex, replace);
169+
} else {
170+
// Replace "crate::" with "::"
171+
let src_data = std::fs::read(&src_path).unwrap();
172+
let dst_data = regex.replace_all(&src_data, b"::");
173+
std::fs::write(&dst_path, &dst_data).unwrap();
174+
}
175+
}
176+
}
177+
153178
macro_rules! headers {
154179
($cfg:ident: [$m:expr]: $header:literal) => {
155180
if $m {
@@ -442,7 +467,7 @@ fn test_apple(target: &str) {
442467
"uuid_t" | "vol_capabilities_set_t" => true,
443468
_ => false,
444469
});
445-
cfg.generate("../src/lib.rs", "main.rs");
470+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
446471
}
447472

448473
fn test_openbsd(target: &str) {
@@ -607,7 +632,7 @@ fn test_openbsd(target: &str) {
607632
}
608633
});
609634

610-
cfg.generate("../src/lib.rs", "main.rs");
635+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
611636
}
612637

613638
fn test_windows(target: &str) {
@@ -729,7 +754,7 @@ fn test_windows(target: &str) {
729754

730755
cfg.skip_fn(|_| false);
731756

732-
cfg.generate("../src/lib.rs", "main.rs");
757+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
733758
}
734759

735760
fn test_redox(target: &str) {
@@ -779,7 +804,7 @@ fn test_redox(target: &str) {
779804
"wchar.h",
780805
}
781806

782-
cfg.generate("../src/lib.rs", "main.rs");
807+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
783808
}
784809

785810
fn test_solarish(target: &str) {
@@ -1054,7 +1079,7 @@ fn test_solarish(target: &str) {
10541079
}
10551080
});
10561081

1057-
cfg.generate("../src/lib.rs", "main.rs");
1082+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
10581083
}
10591084

10601085
fn test_netbsd(target: &str) {
@@ -1267,7 +1292,7 @@ fn test_netbsd(target: &str) {
12671292
}
12681293
});
12691294

1270-
cfg.generate("../src/lib.rs", "main.rs");
1295+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
12711296
}
12721297

12731298
fn test_dragonflybsd(target: &str) {
@@ -1490,7 +1515,7 @@ fn test_dragonflybsd(target: &str) {
14901515
(struct_ == "sigevent" && field == "sigev_notify_thread_id")
14911516
});
14921517

1493-
cfg.generate("../src/lib.rs", "main.rs");
1518+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
14941519
}
14951520

14961521
fn test_wasi(target: &str) {
@@ -1597,7 +1622,7 @@ fn test_wasi(target: &str) {
15971622
// doesn't support sizeof.
15981623
cfg.skip_field(|s, field| s == "dirent" && field == "d_name");
15991624

1600-
cfg.generate("../src/lib.rs", "main.rs");
1625+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
16011626
}
16021627

16031628
fn test_android(target: &str) {
@@ -2090,7 +2115,7 @@ fn test_android(target: &str) {
20902115
}
20912116
});
20922117

2093-
cfg.generate("../src/lib.rs", "main.rs");
2118+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
20942119

20952120
test_linux_like_apis(target);
20962121
}
@@ -2746,7 +2771,7 @@ fn test_freebsd(target: &str) {
27462771
});
27472772
}
27482773

2749-
cfg.generate("../src/lib.rs", "main.rs");
2774+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
27502775
}
27512776

27522777
fn test_emscripten(target: &str) {
@@ -2983,7 +3008,7 @@ fn test_emscripten(target: &str) {
29833008
].contains(&field))
29843009
});
29853010

2986-
cfg.generate("../src/lib.rs", "main.rs");
3011+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
29873012
}
29883013

29893014
fn test_neutrino(target: &str) {
@@ -3233,7 +3258,7 @@ fn test_neutrino(target: &str) {
32333258

32343259
cfg.skip_static(move |name| (name == "__dso_handle"));
32353260

3236-
cfg.generate("../src/lib.rs", "main.rs");
3261+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
32373262
}
32383263

32393264
fn test_vxworks(target: &str) {
@@ -3341,7 +3366,7 @@ fn test_vxworks(target: &str) {
33413366
_ => false,
33423367
});
33433368

3344-
cfg.generate("../src/lib.rs", "main.rs");
3369+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
33453370
}
33463371

33473372
fn test_linux(target: &str) {
@@ -4462,7 +4487,7 @@ fn test_linux(target: &str) {
44624487
_ => false,
44634488
});
44644489

4465-
cfg.generate("../src/lib.rs", "main.rs");
4490+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
44664491

44674492
test_linux_like_apis(target);
44684493
}
@@ -4489,7 +4514,7 @@ fn test_linux_like_apis(target: &str) {
44894514
})
44904515
.skip_const(|_| true)
44914516
.skip_struct(|_| true);
4492-
cfg.generate("../src/lib.rs", "linux_strerror_r.rs");
4517+
cfg.generate("../src-hotfix/lib.rs", "linux_strerror_r.rs");
44934518
}
44944519

44954520
if linux || android || emscripten {
@@ -4519,7 +4544,7 @@ fn test_linux_like_apis(target: &str) {
45194544
t => t.to_string(),
45204545
});
45214546

4522-
cfg.generate("../src/lib.rs", "linux_fcntl.rs");
4547+
cfg.generate("../src-hotfix/lib.rs", "linux_fcntl.rs");
45234548
}
45244549

45254550
if linux || android {
@@ -4543,7 +4568,7 @@ fn test_linux_like_apis(target: &str) {
45434568
t if is_union => format!("union {}", t),
45444569
t => t.to_string(),
45454570
});
4546-
cfg.generate("../src/lib.rs", "linux_termios.rs");
4571+
cfg.generate("../src-hotfix/lib.rs", "linux_termios.rs");
45474572
}
45484573

45494574
if linux || android {
@@ -4571,7 +4596,7 @@ fn test_linux_like_apis(target: &str) {
45714596
t if is_union => format!("union {}", t),
45724597
t => t.to_string(),
45734598
});
4574-
cfg.generate("../src/lib.rs", "linux_ipv6.rs");
4599+
cfg.generate("../src-hotfix/lib.rs", "linux_ipv6.rs");
45754600
}
45764601

45774602
if linux || android {
@@ -4593,7 +4618,7 @@ fn test_linux_like_apis(target: &str) {
45934618
"Elf64_Phdr" | "Elf32_Phdr" => false,
45944619
_ => true,
45954620
});
4596-
cfg.generate("../src/lib.rs", "linux_elf.rs");
4621+
cfg.generate("../src-hotfix/lib.rs", "linux_elf.rs");
45974622
}
45984623

45994624
if linux || android {
@@ -4608,7 +4633,7 @@ fn test_linux_like_apis(target: &str) {
46084633
})
46094634
.skip_struct(|_| true)
46104635
.skip_type(|_| true);
4611-
cfg.generate("../src/lib.rs", "linux_if_arp.rs");
4636+
cfg.generate("../src-hotfix/lib.rs", "linux_if_arp.rs");
46124637
}
46134638
}
46144639

@@ -4964,5 +4989,5 @@ fn test_haiku(target: &str) {
49644989
s => s.to_string(),
49654990
}
49664991
});
4967-
cfg.generate("../src/lib.rs", "main.rs");
4992+
cfg.generate("../src-hotfix/lib.rs", "main.rs");
49684993
}

0 commit comments

Comments
 (0)