use BTree{Map,Set} to ensure a stable order based on the key/entry even if filesystem enumeration order changes
this should help with reproducibility
This commit is contained in:
@@ -33,7 +33,6 @@ function_casts_as_integer = "deny"
|
|||||||
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
indexmap = "2.3.0"
|
|
||||||
proc-macro2 = "1.0.86"
|
proc-macro2 = "1.0.86"
|
||||||
quote = "1.0.36"
|
quote = "1.0.36"
|
||||||
strum = "0.26"
|
strum = "0.26"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ mod static_string_indexing;
|
|||||||
use instructions_template::generate_instructions_rs;
|
use instructions_template::generate_instructions_rs;
|
||||||
use static_string_indexing::index_static_strings;
|
use static_string_indexing::index_static_strings;
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
@@ -13,11 +14,12 @@ use std::path::MAIN_SEPARATOR_STR;
|
|||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
fn find_prolog_files(path_prefix: &str, current_dir: &Path) -> Vec<(String, PathBuf)> {
|
fn find_prolog_files(path_prefix: &str, current_dir: &Path) -> Vec<(String, PathBuf)> {
|
||||||
let mut libraries = vec![];
|
// use a BTreeMap to get a stable order independent of fs enumeration order
|
||||||
|
let mut libraries = BTreeMap::new();
|
||||||
|
|
||||||
let entries = match current_dir.read_dir() {
|
let entries = match current_dir.read_dir() {
|
||||||
Ok(entries) => entries,
|
Ok(entries) => entries,
|
||||||
Err(_) => return libraries,
|
Err(_) => return vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
for entry in entries.filter_map(Result::ok).map(|e| e.path()) {
|
for entry in entries.filter_map(Result::ok).map(|e| e.path()) {
|
||||||
@@ -34,12 +36,12 @@ fn find_prolog_files(path_prefix: &str, current_dir: &Path) -> Vec<(String, Path
|
|||||||
let name = entry.file_stem().unwrap().to_str().unwrap();
|
let name = entry.file_stem().unwrap().to_str().unwrap();
|
||||||
let lib_name = format!("{path_prefix}{name}");
|
let lib_name = format!("{path_prefix}{name}");
|
||||||
|
|
||||||
libraries.push((lib_name, entry));
|
libraries.insert(lib_name, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
libraries
|
libraries.into_iter().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use syn::parse::*;
|
use syn::parse::*;
|
||||||
use syn::visit::*;
|
use syn::visit::*;
|
||||||
use syn::*;
|
use syn::*;
|
||||||
|
|
||||||
use indexmap::IndexSet;
|
|
||||||
|
|
||||||
struct StaticStrVisitor {
|
struct StaticStrVisitor {
|
||||||
static_strs: IndexSet<String>,
|
static_strs: BTreeSet<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticStrVisitor {
|
impl StaticStrVisitor {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
static_strs: IndexSet::new(),
|
static_strs: BTreeSet::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,9 +166,9 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea
|
|||||||
visitor.visit_file(&syntax)
|
visitor.visit_file(&syntax)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut static_str_keys = vec![];
|
let static_str_keys: Vec<_> = visitor.static_strs.iter().collect();
|
||||||
let mut static_strs = vec![];
|
let mut static_strs = Vec::with_capacity(static_str_keys.len());
|
||||||
let mut static_str_indices = vec![];
|
let mut static_str_indices = Vec::with_capacity(static_str_keys.len());
|
||||||
|
|
||||||
let indices: Vec<u64> = visitor
|
let indices: Vec<u64> = visitor
|
||||||
.static_strs
|
.static_strs
|
||||||
@@ -176,8 +176,6 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea
|
|||||||
.map(|string| {
|
.map(|string| {
|
||||||
let index = static_string_index(string, static_strs.len());
|
let index = static_string_index(string, static_strs.len());
|
||||||
|
|
||||||
static_str_keys.push(string);
|
|
||||||
|
|
||||||
if index & 1 == 1 {
|
if index & 1 == 1 {
|
||||||
index
|
index
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user