Buttplug sex toy control library

build: Check for changes between old/new device files on build

Just in case

Fixes #747

+16 -10
+16 -10
crates/buttplug_server_device_config/build.rs
··· 10 10 const PROTOCOL_DIR: &str = "./device-config-v4/protocols/"; 11 11 const SCHEMA_FILE: &str = "./device-config-v4/buttplug-device-config-schema-v4.json"; 12 12 13 - #[derive(Serialize, Deserialize)] 13 + #[derive(Serialize, Deserialize, Eq, PartialEq)] 14 14 struct VersionFile { 15 15 version: BuildVersion 16 16 } 17 17 18 - #[derive(Serialize, Deserialize)] 18 + #[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Copy)] 19 19 struct BuildVersion { 20 20 pub major: u32, 21 21 pub minor: u32 22 22 } 23 23 24 - #[derive(Serialize)] 24 + #[derive(Deserialize, Serialize, Eq, PartialEq)] 25 25 struct JsonOutputFile { 26 26 version: BuildVersion, 27 27 protocols: BTreeMap<String, Value> ··· 34 34 let mut version: VersionFile = serde_yaml::from_str(&std::fs::read_to_string(VERSION_FILE).unwrap()).unwrap(); 35 35 // Bump minor version 36 36 version.version.minor += 1; 37 - std::fs::write(VERSION_FILE, serde_yaml::to_string(&version).unwrap().as_bytes()).unwrap(); 38 - 37 + 39 38 // Compile device config file 40 39 let mut output = JsonOutputFile { 41 40 // lol ··· 49 48 } 50 49 51 50 let json = serde_json::to_string(&output).unwrap(); 51 + 52 + // Validate 52 53 let validator = JSONValidator::new(&std::fs::read_to_string(SCHEMA_FILE).unwrap()); 53 54 validator.validate(&json).unwrap(); 54 55 55 - // Validate 56 + // See if it's actually different than our last output file 57 + if let Ok(true) = std::fs::exists(OUTPUT_FILE) { 58 + let old_output: JsonOutputFile = serde_json::from_str(&std::fs::read_to_string(OUTPUT_FILE).unwrap()).unwrap(); 59 + if old_output.protocols == output.protocols { 60 + // No actual changes, break out early, don't save 61 + return; 62 + } 63 + } 56 64 57 65 // Save it to the build_config directory 58 - std::fs::write(OUTPUT_FILE, json.as_bytes()).unwrap(); 59 - 60 - 61 - 66 + std::fs::write(VERSION_FILE, serde_yaml::to_string(&version).unwrap().as_bytes()).unwrap(); 67 + std::fs::write(OUTPUT_FILE, json.as_bytes()).unwrap(); 62 68 }