mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
Make generated names stable when sorting.
This commit is contained in:
parent
a654d13eef
commit
577d188f72
2 changed files with 35 additions and 12 deletions
12
ci/script.sh
12
ci/script.sh
|
@ -27,13 +27,15 @@ arm_example() {
|
|||
else
|
||||
cargo $COMMAND $CARGO_FLAGS
|
||||
fi
|
||||
arm-none-eabi-objcopy -O ihex target/$TARGET/$BUILD_MODE/examples/$EXAMPLE ${EXAMPLE}_${FEATURES_STR}${BUILD_MODE}_${BUILD_NUM}.hex
|
||||
arm-none-eabi-objcopy -O ihex target/$TARGET/$BUILD_MODE/examples/$EXAMPLE ci/builds/${EXAMPLE}_${FEATURES_STR}${BUILD_MODE}_${BUILD_NUM}.hex
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
local T=$TARGET
|
||||
|
||||
mkdir -p ci/builds
|
||||
|
||||
if [ $T = x86_64-unknown-linux-gnu ]; then
|
||||
# compile-fail and compile-pass tests
|
||||
case $TRAVIS_RUST_VERSION in
|
||||
|
@ -138,16 +140,16 @@ main() {
|
|||
|
||||
if [ $ex != types ]; then
|
||||
arm_example "build" $ex "debug" "" "2"
|
||||
cmp ${ex}_debug_1.hex ${ex}_debug_2.hex
|
||||
cmp ci/builds/${ex}_debug_1.hex ci/builds/${ex}_debug_2.hex
|
||||
arm_example "build" $ex "release" "" "2"
|
||||
cmp ${ex}_release_1.hex ${ex}_release_2.hex
|
||||
cmp ci/builds/${ex}_release_1.hex ci/builds/${ex}_release_2.hex
|
||||
fi
|
||||
|
||||
if [ $TARGET != thumbv6m-none-eabi ]; then
|
||||
arm_example "build" $ex "debug" "timer-queue" "2"
|
||||
cmp ${ex}_timer-queue_debug_1.hex ${ex}_timer-queue_debug_2.hex
|
||||
cmp ci/builds/${ex}_timer-queue_debug_1.hex ci/builds/${ex}_timer-queue_debug_2.hex
|
||||
arm_example "build" $ex "release" "timer-queue" "2"
|
||||
cmp ${ex}_timer-queue_release_1.hex ${ex}_timer-queue_release_2.hex
|
||||
cmp ci/builds/${ex}_timer-queue_release_1.hex ci/builds/${ex}_timer-queue_release_2.hex
|
||||
fi
|
||||
done
|
||||
esac
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use proc_macro::TokenStream;
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use proc_macro2::Span;
|
||||
|
@ -1993,30 +1994,48 @@ fn mk_typenum_capacity(capacity: u8, power_of_two: bool) -> proc_macro2::TokenSt
|
|||
}
|
||||
|
||||
struct IdentGenerator {
|
||||
call_count: u32,
|
||||
rng: rand::rngs::SmallRng,
|
||||
}
|
||||
|
||||
impl IdentGenerator {
|
||||
fn new() -> IdentGenerator {
|
||||
let crate_name = env!("CARGO_PKG_NAME");
|
||||
let seed = [0u8; 16];
|
||||
for (i, b) in crate_name.bytes().enumerate() {
|
||||
seed[i%seed.len()].wrapping_add(b);
|
||||
let elapsed = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
|
||||
|
||||
let secs = elapsed.as_secs();
|
||||
let nanos = elapsed.subsec_nanos();
|
||||
|
||||
let mut seed: [u8; 16] = [0; 16];
|
||||
|
||||
for (i, v) in seed.iter_mut().take(8).enumerate() {
|
||||
*v = ((secs >> (i * 8)) & 0xFF) as u8
|
||||
}
|
||||
|
||||
for (i, v) in seed.iter_mut().skip(8).take(4).enumerate() {
|
||||
*v = ((nanos >> (i * 8)) & 0xFF) as u8
|
||||
}
|
||||
|
||||
let rng = rand::rngs::SmallRng::from_seed(seed);
|
||||
|
||||
IdentGenerator {
|
||||
call_count: 0,
|
||||
rng,
|
||||
}
|
||||
IdentGenerator { rng: rand::rngs::SmallRng::from_seed(seed) }
|
||||
}
|
||||
|
||||
fn mk_ident(&mut self, name: Option<&str>) -> Ident {
|
||||
let n;
|
||||
let mut s = if let Some(name) = name {
|
||||
let s = if let Some(name) = name {
|
||||
n = 4;
|
||||
format!("{}_", name)
|
||||
} else {
|
||||
let crate_name = env!("CARGO_PKG_NAME").replace("-", "_").to_lowercase();
|
||||
n = 16;
|
||||
n = 4;
|
||||
format!("{}__internal__", crate_name)
|
||||
};
|
||||
|
||||
let mut s = format!("{}{}_", s, self.call_count);
|
||||
|
||||
for i in 0..n {
|
||||
if i == 0 || self.rng.gen() {
|
||||
s.push(('a' as u8 + self.rng.gen::<u8>() % 25) as char)
|
||||
|
@ -2025,6 +2044,8 @@ impl IdentGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
self.call_count += 1;
|
||||
|
||||
Ident::new(&s, Span::call_site())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue