chore: establish wave 7 local baseline
This commit is contained in:
@@ -35,7 +35,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if check {
|
||||
let mut stale = Vec::new();
|
||||
for (path, expected) in outputs {
|
||||
if fs::read(&path).ok().as_deref() != Some(expected.as_slice()) {
|
||||
let matches = fs::read(&path).ok().is_some_and(|actual| {
|
||||
normalize_line_endings(&actual) == normalize_line_endings(&expected)
|
||||
});
|
||||
if !matches {
|
||||
stale.push(path);
|
||||
}
|
||||
}
|
||||
@@ -57,6 +60,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn normalize_line_endings(bytes: &[u8]) -> Vec<u8> {
|
||||
let mut normalized = Vec::with_capacity(bytes.len());
|
||||
let mut index = 0;
|
||||
|
||||
while index < bytes.len() {
|
||||
if bytes[index] == b'\r' && bytes.get(index + 1) == Some(&b'\n') {
|
||||
normalized.push(b'\n');
|
||||
index += 2;
|
||||
} else {
|
||||
normalized.push(bytes[index]);
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
normalized
|
||||
}
|
||||
|
||||
fn generated_outputs(root: &Path) -> Result<GeneratedOutputs, Box<dyn std::error::Error>> {
|
||||
let mut outputs = Vec::new();
|
||||
let schema_dir = root.join("contracts/schema");
|
||||
@@ -100,7 +120,10 @@ fn generated_outputs(root: &Path) -> Result<GeneratedOutputs, Box<dyn std::error
|
||||
outputs.push((root.join("contracts/ts/index.ts"), ts.into_bytes()));
|
||||
|
||||
let domain_source = fs::read(root.join("crates/nana-domain/src/lib.rs"))?;
|
||||
let source_hash = format!("{:x}\n", Sha256::digest(domain_source));
|
||||
let source_hash = format!(
|
||||
"{:x}\n",
|
||||
Sha256::digest(normalize_line_endings(&domain_source))
|
||||
);
|
||||
outputs.push((
|
||||
root.join("contracts/.source.sha256"),
|
||||
source_hash.into_bytes(),
|
||||
@@ -205,3 +228,20 @@ fn add_schema<T: JsonSchema + Serialize>(
|
||||
outputs.push((schema_dir.join(format!("{name}.schema.json")), bytes));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::normalize_line_endings;
|
||||
|
||||
#[test]
|
||||
fn source_hash_input_is_independent_of_checkout_line_endings() {
|
||||
assert_eq!(
|
||||
normalize_line_endings(b"first\r\nsecond\nthird\r"),
|
||||
b"first\nsecond\nthird\r"
|
||||
);
|
||||
assert_eq!(
|
||||
normalize_line_endings(b"first\nsecond\nthird\r"),
|
||||
b"first\nsecond\nthird\r"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user