Skip to content

Commit 83eeab3

Browse files
authored
Merge pull request #23 from jethrogb/fix-old-versions
Parse mapping.rs manually, fix CI versions.
2 parents 2484fc7 + 74ade3b commit 83eeab3

File tree

4 files changed

+58
-45
lines changed

4 files changed

+58
-45
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ branches:
99
language: rust
1010
dist: xenial
1111
rust:
12-
- nightly-2015-05-01 # see ct.sh for more versions
12+
- nightly-2016-03-11 # see ct.sh for more versions
1313
env:
1414
- RUST_BACKTRACE=1
1515
before_script:

build.rs

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,45 @@ use std::env;
44
use std::fs::File;
55
use std::io::Write;
66
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+
218
struct Mapping(&'static str,&'static str);
229

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;
2720
}
28-
}
2921

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+
}
3528
}
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
3646
}
3747

3848
fn main() {
@@ -42,8 +52,8 @@ fn main() {
4252
Ok(c) => c,
4353
Err(env::VarError::NotUnicode(_)) => panic!("Invalid commit specified in CORE_IO_COMMIT"),
4454
Err(env::VarError::NotPresent) => {
45-
let mappings=include!("mapping.rs");
46-
55+
let mappings=parse_mappings(include_str!("mapping.rs"));
56+
4757
let compiler=ver.commit_hash.expect("Couldn't determine compiler version");
4858
mappings.iter().find(|&&Mapping(elem,_)|elem==compiler).expect("Unknown compiler version, upgrade core_io?").1.to_owned()
4959
}

ct.sh

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
#!/bin/bash -e
2+
3+
# Old versions should come first so we go from oldest Cargo.lock version to
4+
# newest when building.
25
RUST_VERSIONS=$(awk '{print $1}' <<EOF
3-
nightly-2019-04-27 # core_io release
4-
nightly-2018-08-14 # edge case: old features disallowed
5-
nightly-2018-08-06 # edge case: old features allowed
6-
nightly-2018-03-07 # core_io release
7-
nightly-2018-01-02 # edge case: memchr in core
8-
nightly-2018-01-01 # edge case: no memchr in core
9-
nightly-2017-06-16 # edge case: no collections crate
10-
nightly-2017-06-15 # edge case: collections crate
11-
nightly-2017-04-09 # core_io release
12-
nightly-2017-03-04 # edge case: std_unicode crate
13-
nightly-2017-03-03 # edge case: rustc_unicode crate
14-
nightly-2017-01-18 # edge case: rustc_unicode crate
15-
nightly-2016-12-05 # edge case: no unicode crate
16-
nightly-2016-10-28 # core_io release
6+
nightly-2016-03-11 # first supported version
177
nightly-2016-07-07 # core_io release
18-
nightly-2015-05-01 # some old version
8+
nightly-2016-10-28 # core_io release
9+
nightly-2016-12-05 # edge case: no unicode crate
10+
nightly-2017-01-18 # edge case: rustc_unicode crate
11+
nightly-2017-03-03 # edge case: rustc_unicode crate
12+
nightly-2017-03-04 # edge case: std_unicode crate
13+
nightly-2017-04-09 # core_io release
14+
nightly-2017-06-15 # edge case: collections crate
15+
nightly-2017-06-16 # edge case: no collections crate
16+
nightly-2018-01-01 # edge case: no memchr in core
17+
nightly-2018-01-02 # edge case: memchr in core
18+
nightly-2018-03-07 # core_io release
19+
nightly-2018-08-06 # edge case: old features allowed
20+
nightly-2018-08-14 # edge case: old features disallowed
21+
nightly-2019-04-27 # core_io release
1922
EOF
2023
)
2124

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
//! the [std documentation](https://doc.rust-lang.org/nightly/std/io/index.html)
44
//! for a full description of the functionality.
55
#![allow(stable_features,unused_features)]
6-
#![feature(question_mark,const_fn,copy_from_slice,non_exhaustive,
7-
bind_by_move_pattern_guards,try_from,str_internals,align_offset,doc_spotlight,
8-
slice_internals)]
6+
#![feature(question_mark,const_fn,collections,alloc,unicode,copy_from_slice,
7+
str_char,try_from,str_internals,align_offset,doc_spotlight,
8+
slice_internals,non_exhaustive,bind_by_move_pattern_guards)]
99
#![no_std]
1010

1111
#[cfg_attr(feature="collections",macro_use)]

0 commit comments

Comments
 (0)