@@ -7,6 +7,10 @@ use std::io::{BufRead, BufReader, BufWriter, Write};
77use std:: path:: { Path , PathBuf } ;
88use std:: { env, io} ;
99
10+ fn src_hotfix_dir ( ) -> PathBuf {
11+ Path :: new ( & env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) . join ( "src-hotfix" )
12+ }
13+
1014fn do_cc ( ) {
1115 let target = env:: var ( "TARGET" ) . unwrap ( ) ;
1216 if cfg ! ( unix) {
@@ -145,11 +149,37 @@ fn main() {
145149 // Avoid unnecessary re-building.
146150 println ! ( "cargo:rerun-if-changed=build.rs" ) ;
147151
152+ let hotfix_dir = src_hotfix_dir ( ) ;
153+ if std:: fs:: exists ( & hotfix_dir) . unwrap ( ) {
154+ std:: fs:: remove_dir_all ( & hotfix_dir) . unwrap ( ) ;
155+ }
156+
157+ // FIXME(ctest): ctest2 cannot parse `crate::` in paths, so replace them with `::`
158+ let re = regex:: bytes:: Regex :: new ( r"(?-u:\b)crate::" ) . unwrap ( ) ;
159+ copy_dir_hotfix ( Path :: new ( "../src" ) , & hotfix_dir, & re, b"::" ) ;
160+
148161 do_cc ( ) ;
149162 do_ctest ( ) ;
150163 do_semver ( ) ;
151164}
152165
166+ fn copy_dir_hotfix ( src : & Path , dst : & Path , regex : & regex:: bytes:: Regex , replace : & [ u8 ] ) {
167+ std:: fs:: create_dir ( & dst) . unwrap ( ) ;
168+ for entry in src. read_dir ( ) . unwrap ( ) {
169+ let entry = entry. unwrap ( ) ;
170+ let src_path = entry. path ( ) ;
171+ let dst_path = dst. join ( entry. file_name ( ) ) ;
172+ if entry. file_type ( ) . unwrap ( ) . is_dir ( ) {
173+ copy_dir_hotfix ( & src_path, & dst_path, regex, replace) ;
174+ } else {
175+ // Replace "crate::" with "::"
176+ let src_data = std:: fs:: read ( & src_path) . unwrap ( ) ;
177+ let dst_data = regex. replace_all ( & src_data, b"::" ) ;
178+ std:: fs:: write ( & dst_path, & dst_data) . unwrap ( ) ;
179+ }
180+ }
181+ }
182+
153183macro_rules! headers {
154184 ( $cfg: ident: [ $m: expr] : $header: literal) => {
155185 if $m {
@@ -442,7 +472,7 @@ fn test_apple(target: &str) {
442472 "uuid_t" | "vol_capabilities_set_t" => true ,
443473 _ => false ,
444474 } ) ;
445- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
475+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
446476}
447477
448478fn test_openbsd ( target : & str ) {
@@ -607,7 +637,7 @@ fn test_openbsd(target: &str) {
607637 }
608638 } ) ;
609639
610- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
640+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
611641}
612642
613643fn test_windows ( target : & str ) {
@@ -729,7 +759,7 @@ fn test_windows(target: &str) {
729759
730760 cfg. skip_fn ( |_| false ) ;
731761
732- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
762+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
733763}
734764
735765fn test_redox ( target : & str ) {
@@ -779,7 +809,7 @@ fn test_redox(target: &str) {
779809 "wchar.h" ,
780810 }
781811
782- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
812+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
783813}
784814
785815fn test_solarish ( target : & str ) {
@@ -1054,7 +1084,7 @@ fn test_solarish(target: &str) {
10541084 }
10551085 } ) ;
10561086
1057- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1087+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
10581088}
10591089
10601090fn test_netbsd ( target : & str ) {
@@ -1267,7 +1297,7 @@ fn test_netbsd(target: &str) {
12671297 }
12681298 } ) ;
12691299
1270- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1300+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
12711301}
12721302
12731303fn test_dragonflybsd ( target : & str ) {
@@ -1490,7 +1520,7 @@ fn test_dragonflybsd(target: &str) {
14901520 ( struct_ == "sigevent" && field == "sigev_notify_thread_id" )
14911521 } ) ;
14921522
1493- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1523+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
14941524}
14951525
14961526fn test_wasi ( target : & str ) {
@@ -1597,7 +1627,7 @@ fn test_wasi(target: &str) {
15971627 // doesn't support sizeof.
15981628 cfg. skip_field ( |s, field| s == "dirent" && field == "d_name" ) ;
15991629
1600- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1630+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
16011631}
16021632
16031633fn test_android ( target : & str ) {
@@ -2093,7 +2123,7 @@ fn test_android(target: &str) {
20932123 }
20942124 } ) ;
20952125
2096- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
2126+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
20972127
20982128 test_linux_like_apis ( target) ;
20992129}
@@ -2752,7 +2782,7 @@ fn test_freebsd(target: &str) {
27522782 } ) ;
27532783 }
27542784
2755- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
2785+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
27562786}
27572787
27582788fn test_emscripten ( target : & str ) {
@@ -2994,7 +3024,7 @@ fn test_emscripten(target: &str) {
29943024 ] . contains ( & field) )
29953025 } ) ;
29963026
2997- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
3027+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
29983028}
29993029
30003030fn test_neutrino ( target : & str ) {
@@ -3244,7 +3274,7 @@ fn test_neutrino(target: &str) {
32443274
32453275 cfg. skip_static ( move |name| ( name == "__dso_handle" ) ) ;
32463276
3247- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
3277+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
32483278}
32493279
32503280fn test_vxworks ( target : & str ) {
@@ -3352,7 +3382,7 @@ fn test_vxworks(target: &str) {
33523382 _ => false ,
33533383 } ) ;
33543384
3355- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
3385+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
33563386}
33573387
33583388fn test_linux ( target : & str ) {
@@ -4482,7 +4512,7 @@ fn test_linux(target: &str) {
44824512 _ => false ,
44834513 } ) ;
44844514
4485- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
4515+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
44864516
44874517 test_linux_like_apis ( target) ;
44884518}
@@ -4509,7 +4539,7 @@ fn test_linux_like_apis(target: &str) {
45094539 } )
45104540 . skip_const ( |_| true )
45114541 . skip_struct ( |_| true ) ;
4512- cfg. generate ( "../src/ lib.rs", "linux_strerror_r.rs" ) ;
4542+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_strerror_r.rs" ) ;
45134543 }
45144544
45154545 if linux || android || emscripten {
@@ -4539,7 +4569,7 @@ fn test_linux_like_apis(target: &str) {
45394569 t => t. to_string ( ) ,
45404570 } ) ;
45414571
4542- cfg. generate ( "../src/ lib.rs", "linux_fcntl.rs" ) ;
4572+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_fcntl.rs" ) ;
45434573 }
45444574
45454575 if linux || android {
@@ -4563,7 +4593,7 @@ fn test_linux_like_apis(target: &str) {
45634593 t if is_union => format ! ( "union {}" , t) ,
45644594 t => t. to_string ( ) ,
45654595 } ) ;
4566- cfg. generate ( "../src/ lib.rs", "linux_termios.rs" ) ;
4596+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_termios.rs" ) ;
45674597 }
45684598
45694599 if linux || android {
@@ -4591,7 +4621,7 @@ fn test_linux_like_apis(target: &str) {
45914621 t if is_union => format ! ( "union {}" , t) ,
45924622 t => t. to_string ( ) ,
45934623 } ) ;
4594- cfg. generate ( "../src/ lib.rs", "linux_ipv6.rs" ) ;
4624+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_ipv6.rs" ) ;
45954625 }
45964626
45974627 if linux || android {
@@ -4613,7 +4643,7 @@ fn test_linux_like_apis(target: &str) {
46134643 "Elf64_Phdr" | "Elf32_Phdr" => false ,
46144644 _ => true ,
46154645 } ) ;
4616- cfg. generate ( "../src/ lib.rs", "linux_elf.rs" ) ;
4646+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_elf.rs" ) ;
46174647 }
46184648
46194649 if linux || android {
@@ -4628,7 +4658,7 @@ fn test_linux_like_apis(target: &str) {
46284658 } )
46294659 . skip_struct ( |_| true )
46304660 . skip_type ( |_| true ) ;
4631- cfg. generate ( "../src/ lib.rs", "linux_if_arp.rs" ) ;
4661+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_if_arp.rs" ) ;
46324662 }
46334663}
46344664
@@ -4984,5 +5014,5 @@ fn test_haiku(target: &str) {
49845014 s => s. to_string ( ) ,
49855015 }
49865016 } ) ;
4987- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
5017+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
49885018}
0 commit comments