Lines
95.59 %
Functions
100 %
Branches
use sha2::{Digest, Sha256};
use std::env;
use std::fs;
use std::io::{self, Read};
use std::process::Command;
fn checksum(file_path: &str) -> io::Result<String> {
let mut file = fs::File::open(file_path)?;
let mut hasher = Sha256::new();
let mut buffer = [0; 1024];
loop {
let bytes_read = file.read(&mut buffer)?;
if bytes_read == 0 {
break;
}
hasher.update(&buffer[..bytes_read]);
Ok(format!("{:x}", hasher.finalize()))
fn main() {
println!("cargo:rerun-if-changed=../doc/disdoc.org");
let status = Command::new("emacs")
.args([
"-q",
"--batch",
"../doc/disdoc.org",
"-l",
"ox-md",
"--eval",
"(org-md-export-to-markdown)",
"-f",
"save-buffer",
"kill-emacs",
])
.status()
.expect("Failed to export doc");
assert!(status.success(), "Building finance doc failed");
fs::rename("../doc/disdoc.md", "../target/nomisync.md").expect("Can't update finance doc file");
println!(
"cargo:rustc-env=CARGO_TARGET_DIR={}/../",
env::var("CARGO_MANIFEST_DIR").unwrap()
);
println!("cargo:rerun-if-changed=../doc/nomisync.org");
"../doc/nomisync.org",
"(org-babel-tangle)",
.expect("Failed to export SQL");
let status = Command::new("sqlfluff")
"fix",
"--dialect",
"postgres",
"../doc/nomisync.sql",
"--force",
.expect("Failed to format SQL");
assert!(status.success(), "Building migrations failed");
if checksum("../doc/nomisync.sql").unwrap()
== checksum("../migrations/0002_nomisync.sql").unwrap()
{
fs::remove_file("../doc/nomisync.sql").unwrap();
} else {
fs::rename("../doc/nomisync.sql", "../migrations/0002_nomisync.sql")
.expect("Can't update finance migrations file");
println!("cargo:rerun-if-changed=../migrations");