blob: 63764b60202c13599f874ee90d7ec3a8da7691e8 [file] [log] [blame]
David Tolnay10227122019-02-15 20:53:45 -08001use crate::types::Definitions;
Carl Lerche9a7d5882019-02-15 12:27:04 -08002
David Tolnay10227122019-02-15 20:53:45 -08003use std::fs;
Carl Lerche9a7d5882019-02-15 12:27:04 -08004use std::path::Path;
5
David Tolnay10227122019-02-15 20:53:45 -08006pub fn generate(defs: &Definitions) {
David Tolnay12c027f2019-02-28 23:39:57 -08007 let mut j = serde_json::to_string_pretty(&defs).unwrap();
8 j.push('\n');
9
David Tolnay10227122019-02-15 20:53:45 -080010 let check: Definitions = serde_json::from_str(&j).unwrap();
11 assert_eq!(*defs, check);
12
Carl Lerche9a7d5882019-02-15 12:27:04 -080013 let codegen_root = Path::new(env!("CARGO_MANIFEST_DIR"));
David Tolnay07b2cca2019-02-15 18:58:27 -080014 let json_path = codegen_root.join("../syn.json");
15 fs::write(json_path, j).unwrap();
Carl Lerche9a7d5882019-02-15 12:27:04 -080016}