From de54c213eb28da915526f5ac5dc995329b664d47 Mon Sep 17 00:00:00 2001 From: Cappy Ishihara Date: Thu, 10 Oct 2024 12:57:13 +0700 Subject: [PATCH] noop out more code, proper-ish parsing? --- src/cfg/manifest.rs | 181 ------------ src/cfg/manifest/mod.rs | 259 +++++++++++++++++ src/cfg/mod.rs | 2 +- src/cfg/script.rs | 4 + src/main.rs | 30 +- tests/main.katsu.hcl | 261 ++---------------- tests/ng/.gitignore | 1 - tests/ng/katsu-arm.yaml | 32 --- tests/ng/katsu-iso-limine.yaml | 29 -- tests/ng/katsu-iso.yaml | 28 -- tests/ng/katsu-script-test.yaml | 12 - tests/ng/katsu.yaml | 38 --- tests/ng/modules/base.yaml | 80 ------ tests/ng/modules/live-image/live.yaml | 12 - tests/ng/modules/live-image/liveimage.sh | 5 - .../repodir/fedora-cisco-openh264.repo | 22 -- tests/ng/modules/repodir/fedora-updates.repo | 36 --- tests/ng/modules/repodir/fedora.repo | 36 --- .../repodir/rpmfusion-free-tainted.repo | 33 --- .../repodir/rpmfusion-free-updates.repo | 31 --- tests/ng/modules/repodir/rpmfusion-free.repo | 33 --- .../repodir/rpmfusion-nonfree-tainted.repo | 33 --- .../repodir/rpmfusion-nonfree-updates.repo | 31 --- .../ng/modules/repodir/rpmfusion-nonfree.repo | 34 --- tests/ng/modules/repodir/terra.repo | 11 - tests/ng/modules/repodir/ultramarine.repo | 11 - tests/ng/modules/scripts/grub-install.sh | 40 --- tests/ng/modules/scripts/image-cleanup.sh | 46 --- tests/ng/modules/scripts/pre-test2.sh | 37 --- tests/ng/modules/scripts/selinux.sh | 6 - tests/ng/modules/tests.yaml | 9 - tests/ng/recurse/manifest.yaml | 9 - tests/ng/recurse/recurse1.yaml | 12 - tests/ng/recurse/recurse2.yaml | 8 - tests/pkglist.katsu.hcl | 13 + tests/{test.katsu.hcl => reference.katsu.hcl} | 9 +- 36 files changed, 321 insertions(+), 1153 deletions(-) delete mode 100644 src/cfg/manifest.rs create mode 100644 src/cfg/manifest/mod.rs delete mode 100644 tests/ng/.gitignore delete mode 100644 tests/ng/katsu-arm.yaml delete mode 100644 tests/ng/katsu-iso-limine.yaml delete mode 100644 tests/ng/katsu-iso.yaml delete mode 100644 tests/ng/katsu-script-test.yaml delete mode 100644 tests/ng/katsu.yaml delete mode 100644 tests/ng/modules/base.yaml delete mode 100644 tests/ng/modules/live-image/live.yaml delete mode 100644 tests/ng/modules/live-image/liveimage.sh delete mode 100644 tests/ng/modules/repodir/fedora-cisco-openh264.repo delete mode 100644 tests/ng/modules/repodir/fedora-updates.repo delete mode 100644 tests/ng/modules/repodir/fedora.repo delete mode 100644 tests/ng/modules/repodir/rpmfusion-free-tainted.repo delete mode 100644 tests/ng/modules/repodir/rpmfusion-free-updates.repo delete mode 100644 tests/ng/modules/repodir/rpmfusion-free.repo delete mode 100644 tests/ng/modules/repodir/rpmfusion-nonfree-tainted.repo delete mode 100644 tests/ng/modules/repodir/rpmfusion-nonfree-updates.repo delete mode 100644 tests/ng/modules/repodir/rpmfusion-nonfree.repo delete mode 100644 tests/ng/modules/repodir/terra.repo delete mode 100644 tests/ng/modules/repodir/ultramarine.repo delete mode 100644 tests/ng/modules/scripts/grub-install.sh delete mode 100644 tests/ng/modules/scripts/image-cleanup.sh delete mode 100644 tests/ng/modules/scripts/pre-test2.sh delete mode 100644 tests/ng/modules/scripts/selinux.sh delete mode 100644 tests/ng/modules/tests.yaml delete mode 100644 tests/ng/recurse/manifest.yaml delete mode 100644 tests/ng/recurse/recurse1.yaml delete mode 100644 tests/ng/recurse/recurse2.yaml create mode 100644 tests/pkglist.katsu.hcl rename tests/{test.katsu.hcl => reference.katsu.hcl} (98%) diff --git a/src/cfg/manifest.rs b/src/cfg/manifest.rs deleted file mode 100644 index 7e126ab..0000000 --- a/src/cfg/manifest.rs +++ /dev/null @@ -1,181 +0,0 @@ -use std::{fmt::Debug, path::Path}; - -use bytesize::ByteSize; -use serde::{Deserialize, Serialize}; - -use super::{partition::PartitionType, script::Script}; - -const DEFAULT_VOLID: &str = "KATSU-LIVEOS"; - -fn _default_volid() -> String { - DEFAULT_VOLID.to_owned() -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -pub struct IsoConfig { - /// Volume ID for the ISO image - #[serde(default = "_default_volid")] - pub volume_id: String, -} - -#[derive(Default, Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "kebab-case")] -pub enum BuilderType { - #[default] - Dnf, -} - -pub trait BootstrapOption: Debug + dyn_clone::DynClone { - fn bootstrap_system(&self) -> color_eyre::Result<()>; -} - -mod bootstrap_option_serde { - use super::BootstrapOption; - - pub fn serialize<'se, S>( - bootstrap_option: &Box, serializer: S, - ) -> Result - where - S: serde::Serializer, - { - todo!() - } -} - -dyn_clone::clone_trait_object!(BootstrapOption); - -// todo: rewrite everything -#[derive(Deserialize, Debug, Clone, Serialize)] -pub struct Manifest { - /// Builder type - #[serde(default)] - pub builder: BuilderType, - /// The distro name for the build result - // entrypoint must have a distro name - #[serde(default)] - pub distro: Option, - - /// Output file name - // entrypoint must have an output location - #[serde(default)] - pub out_file: Option, - - #[serde(default)] - pub disk: Option, - - /// DNF configuration - // todo: dynamically load this? - #[serde(default)] - pub dnf: crate::builder::DnfRootBuilder, - - /// Scripts to run before and after the build - #[serde(default)] - pub scripts: super::script::ScriptsManifest, - - /// Users to add to the image - #[serde(default)] - pub users: Vec, - - /// Extra parameters to the kernel command line in bootloader configs - pub kernel_cmdline: Option, - - /// ISO config (optional) - /// This is only used for ISO images - #[serde(default)] - pub iso: Option, - - #[serde(default)] - pub bootloader: super::boot::Bootloader, -} - -impl Manifest { - #[must_use] - pub fn get_volid(&self) -> &str { - self.iso.as_ref().map_or(DEFAULT_VOLID, |iso| &iso.volume_id) - } - /// Load manifest from file - /// - /// # Errors - /// - /// This function will return an error if the file cannot be read or parsed. - pub fn load(path: &Path) -> color_eyre::Result { - Ok(hcl::de::from_body(ensan::parse(std::fs::read_to_string(path)?)?)?) - } -} - -/// Variable types used for validation in `[Var]` -#[derive(Deserialize, Debug, Clone, Serialize)] -pub enum VarType { - String, - Int, - Object, -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -pub struct Var { - #[serde(rename = "type")] - pub var_type: VarType, - pub default: Option, -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -pub enum BootstrapMethod { - Oci, - Tar, - Dir, - Squashfs, - Dnf, -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -#[serde(rename_all = "snake_case")] -#[serde(tag = "type")] -pub struct PartitionLayout { - // pub partition: Vec, -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -pub struct Partition { - pub size: ByteSize, - pub mountpoint: String, - pub filesystem: String, - #[serde(rename = "type")] - pub partition_type: PartitionType, - pub copy_blocks: Option, -} - -#[derive(Deserialize, Debug, Clone, Serialize)] -pub struct CopyFiles { - pub source: String, - pub destination: String, -} - -/// A Katsu target -/// -/// Represented by a HCL block `target` -/// -/// ```hcl -/// output "type" "id" { -/// method = "oci" -/// } -/// ``` -// todo: evaluate dep graph for outputs, so we can build them in the correct order -#[derive(Debug, Clone, Serialize)] -#[serde(tag = "type")] -// an output can be a filesystem, a container image, or a disk image. -// It can also rely on other outputs for bootstrapping. -pub struct Target { - pub id: String, - /// Method to bootstrap the output filesystem - pub method: BootstrapMethod, - /// Copy files from the host to the output tree before packing - pub copy: Vec, - /// Scripts to run before and after the build - pub script: Vec