@@ -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) {
@@ -150,11 +154,37 @@ fn main() {
150
154
// Avoid unnecessary re-building.
151
155
println ! ( "cargo:rerun-if-changed=build.rs" ) ;
152
156
157
+ let hotfix_dir = src_hotfix_dir ( ) ;
158
+ if std:: fs:: exists ( & hotfix_dir) . unwrap ( ) {
159
+ std:: fs:: remove_dir_all ( & hotfix_dir) . unwrap ( ) ;
160
+ }
161
+
162
+ // FIXME(ctest): ctest2 cannot parse `crate::` in paths, so replace them with `::`
163
+ let re = regex:: bytes:: Regex :: new ( r"(?-u:\b)crate::" ) . unwrap ( ) ;
164
+ copy_dir_hotfix ( Path :: new ( "../src" ) , & hotfix_dir, & re, b"::" ) ;
165
+
153
166
do_cc ( ) ;
154
167
do_ctest ( ) ;
155
168
do_semver ( ) ;
156
169
}
157
170
171
+ fn copy_dir_hotfix ( src : & Path , dst : & Path , regex : & regex:: bytes:: Regex , replace : & [ u8 ] ) {
172
+ std:: fs:: create_dir ( & dst) . unwrap ( ) ;
173
+ for entry in src. read_dir ( ) . unwrap ( ) {
174
+ let entry = entry. unwrap ( ) ;
175
+ let src_path = entry. path ( ) ;
176
+ let dst_path = dst. join ( entry. file_name ( ) ) ;
177
+ if entry. file_type ( ) . unwrap ( ) . is_dir ( ) {
178
+ copy_dir_hotfix ( & src_path, & dst_path, regex, replace) ;
179
+ } else {
180
+ // Replace "crate::" with "::"
181
+ let src_data = std:: fs:: read ( & src_path) . unwrap ( ) ;
182
+ let dst_data = regex. replace_all ( & src_data, b"::" ) ;
183
+ std:: fs:: write ( & dst_path, & dst_data) . unwrap ( ) ;
184
+ }
185
+ }
186
+ }
187
+
158
188
macro_rules! headers {
159
189
( $cfg: ident: [ $m: expr] : $header: literal) => {
160
190
if $m {
@@ -464,7 +494,7 @@ fn test_apple(target: &str) {
464
494
"uuid_t" | "vol_capabilities_set_t" => true ,
465
495
_ => false ,
466
496
} ) ;
467
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
497
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
468
498
}
469
499
470
500
fn test_openbsd ( target : & str ) {
@@ -651,7 +681,7 @@ fn test_openbsd(target: &str) {
651
681
}
652
682
} ) ;
653
683
654
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
684
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
655
685
}
656
686
657
687
fn test_windows ( target : & str ) {
@@ -780,7 +810,7 @@ fn test_windows(target: &str) {
780
810
}
781
811
} ) ;
782
812
783
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
813
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
784
814
}
785
815
786
816
fn test_redox ( target : & str ) {
@@ -830,7 +860,7 @@ fn test_redox(target: &str) {
830
860
"wchar.h" ,
831
861
}
832
862
833
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
863
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
834
864
}
835
865
836
866
fn test_solarish ( target : & str ) {
@@ -1108,7 +1138,7 @@ fn test_solarish(target: &str) {
1108
1138
}
1109
1139
} ) ;
1110
1140
1111
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1141
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
1112
1142
}
1113
1143
1114
1144
fn test_netbsd ( target : & str ) {
@@ -1323,7 +1353,7 @@ fn test_netbsd(target: &str) {
1323
1353
}
1324
1354
} ) ;
1325
1355
1326
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1356
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
1327
1357
}
1328
1358
1329
1359
fn test_dragonflybsd ( target : & str ) {
@@ -1549,7 +1579,7 @@ fn test_dragonflybsd(target: &str) {
1549
1579
( struct_ == "sigevent" && field == "sigev_notify_thread_id" )
1550
1580
} ) ;
1551
1581
1552
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1582
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
1553
1583
}
1554
1584
1555
1585
fn test_wasi ( target : & str ) {
@@ -1656,7 +1686,7 @@ fn test_wasi(target: &str) {
1656
1686
// doesn't support sizeof.
1657
1687
cfg. skip_field ( |s, field| s == "dirent" && field == "d_name" ) ;
1658
1688
1659
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
1689
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
1660
1690
}
1661
1691
1662
1692
fn test_android ( target : & str ) {
@@ -2149,7 +2179,7 @@ fn test_android(target: &str) {
2149
2179
}
2150
2180
} ) ;
2151
2181
2152
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
2182
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
2153
2183
2154
2184
test_linux_like_apis ( target) ;
2155
2185
}
@@ -2821,7 +2851,7 @@ fn test_freebsd(target: &str) {
2821
2851
} ) ;
2822
2852
}
2823
2853
2824
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
2854
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
2825
2855
}
2826
2856
2827
2857
fn test_emscripten ( target : & str ) {
@@ -3058,7 +3088,7 @@ fn test_emscripten(target: &str) {
3058
3088
] . contains ( & field) )
3059
3089
} ) ;
3060
3090
3061
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
3091
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
3062
3092
}
3063
3093
3064
3094
fn test_neutrino ( target : & str ) {
@@ -3311,7 +3341,7 @@ fn test_neutrino(target: &str) {
3311
3341
3312
3342
cfg. skip_static ( move |name| ( name == "__dso_handle" ) ) ;
3313
3343
3314
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
3344
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
3315
3345
}
3316
3346
3317
3347
fn test_vxworks ( target : & str ) {
@@ -3419,7 +3449,7 @@ fn test_vxworks(target: &str) {
3419
3449
_ => false ,
3420
3450
} ) ;
3421
3451
3422
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
3452
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
3423
3453
}
3424
3454
3425
3455
fn test_linux ( target : & str ) {
@@ -4553,7 +4583,7 @@ fn test_linux(target: &str) {
4553
4583
_ => false ,
4554
4584
} ) ;
4555
4585
4556
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
4586
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
4557
4587
4558
4588
test_linux_like_apis ( target) ;
4559
4589
}
@@ -4580,7 +4610,7 @@ fn test_linux_like_apis(target: &str) {
4580
4610
} )
4581
4611
. skip_const ( |_| true )
4582
4612
. skip_struct ( |_| true ) ;
4583
- cfg. generate ( "../src/ lib.rs", "linux_strerror_r.rs" ) ;
4613
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_strerror_r.rs" ) ;
4584
4614
}
4585
4615
4586
4616
if linux || android || emscripten {
@@ -4610,7 +4640,7 @@ fn test_linux_like_apis(target: &str) {
4610
4640
t => t. to_string ( ) ,
4611
4641
} ) ;
4612
4642
4613
- cfg. generate ( "../src/ lib.rs", "linux_fcntl.rs" ) ;
4643
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_fcntl.rs" ) ;
4614
4644
}
4615
4645
4616
4646
if linux || android {
@@ -4634,7 +4664,7 @@ fn test_linux_like_apis(target: &str) {
4634
4664
t if is_union => format ! ( "union {}" , t) ,
4635
4665
t => t. to_string ( ) ,
4636
4666
} ) ;
4637
- cfg. generate ( "../src/ lib.rs", "linux_termios.rs" ) ;
4667
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_termios.rs" ) ;
4638
4668
}
4639
4669
4640
4670
if linux || android {
@@ -4662,7 +4692,7 @@ fn test_linux_like_apis(target: &str) {
4662
4692
t if is_union => format ! ( "union {}" , t) ,
4663
4693
t => t. to_string ( ) ,
4664
4694
} ) ;
4665
- cfg. generate ( "../src/ lib.rs", "linux_ipv6.rs" ) ;
4695
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_ipv6.rs" ) ;
4666
4696
}
4667
4697
4668
4698
if linux || android {
@@ -4684,7 +4714,7 @@ fn test_linux_like_apis(target: &str) {
4684
4714
"Elf64_Phdr" | "Elf32_Phdr" => false ,
4685
4715
_ => true ,
4686
4716
} ) ;
4687
- cfg. generate ( "../src/ lib.rs", "linux_elf.rs" ) ;
4717
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_elf.rs" ) ;
4688
4718
}
4689
4719
4690
4720
if linux || android {
@@ -4699,7 +4729,7 @@ fn test_linux_like_apis(target: &str) {
4699
4729
} )
4700
4730
. skip_struct ( |_| true )
4701
4731
. skip_type ( |_| true ) ;
4702
- cfg. generate ( "../src/ lib.rs", "linux_if_arp.rs" ) ;
4732
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "linux_if_arp.rs" ) ;
4703
4733
}
4704
4734
}
4705
4735
@@ -5057,5 +5087,5 @@ fn test_haiku(target: &str) {
5057
5087
s => s. to_string ( ) ,
5058
5088
}
5059
5089
} ) ;
5060
- cfg. generate ( "../src/ lib.rs", "main.rs" ) ;
5090
+ cfg. generate ( src_hotfix_dir ( ) . join ( " lib.rs") , "main.rs" ) ;
5061
5091
}
0 commit comments