@@ -4,35 +4,45 @@ use std::env;
4
4
use std:: fs:: File ;
5
5
use std:: io:: Write ;
6
6
use std:: path:: PathBuf ;
7
- use std:: ops:: { Neg , Sub } ;
8
-
9
- /*
10
- * Let me explain this hack. For the sync shell script it's easiest if every
11
- * line in mapping.rs looks exactly the same. This means that specifying an
12
- * array literal is not possible. include!() can only expand to expressions, so
13
- * just specifying the contents of an array is also not possible.
14
- *
15
- * This leaves us with trying to find an expression in which every line looks
16
- * the same. This can be done using the `-` operator. This can be a unary
17
- * operator (first thing on the first line), or a binary operator (later
18
- * lines). That is exactly what's going on here, and Neg and Sub simply build a
19
- * vector of the operangs.
20
- */
7
+
21
8
struct Mapping ( & ' static str , & ' static str ) ;
22
9
23
- impl Neg for Mapping {
24
- type Output = Vec < Mapping > ;
25
- fn neg ( self ) -> Vec < Mapping > {
26
- vec ! [ self . into( ) ]
10
+ fn parse_mappings ( mut mappings : & ' static str ) -> Vec < Mapping > {
11
+ // FIXME: The format used here used to be parsed directly by rustc, which
12
+ // is why it's kind of weird. It should be changed to a saner format.
13
+
14
+ const P1 : & ' static str = r#"-Mapping(""# ;
15
+ const P2 : & ' static str = r#"",""# ; ;
16
+ const P3 : & ' static str = "\" )\n " ;
17
+
18
+ trait TakePrefix : Sized {
19
+ fn take_prefix ( & mut self , mid : usize ) -> Self ;
27
20
}
28
- }
29
21
30
- impl Sub < Mapping > for Vec < Mapping > {
31
- type Output =Vec < Mapping > ;
32
- fn sub ( mut self , rhs : Mapping ) -> Vec < Mapping > {
33
- self . push ( rhs. into ( ) ) ;
34
- self
22
+ impl < ' a > TakePrefix for & ' a str {
23
+ fn take_prefix ( & mut self , mid : usize ) -> Self {
24
+ let prefix = & self [ ..mid] ;
25
+ * self = & self [ mid..] ;
26
+ prefix
27
+ }
35
28
}
29
+
30
+ let mut result = Vec :: with_capacity ( mappings. len ( ) / ( P1 . len ( ) +40 +P2 . len ( ) +40 +P3 . len ( ) ) ) ;
31
+
32
+ while mappings. len ( ) != 0 {
33
+ match (
34
+ mappings. take_prefix ( P1 . len ( ) ) ,
35
+ mappings. take_prefix ( 40 ) ,
36
+ mappings. take_prefix ( P2 . len ( ) ) ,
37
+ mappings. take_prefix ( 40 ) ,
38
+ mappings. take_prefix ( P3 . len ( ) ) ,
39
+ ) {
40
+ ( P1 , hash1, P2 , hash2, P3 ) => result. push ( Mapping ( hash1, hash2) ) ,
41
+ _ => panic ! ( "Invalid input in mappings" ) ,
42
+ }
43
+ }
44
+
45
+ result
36
46
}
37
47
38
48
fn main ( ) {
@@ -42,8 +52,8 @@ fn main() {
42
52
Ok ( c) => c,
43
53
Err ( env:: VarError :: NotUnicode ( _) ) => panic ! ( "Invalid commit specified in CORE_IO_COMMIT" ) ,
44
54
Err ( env:: VarError :: NotPresent ) => {
45
- let mappings=include ! ( "mapping.rs" ) ;
46
-
55
+ let mappings=parse_mappings ( include_str ! ( "mapping.rs" ) ) ;
56
+
47
57
let compiler=ver. commit_hash . expect ( "Couldn't determine compiler version" ) ;
48
58
mappings. iter ( ) . find ( |& & Mapping ( elem, _) |elem==compiler) . expect ( "Unknown compiler version, upgrade core_io?" ) . 1 . to_owned ( )
49
59
}
0 commit comments