File tree 2 files changed +47
-3
lines changed
librustc_incremental/persist
2 files changed +47
-3
lines changed Original file line number Diff line number Diff line change 22
22
use std:: io:: { self , Read } ;
23
23
use std:: path:: Path ;
24
24
use std:: fs:: File ;
25
+ use std:: env;
26
+
27
+ use rustc:: session:: config:: nightly_options;
25
28
26
29
/// The first few bytes of files generated by incremental compilation
27
30
const FILE_MAGIC : & ' static [ u8 ] = b"RSIC" ;
@@ -38,9 +41,11 @@ pub fn write_file_header<W: io::Write>(stream: &mut W) -> io::Result<()> {
38
41
stream. write_all ( FILE_MAGIC ) ?;
39
42
stream. write_all ( & [ ( HEADER_FORMAT_VERSION >> 0 ) as u8 ,
40
43
( HEADER_FORMAT_VERSION >> 8 ) as u8 ] ) ?;
41
- assert_eq ! ( RUSTC_VERSION . len( ) , ( RUSTC_VERSION . len( ) as u8 ) as usize ) ;
42
- stream. write_all ( & [ RUSTC_VERSION . len ( ) as u8 ] ) ?;
43
- stream. write_all ( RUSTC_VERSION . as_bytes ( ) ) ?;
44
+
45
+ let rustc_version = rustc_version ( ) ;
46
+ assert_eq ! ( rustc_version. len( ) , ( rustc_version. len( ) as u8 ) as usize ) ;
47
+ stream. write_all ( & [ rustc_version. len ( ) as u8 ] ) ?;
48
+ stream. write_all ( rustc_version. as_bytes ( ) ) ?;
44
49
45
50
Ok ( ( ) )
46
51
}
@@ -103,3 +108,13 @@ pub fn read_file(path: &Path) -> io::Result<Option<Vec<u8>>> {
103
108
104
109
Ok ( Some ( data) )
105
110
}
111
+
112
+ fn rustc_version ( ) -> String {
113
+ if nightly_options:: is_nightly_build ( ) {
114
+ if let Some ( val) = env:: var_os ( "RUSTC_FORCE_INCR_COMP_ARTIFACT_HEADER" ) {
115
+ return val. to_string_lossy ( ) . into_owned ( )
116
+ }
117
+ }
118
+
119
+ RUSTC_VERSION . to_string ( )
120
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // This test case makes sure that the compiler does not try to re-use anything
12
+ // from the incremental compilation cache if the cache was produced by a
13
+ // different compiler version. This is tested by artificially forcing the
14
+ // emission of a different compiler version in the header of rpass1 artifacts,
15
+ // and then making sure that the only object file of the test program gets
16
+ // re-translated although the program stays unchanged.
17
+
18
+ // The `l33t haxx0r` Rust compiler is known to produce incr. comp. artifacts
19
+ // that are outrageously incompatible with just about anything, even itself:
20
+ //[rpass1] rustc-env:RUSTC_FORCE_INCR_COMP_ARTIFACT_HEADER="l33t haxx0r rustc 2.1 LTS"
21
+
22
+ // revisions:rpass1 rpass2
23
+
24
+ #![ feature( rustc_attrs) ]
25
+ #![ rustc_partition_translated( module="cache_file_headers" , cfg="rpass2" ) ]
26
+
27
+ fn main ( ) {
28
+ // empty
29
+ }
You can’t perform that action at this time.
0 commit comments