@@ -7,6 +7,10 @@ use std::io::{BufRead, BufReader, BufWriter, Write};
7
7
use std:: path:: { Path , PathBuf } ;
8
8
use std:: { env, io} ;
9
9
10
+ fn src_hotfix_dir ( ) -> PathBuf {
11
+ Path :: new ( & env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) . join ( "src-hotfix" )
12
+ }
13
+
10
14
fn do_cc ( ) {
11
15
let target = env:: var ( "TARGET" ) . unwrap ( ) ;
12
16
if cfg ! ( unix) {
@@ -145,11 +149,37 @@ fn main() {
145
149
// Avoid unnecessary re-building.
146
150
println ! ( "cargo:rerun-if-changed=build.rs" ) ;
147
151
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
+
148
161
do_cc ( ) ;
149
162
do_ctest ( ) ;
150
163
do_semver ( ) ;
151
164
}
152
165
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
+
153
183
macro_rules! headers {
154
184
( $cfg: ident: [ $m: expr] : $header: literal) => {
155
185
if $m {
@@ -442,7 +472,7 @@ fn test_apple(target: &str) {
442
472
"uuid_t" | "vol_capabilities_set_t" => true ,
443
473
_ => false ,
444
474
} ) ;
445
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
475
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
446
476
}
447
477
448
478
fn test_openbsd ( target : & str ) {
@@ -607,7 +637,7 @@ fn test_openbsd(target: &str) {
607
637
}
608
638
} ) ;
609
639
610
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
640
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
611
641
}
612
642
613
643
fn test_windows ( target : & str ) {
@@ -729,7 +759,7 @@ fn test_windows(target: &str) {
729
759
730
760
cfg. skip_fn ( |_| false ) ;
731
761
732
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
762
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
733
763
}
734
764
735
765
fn test_redox ( target : & str ) {
@@ -779,7 +809,7 @@ fn test_redox(target: &str) {
779
809
"wchar.h" ,
780
810
}
781
811
782
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
812
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
783
813
}
784
814
785
815
fn test_solarish ( target : & str ) {
@@ -1054,7 +1084,7 @@ fn test_solarish(target: &str) {
1054
1084
}
1055
1085
} ) ;
1056
1086
1057
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1087
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
1058
1088
}
1059
1089
1060
1090
fn test_netbsd ( target : & str ) {
@@ -1267,7 +1297,7 @@ fn test_netbsd(target: &str) {
1267
1297
}
1268
1298
} ) ;
1269
1299
1270
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1300
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
1271
1301
}
1272
1302
1273
1303
fn test_dragonflybsd ( target : & str ) {
@@ -1490,7 +1520,7 @@ fn test_dragonflybsd(target: &str) {
1490
1520
( struct_ == "sigevent" && field == "sigev_notify_thread_id" )
1491
1521
} ) ;
1492
1522
1493
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1523
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
1494
1524
}
1495
1525
1496
1526
fn test_wasi ( target : & str ) {
@@ -1597,7 +1627,7 @@ fn test_wasi(target: &str) {
1597
1627
// doesn't support sizeof.
1598
1628
cfg. skip_field ( |s, field| s == "dirent" && field == "d_name" ) ;
1599
1629
1600
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1630
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
1601
1631
}
1602
1632
1603
1633
fn test_android ( target : & str ) {
@@ -2093,7 +2123,7 @@ fn test_android(target: &str) {
2093
2123
}
2094
2124
} ) ;
2095
2125
2096
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
2126
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
2097
2127
2098
2128
test_linux_like_apis ( target) ;
2099
2129
}
@@ -2752,7 +2782,7 @@ fn test_freebsd(target: &str) {
2752
2782
} ) ;
2753
2783
}
2754
2784
2755
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
2785
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
2756
2786
}
2757
2787
2758
2788
fn test_emscripten ( target : & str ) {
@@ -2994,7 +3024,7 @@ fn test_emscripten(target: &str) {
2994
3024
] . contains ( & field) )
2995
3025
} ) ;
2996
3026
2997
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
3027
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
2998
3028
}
2999
3029
3000
3030
fn test_neutrino ( target : & str ) {
@@ -3244,7 +3274,7 @@ fn test_neutrino(target: &str) {
3244
3274
3245
3275
cfg. skip_static ( move |name| ( name == "__dso_handle" ) ) ;
3246
3276
3247
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
3277
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
3248
3278
}
3249
3279
3250
3280
fn test_vxworks ( target : & str ) {
@@ -3352,7 +3382,7 @@ fn test_vxworks(target: &str) {
3352
3382
_ => false ,
3353
3383
} ) ;
3354
3384
3355
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
3385
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
3356
3386
}
3357
3387
3358
3388
fn test_linux ( target : & str ) {
@@ -4482,7 +4512,7 @@ fn test_linux(target: &str) {
4482
4512
_ => false ,
4483
4513
} ) ;
4484
4514
4485
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
4515
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
4486
4516
4487
4517
test_linux_like_apis ( target) ;
4488
4518
}
@@ -4509,7 +4539,7 @@ fn test_linux_like_apis(target: &str) {
4509
4539
} )
4510
4540
. skip_const ( |_| true )
4511
4541
. 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" ) ;
4513
4543
}
4514
4544
4515
4545
if linux || android || emscripten {
@@ -4539,7 +4569,7 @@ fn test_linux_like_apis(target: &str) {
4539
4569
t => t. to_string ( ) ,
4540
4570
} ) ;
4541
4571
4542
- cfg. generate ( "../src/ lib.rs", "linux_fcntl.rs" ) ;
4572
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_fcntl.rs" ) ;
4543
4573
}
4544
4574
4545
4575
if linux || android {
@@ -4563,7 +4593,7 @@ fn test_linux_like_apis(target: &str) {
4563
4593
t if is_union => format ! ( "union {}" , t) ,
4564
4594
t => t. to_string ( ) ,
4565
4595
} ) ;
4566
- cfg. generate ( "../src/ lib.rs", "linux_termios.rs" ) ;
4596
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_termios.rs" ) ;
4567
4597
}
4568
4598
4569
4599
if linux || android {
@@ -4591,7 +4621,7 @@ fn test_linux_like_apis(target: &str) {
4591
4621
t if is_union => format ! ( "union {}" , t) ,
4592
4622
t => t. to_string ( ) ,
4593
4623
} ) ;
4594
- cfg. generate ( "../src/ lib.rs", "linux_ipv6.rs" ) ;
4624
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_ipv6.rs" ) ;
4595
4625
}
4596
4626
4597
4627
if linux || android {
@@ -4613,7 +4643,7 @@ fn test_linux_like_apis(target: &str) {
4613
4643
"Elf64_Phdr" | "Elf32_Phdr" => false ,
4614
4644
_ => true ,
4615
4645
} ) ;
4616
- cfg. generate ( "../src/ lib.rs", "linux_elf.rs" ) ;
4646
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_elf.rs" ) ;
4617
4647
}
4618
4648
4619
4649
if linux || android {
@@ -4628,7 +4658,7 @@ fn test_linux_like_apis(target: &str) {
4628
4658
} )
4629
4659
. skip_struct ( |_| true )
4630
4660
. 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" ) ;
4632
4662
}
4633
4663
}
4634
4664
@@ -4984,5 +5014,5 @@ fn test_haiku(target: &str) {
4984
5014
s => s. to_string ( ) ,
4985
5015
}
4986
5016
} ) ;
4987
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
5017
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
4988
5018
}
0 commit comments