/* * SPDX-FileCopyrightText: 2021 - 2024 StorPool * SPDX-License-Identifier: BSD-2-Clause */ //! Partially-generated data for handling build variants. //! //! The data is autogenerated from the supported StorPool build variants. use std::collections::HashMap; use std::str::FromStr; use enum_iterator::Sequence; use once_cell::sync::Lazy; use serde_derive::{Deserialize, Serialize}; use crate::{ Builder, DebRepo, Detect, Repo, Supported, Variant, VariantDefTop, VariantError, VariantFormat, VariantFormatVersion, YumRepo, }; /// The supported StorPool build variants (OS distribution, version, etc). #[derive(Debug, Clone, Copy, PartialEq, Hash, Eq, Serialize, Deserialize, Sequence)] #[non_exhaustive] pub enum VariantKind { {%- for name, var in variants|dictvsort -%} /// {{ var.descr }} {{ name }}, {%- endfor -%} } impl VariantKind { {%- for name in variants|vsort -%} const {{ name }}_NAME: &'static str = "{{ name }}"; {%- endfor -%} } impl AsRef for VariantKind { #[inline] fn as_ref(&self) -> &str { match *self { {%- for name in variants|vsort -%} Self::{{ name }} => Self::{{ name }}_NAME, {%- endfor -%} } } } impl FromStr for VariantKind { type Err = VariantError; #[inline] fn from_str(value: &str) -> Result { match value { {%- for name in variants|vsort -%} Self::{{ name }}_NAME => Ok(Self::{{ name }}), {%- endfor -%} other => Err(VariantError::BadVariant(other.to_owned())), } } } /// Return the definition of the StorPool variants. #[allow(clippy::manual_string_new)] #[allow(clippy::panic)] #[allow(clippy::too_many_lines)] #[must_use] pub fn get_variants() -> &'static VariantDefTop { static DEF_TOP: Lazy = Lazy::new(|| { VariantDefTop { format: VariantFormat { version: VariantFormatVersion { major: {{ format_version[0] }}, minor: {{ format_version[1] }}, }, }, order: vec![ {%- for name in order %} VariantKind::{{name}}, {%- endfor %} ], variants: HashMap::from( [ {%- for name, var in variants|dictvsort %} ( VariantKind::{{ name }}, Variant { kind: VariantKind::{{ name }}, descr: "{{ var.descr }}".to_owned(), family: "{{ var.family }}".to_owned(), parent: "{{ var.parent }}".to_owned(), detect: Detect { filename: "{{ var.detect.filename }}".to_owned(), #[allow(clippy::needless_raw_strings)] regex: r"{{ var.detect.regex.pattern }}".to_owned(), os_id: "{{ var.detect.os_id }}".to_owned(), #[allow(clippy::needless_raw_strings)] os_version_regex: r"{{ var.detect.os_version_regex.pattern }}".to_owned(), }, supported: Supported { repo: {{ var.supported.repo|rust_bool }}, }, commands: HashMap::from( [ {%- for cat_name in var.commands._fields|sort %} ( "{{ cat_name }}".to_owned(), HashMap::from( [ {%- for cmd_name in var.commands|attr(cat_name)|attr("_fields")|sort %} ( "{{ cmd_name }}".to_owned(), vec![ {%- for word in var.commands|attr(cat_name)|attr(cmd_name) %} "{{ word|replace("\\", "\\\\")|replace('"', '\\"') }}".to_owned(), {%- endfor %} ], ), {%- endfor %} ] ), ), {%- endfor %} ] ), min_sys_python: "{{ var.min_sys_python }}".to_owned(), repo: {%- if var.family == "redhat" %} Repo::Yum(YumRepo { yumdef: "{{ var.repo.yumdef }}".to_owned(), keyring: "{{ var.repo.keyring }}".to_owned(), }), {% elif var.family == "debian" %} Repo::Deb(DebRepo { codename: "{{ var.repo.codename }}".to_owned(), vendor: "{{ var.repo.vendor }}".to_owned(), sources: "{{ var.repo.sources }}".to_owned(), keyring: "{{ var.repo.keyring }}".to_owned(), req_packages: vec![ {%- for pkg in var.repo.req_packages %} "{{ pkg }}".to_owned(), {%- endfor %} ], }), {% else %} INVALID!, {% endif -%} package: HashMap::from( [ {%- for pkg_name, pkg in var.package|dictsort %} ("{{ pkg_name }}".to_owned(), "{{ pkg }}".to_owned()), {%- endfor %} ] ), systemd_lib: "{{ var.systemd_lib }}".to_owned(), file_ext: "{{ var.file_ext }}".to_owned(), initramfs_flavor: "{{ var.initramfs_flavor }}".to_owned(), builder: Builder { alias: "{{ var.builder.alias }}".to_owned(), base_image: "{{ var.builder.base_image }}".to_owned(), branch: "{{ var.builder.branch }}".to_owned(), kernel_package: "{{ var.builder.kernel_package }}".to_owned(), utf8_locale: "{{ var.builder.utf8_locale }}".to_owned(), }, }, ), {%- endfor %} ] ), version: "{{ version }}".to_owned(), } }); assert!( DEF_TOP.format.version.major == 1, "Internal error: JSON variant definition: version {:?}", DEF_TOP.format.version ); &DEF_TOP }