1pub struct GenerationTargetSupport {
8 pub emit: &'static str,
10 pub display_name: &'static str,
12 pub output_relative_path: &'static str,
14 pub preview_label: &'static str,
16 pub preview_language_id: &'static str,
18}
19
20static GENERATION_TARGET_CATALOG: &[GenerationTargetSupport] = &[
21 GenerationTargetSupport {
22 emit: "zephyr-conf",
23 display_name: "Zephyr config",
24 output_relative_path: "build/generated/alp.conf",
25 preview_label: "Zephyr config preview",
26 preview_language_id: "properties",
27 },
28 GenerationTargetSupport {
29 emit: "dts-overlay",
30 display_name: "Devicetree overlay",
31 output_relative_path: "build/generated/alp.overlay",
32 preview_label: "Devicetree overlay preview",
33 preview_language_id: "dts",
34 },
35 GenerationTargetSupport {
36 emit: "cmake-args",
37 display_name: "CMake args",
38 output_relative_path: "build/generated/alp-cmake-args.txt",
39 preview_label: "CMake args preview",
40 preview_language_id: "plaintext",
41 },
42 GenerationTargetSupport {
43 emit: "yocto-conf",
44 display_name: "Yocto config",
45 output_relative_path: "build/generated/alp-yocto.conf",
46 preview_label: "Yocto config preview",
47 preview_language_id: "properties",
48 },
49];
50
51pub fn list_generation_target_support() -> &'static [GenerationTargetSupport] {
53 GENERATION_TARGET_CATALOG
54}
55
56pub fn generation_target_support(emit: &str) -> Option<&'static GenerationTargetSupport> {
58 GENERATION_TARGET_CATALOG.iter().find(|t| t.emit == emit)
59}
60
61pub const ALL_EMIT_MODES: [&str; 4] = ["zephyr-conf", "dts-overlay", "cmake-args", "yocto-conf"];
63
64pub struct LoaderPlan {
69 pub output_path: String,
71 pub command_line: String,
73}
74
75pub fn create_loader_plan(
78 workspace_root: &str,
79 sdk_root: &str,
80 board_yaml_path: &str,
81 python_binary: &str,
82 target: &GenerationTargetSupport,
83) -> LoaderPlan {
84 let output_path = std::path::Path::new(workspace_root)
85 .join(target.output_relative_path)
86 .to_string_lossy()
87 .to_string();
88 let script_path = std::path::Path::new(sdk_root)
89 .join("scripts")
90 .join("alp_project.py")
91 .to_string_lossy()
92 .to_string();
93 let command_line = format!(
94 "{python_binary} {script_path} --input {board_yaml_path} --emit {} --output {output_path}",
95 target.emit
96 );
97 LoaderPlan {
98 output_path,
99 command_line,
100 }
101}
102
103#[cfg(test)]
104mod tests {
105 use super::*;
106
107 #[test]
108 fn catalog_lists_four_targets_in_order() {
109 let emits: Vec<&str> = list_generation_target_support()
110 .iter()
111 .map(|t| t.emit)
112 .collect();
113 assert_eq!(
114 emits,
115 ["zephyr-conf", "dts-overlay", "cmake-args", "yocto-conf"]
116 );
117 }
118
119 #[test]
120 fn lookup_by_emit() {
121 assert_eq!(
122 generation_target_support("cmake-args").map(|t| t.display_name),
123 Some("CMake args")
124 );
125 assert!(generation_target_support("bogus").is_none());
126 }
127}