| 194 | struct Program { |
| 195 | name: String, |
| 196 | title: String, |
| 197 | description: String, |
| 198 | kind: Kind, |
| 199 | install_path: Option<String>, |
| 200 | source: String, |
| 201 | build_path: String, |
| 202 | import_closure: bool, |
| 203 | mangle_symbols: bool, |
| 204 | layout_const: Option<String>, |
| 205 | layout_path: Option<String>, |
| 206 | } |
| 207 | |
| 208 | impl Program { |
| 209 | fn load(build_path: &Path) -> Self { |
| 210 | println!("cargo:rerun-if-changed={}", build_path.display()); |
| 211 | let text = fs::read_to_string(build_path).expect("read .build"); |
| 212 | let manifest = build_manifest::parse(&text) |
| 213 | .unwrap_or_else(|err| panic!("{}: {err}", build_path.display())); |
| 214 | let dir = build_path.parent().expect("manifest parent"); |
| 215 | let field = |key: &str| { |
| 216 | manifest |
| 217 | .string(key) |
| 218 | .unwrap_or_else(|| panic!("{}: missing `{key}`", build_path.display())) |
| 219 | }; |
| 220 | |
| 221 | let name = field("name"); |
| 222 | let kind = Kind::parse(&field("kind")); |
| 223 | let source = abs(dir, &field("root")); |
| 224 | println!("cargo:rerun-if-changed={source}"); |
| 225 | let import_closure = manifest |
| 226 | .bool("import_closure") |
| 227 | .expect("import_closure") |
| 228 | .unwrap_or(true); |
| 229 | let mangle_symbols = manifest |
| 230 | .bool("mangle_symbols") |
| 231 | .expect("mangle_symbols") |
| 232 | .unwrap_or(true); |
| 233 | |
| 234 | let (layout_const, layout_path) = match manifest.get("source_prelude") { |
| 235 | Some(rel) => { |
| 236 | let path = abs(dir, rel); |
| 237 | println!("cargo:rerun-if-changed={path}"); |
| 238 | (Some(format!("{}_LAYOUT", name.to_uppercase())), Some(path)) |
| 239 | } |
| 240 | None => (None, None), |
| 241 | }; |
| 242 | |
| 243 | Self { |
| 244 | name, |
| 245 | title: field("title"), |
| 246 | description: field("description"), |