oxidecomputer / hubris

A lightweight, memory-protected, message-passing kernel for deeply embedded systems.
Mozilla Public License 2.0
2.96k stars 169 forks source link

Giant match statements in flash xtask are fragile, error-prone #1886

Open cbiffle opened 2 hours ago

cbiffle commented 2 hours ago

Currently in build/xtask/src/flash.rs we have giant match statements that derive properties of boards based on hardcoded names. They look like this:

    let mut flash = match board {
        "lpcxpresso55s69" | "rot-carrier-1" | "rot-carrier-2"
        | "oxide-rot-1" => {
           // stuff
        }

        "stm32f3-discovery" | "stm32f4-discovery" | "nucleo-h743zi2"
        | "nucleo-h753zi" | "gemini-bu-1" | "gimletlet-1" | "gimletlet-2"
        | "gimlet-b" | "gimlet-c" | "gimlet-d" | "gimlet-e" | "psc-b"
        | "psc-c" | "sidecar-b" | "sidecar-c" | "sidecar-d"
        | "stm32g031-nucleo" | "donglet-g030" | "donglet-g031"
        | "oxcon2023g0" | "stm32g070-nucleo" | "stm32g0b1-nucleo"
        | "medusa-a" | "grapefruit" => {
           // things

This is inflexible and hard to maintain in ways that are actively causing us trouble. Case in point: in #1806 we accidentally removed "gimlet-f" from the match (when resolving a merge conflict with the change that added it) and neither Aaron nor I noticed, because honestly how would you. In #1885 we're restoring it.

While I was getting #1774 in over the course of about five months, I had repeated merge conflicts on this specific code, and spent more time than I'd like staring at it to make sure I didn't resolve them wrong.

Fortunately, in #1774 I also introduced the boards/ directory containing TOML board definitions. These files are currently empty. We should move the information being derived by these horrible match statements into the TOML files.