fn generate_top_level_module<P: AsRef<Path>>(
    autogenerated_folder_path: P,
    configuration: &Configuration,
) -> Result<()> {
    let filename = autogenerated_folder_path.as_ref().join("mod.rs");
    let mut file = OpenOptions::new().write(true).create(true).truncate(true).open(&filename)?;

    let (serial_enabled, recovery_enabled) = if let Serial::Enabled { recovery_enabled, .. } =
        configuration.feature_configuration.serial
    {
        if !Serial::supported(&configuration.port) {
            panic!(
                "Serial features enabled for a port that doesn't support them: {:?}",
                configuration.port
            );
        }
        (true, recovery_enabled)
    } else {
        (false, false)
    };

    let boot_time_metrics_enabled = if let BootMetrics::Enabled { timing: true } =
        &configuration.feature_configuration.boot_metrics
    {
        if !BootMetrics::timing_supported(&configuration.port) {
            panic!(
                "Timing features enabled for a port that doesn't support them: {:?}",
                configuration.port
            );
        }
        true
    } else {
        false
    };

    let loadstone_greeting = match &configuration.feature_configuration.greetings {
        Greetings::Default => LitStr::new("-- Loadstone --", Span::call_site()),
        Greetings::Custom { loadstone,..} => LitStr::new(&loadstone, Span::call_site()),
    };
    let demo_app_greeting = match &configuration.feature_configuration.greetings {
        Greetings::Default => LitStr::new("-- Loadstone Demo App --", Span::call_site()),
        Greetings::Custom { demo,..} => LitStr::new(&demo, Span::call_site()),
    };

    let update_signal = configuration.feature_configuration.update_signal;
    let update_signal_enabled = matches!(update_signal, UpdateSignal::Enabled);

    let code = quote! {
        //! This entire module is autogenerated. Don't modify it manually!
        //! Logic for generating these files is defined under `loadstone_config/src/codegen/`
        pub mod memory_map;
        pub mod pin_configuration;
        pub mod devices;

        #[allow(unused)]
        pub const SERIAL_ENABLED: bool = #serial_enabled;
        #[allow(unused)]
        pub const RECOVERY_ENABLED: bool = #recovery_enabled;
        #[allow(unused)]
        pub const BOOT_TIME_METRICS_ENABLED: bool = #boot_time_metrics_enabled;
        #[allow(unused)]
        pub const LOADSTONE_GREETING: &str = #loadstone_greeting;
        #[allow(unused)]
        pub const DEMO_APP_GREETING: &str = #demo_app_greeting;
        #[allow(unused)]
        pub const UPDATE_SIGNAL_ENABLED: bool = #update_signal_enabled;
    };

    file.write_all(format!("{}", code).as_bytes())?;
    prettify_file(filename).ok();
    Ok(())
}
/// Writes the top level autogenerated module, which includes a few boolean feature flags and
/// the module definitions of every autogenerated submodule.
Writes the top level autogenerated module, which includes a few boolean feature flags and
the module definitions of every autogenerated submodule.
Writes the top level autogenerated module which includes a few boolean feature flags and the module definitions of every autogenerated submodule .
fn generate_top_level_module<P: AsRef<Path>>(
    autogenerated_folder_path: P,
    configuration: &Configuration,
) -> Result<()> {
    let filename = autogenerated_folder_path.as_ref().join("mod.rs");
    let mut file = OpenOptions::new().write(true).create(true).truncate(true).open(&filename)?;
    let (serial_enabled, recovery_enabled) = if let Serial::Enabled { recovery_enabled, .. } =
        configuration.feature_configuration.serial
    {
        if !Serial::supported(&configuration.port) {
            panic!(
                "Serial features enabled for a port that doesn't support them: {:?}",
                configuration.port
            );
        }
        (true, recovery_enabled)
    } else {
        (false, false)
    };
    let boot_time_metrics_enabled = if let BootMetrics::Enabled { timing: true } =
        &configuration.feature_configuration.boot_metrics
    {
        if !BootMetrics::timing_supported(&configuration.port) {
            panic!(
                "Timing features enabled for a port that doesn't support them: {:?}",
                configuration.port
            );
        }
        true
    } else {
        false
    };
    let loadstone_greeting = match &configuration.feature_configuration.greetings {
        Greetings::Default => LitStr::new("-- Loadstone --", Span::call_site()),
        Greetings::Custom { loadstone,..} => LitStr::new(&loadstone, Span::call_site()),
    };
    let demo_app_greeting = match &configuration.feature_configuration.greetings {
        Greetings::Default => LitStr::new("-- Loadstone Demo App --", Span::call_site()),
        Greetings::Custom { demo,..} => LitStr::new(&demo, Span::call_site()),
    };
    let update_signal = configuration.feature_configuration.update_signal;
    let update_signal_enabled = matches!(update_signal, UpdateSignal::Enabled);
    let code = quote! {
        //! This entire module is autogenerated. Don't modify it manually!
        //! Logic for generating these files is defined under `loadstone_config/src/codegen/`
        pub mod memory_map;
        pub mod pin_configuration;
        pub mod devices;
        #[allow(unused)]
        pub const SERIAL_ENABLED: bool = #serial_enabled;
        #[allow(unused)]
        pub const RECOVERY_ENABLED: bool = #recovery_enabled;
        #[allow(unused)]
        pub const BOOT_TIME_METRICS_ENABLED: bool = #boot_time_metrics_enabled;
        #[allow(unused)]
        pub const LOADSTONE_GREETING: &str = #loadstone_greeting;
        #[allow(unused)]
        pub const DEMO_APP_GREETING: &str = #demo_app_greeting;
        #[allow(unused)]
        pub const UPDATE_SIGNAL_ENABLED: bool = #update_signal_enabled;
    };
    file.write_all(format!("{}", code).as_bytes())?;
    prettify_file(filename).ok();
    Ok(())
}
fn generate_top_level_module < P : AsRef < Path > > ( autogenerated_folder_path : P , configuration : & Configuration , ) -> Result < ( ) > { let filename = autogenerated_folder_path . as_ref ( ) . join ( " " ) ; let mut file = OpenOptions :: new ( ) . write ( true ) . create ( true ) . truncate ( true ) . open ( & filename ) ? ; let ( serial_enabled , recovery_enabled ) = if let Serial :: Enabled { recovery_enabled , .. } = configuration . feature_configuration . serial { if ! Serial :: supported ( & configuration . port ) { panic ! ( " " configuration port ) ; } ( true , recovery_enabled ) } else { ( false , false ) } ; let boot_time_metrics_enabled = if let BootMetrics :: Enabled { timing : true } = & configuration . feature_configuration . boot_metrics { if ! BootMetrics :: timing_supported ( & configuration . port ) { panic ! ( " " configuration port ) ; } true } else { false } ; let loadstone_greeting = match & configuration . feature_configuration . greetings { Greetings :: Default => LitStr :: new ( " " , Span :: call_site ( ) ) , Greetings :: Custom { loadstone , .. } => LitStr :: new ( & loadstone , Span :: call_site ( ) ) , } ; let demo_app_greeting = match & configuration . feature_configuration . greetings { Greetings :: Default => LitStr :: new ( " " , Span :: call_site ( ) ) , Greetings :: Custom { demo , .. } => LitStr :: new ( & demo , Span :: call_site ( ) ) , } ; let update_signal = configuration . feature_configuration . update_signal ; let update_signal_enabled = matches ! ( update_signal UpdateSignal Enabled ) ; let code = quote ! { //! This entire module is autogenerated. Don't modify it manually! //! Logic for generating these files is defined under `loadstone_config/src/codegen/` pub mod memory_map pub mod pin_configuration pub mod devices [ allow ( unused ) ] pub const SERIAL_ENABLED bool serial_enabled [ allow ( unused ) ] pub const RECOVERY_ENABLED bool recovery_enabled [ allow ( unused ) ] pub const BOOT_TIME_METRICS_ENABLED bool boot_time_metrics_enabled [ allow ( unused ) ] pub const LOADSTONE_GREETING str loadstone_greeting [ allow ( unused ) ] pub const DEMO_APP_GREETING str demo_app_greeting [ allow ( unused ) ] pub const UPDATE_SIGNAL_ENABLED bool update_signal_enabled } ; file . write_all ( format ! ( " " code ) . as_bytes ( ) ) ? ; prettify_file ( filename ) . ok ( ) ; Ok ( ( ) ) }
Writes the top level autogenerated module, which includes a few boolean feature flags and
the module definitions of every autogenerated submodule.
Writes the top level autogenerated module which includes a few boolean feature flags and the module definitions of every autogenerated submodule .
autogenerated_folder_path
P
configuration
&Configuration
autogenerated_folder_path
P
configuration
&Configuration