From f0e568a513f3f9322ee7502b47b5cdb3f63e50eb Mon Sep 17 00:00:00 2001 From: Lleyton Gray Date: Thu, 14 Nov 2024 15:49:20 -0800 Subject: [PATCH 1/4] remove some unused stuff --- .env.example | 25 ------------------------- .env.vault | 12 ------------ .vscode/settings.json | 12 ------------ 3 files changed, 49 deletions(-) delete mode 100644 .env.example delete mode 100644 .env.vault diff --git a/.env.example b/.env.example deleted file mode 100644 index c176037..0000000 --- a/.env.example +++ /dev/null @@ -1,25 +0,0 @@ -# Listen to 0.0.0.0, so you can access the server from anywhere -ANDA_ADDRESS=0.0.0.0 -# Replace both with your actual local IP if you want to run Andaman Server on your local machine -# Because localhost is not accessible from outside the container. -# Alternatively, try and get the Docker container IP address from the host machine. -# To set up the test BuildKit server, see the justfile. -ANDA_BUILDKIT_HOST=tcp://localhost:1234 -ANDA_ENDPOINT=http://localhost:8000 - -# NOTE: This requires `anda setup` to be run first, so the BuildKit daemon runs. -BUILDKIT_HOST=docker-container://anda-buildkitd - -DATABASE_SCHEMA=anda -# We are using the default PostgreSQL creds here. -# If you're running this in production, change this or get pwned. -DATABASE_URL=postgres://postgres:example@localhost/anda - -# Default minio creds -# Change this if you want to run in production. -S3_ACCESS_KEY=minioadmin -S3_SECRET_KEY=minioadmin -S3_BUCKET=anda -# Endpoint exists because we are running minio and not Amazon S3, Needs to change this at some point for -# people who actually want the *real* S3. -S3_ENDPOINT=http://172.16.5.4:9000 diff --git a/.env.vault b/.env.vault deleted file mode 100644 index 4033b35..0000000 --- a/.env.vault +++ /dev/null @@ -1,12 +0,0 @@ -################################################################################# -# # -# This file uniquely identifies your project in dotenv-vault. # -# You SHOULD commit this file to source control. # -# # -# Generated with 'npx dotenv-vault new' # -# # -# Learn more at https://dotenv.org/env-vault # -# # -################################################################################# - -DOTENV_VAULT=vlt_287b70e2b4dfdab7420e40b43aa8d4af5fad6fd927bc5291c2295645ebaf35cd \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 3481dbd..67e46c9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,16 +1,4 @@ { - "sqltools.connections": [ - { - "previewLimit": 50, - "server": "localhost", - "port": 5432, - "driver": "PostgreSQL", - "name": "anda", - "database": "anda", - "username": "postgres", - "password": "example" - } - ], "rust-analyzer.checkOnSave.command": "clippy", "search.useGlobalIgnoreFiles": true, "files.exclude": { From 02da0cf79490e2b3f93c7cda7b10428960eb907e Mon Sep 17 00:00:00 2001 From: Lleyton Gray Date: Thu, 14 Nov 2024 15:56:48 -0800 Subject: [PATCH 2/4] remove podman, docker, oci, and flatpak --- anda-config/config.rs | 24 ------- andax/fns/cfg.rs | 33 ---------- src/builder.rs | 150 ++---------------------------------------- src/cli.rs | 47 ------------- src/flatpak.rs | 136 -------------------------------------- src/main.rs | 15 +---- src/oci.rs | 81 ----------------------- src/util.rs | 31 +-------- 8 files changed, 10 insertions(+), 507 deletions(-) delete mode 100644 src/flatpak.rs delete mode 100644 src/oci.rs diff --git a/anda-config/config.rs b/anda-config/config.rs index 5888844..665924d 100644 --- a/anda-config/config.rs +++ b/anda-config/config.rs @@ -50,9 +50,6 @@ impl Manifest { #[derive(Deserialize, PartialEq, Eq, Serialize, Debug, Clone, Default)] pub struct Project { pub rpm: Option, - pub podman: Option, - pub docker: Option, - pub flatpak: Option, pub pre_script: Option, pub post_script: Option, pub env: Option>, @@ -191,11 +188,6 @@ pub struct RpmBuild { pub opts: Option>, } -#[derive(Deserialize, PartialEq, Eq, Serialize, Debug, Clone, Default)] -pub struct Docker { - pub image: BTreeMap, // tag, file -} - pub fn parse_kv(input: &str) -> impl Iterator> + '_ { input .split(',') @@ -212,22 +204,6 @@ pub fn parse_labels<'a, I: Iterator>(labels: I) -> Option, - pub import: Option, - pub tag_latest: Option, - pub context: String, - pub version: Option, -} - -#[derive(Deserialize, PartialEq, Eq, Serialize, Debug, Clone)] -pub struct Flatpak { - pub manifest: PathBuf, - pub pre_script: Option, - pub post_script: Option, -} - /// Converts a [`Manifest`] to `String` (.hcl). /// /// # Errors diff --git a/andax/fns/cfg.rs b/andax/fns/cfg.rs index cad3620..a0a9665 100644 --- a/andax/fns/cfg.rs +++ b/andax/fns/cfg.rs @@ -28,9 +28,6 @@ pub mod ar { p.insert(name.into(), { let mut p = rhai::Map::new(); p.insert("rpm".into(), _rpm(proj.rpm)); - p.insert("podman".into(), _docker(proj.podman)); - p.insert("docker".into(), _docker(proj.docker)); - p.insert("flatpak".into(), _flatpak(proj.flatpak)); p.insert("pre_script".into(), _pb(proj.pre_script)); p.insert("post_script".into(), _pb(proj.post_script)); p.insert("env".into(), proj.env.unwrap_or_default().into()); @@ -67,33 +64,3 @@ fn _rpm(o: Option) -> Dynamic { m.into() }) } -fn _docker(o: Option) -> Dynamic { - o.map_or(().into(), |d| { - let mut m = rhai::Map::new(); - m.insert( - "image".into(), - d.image - .into_iter() - .map(|(n, i)| { - let mut a = rhai::Map::new(); - a.insert("dockerfile".into(), i.dockerfile.unwrap_or_default().into()); - a.insert("import".into(), _pb(i.import)); - a.insert("tag_latest".into(), i.tag_latest.unwrap_or(false).into()); - a.insert("context".into(), i.context.into()); - a.insert("version".into(), i.version.unwrap_or_default().into()); - (n, a) - }) - .collect(), - ); - m.into() - }) -} -fn _flatpak(o: Option) -> Dynamic { - o.map_or(().into(), |f| { - let mut m = rhai::Map::new(); - m.insert("manifest".into(), _pb(Some(f.manifest))); - m.insert("pre_script".into(), _pb(f.pre_script)); - m.insert("post_script".into(), _pb(f.post_script)); - m.into() - }) -} diff --git a/src/builder.rs b/src/builder.rs index 1b08f21..763b5a8 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,12 +1,10 @@ use crate::{ artifacts::Artifacts, - cli::{Cli, FlatpakOpts, OciOpts, PackageType, RpmOpts}, + cli::{Cli, PackageType, RpmOpts}, cmd, - flatpak::{FlatpakArtifact, FlatpakBuilder}, - oci::{build_oci, OCIBackend}, rpm_spec::{RPMBuilder, RPMExtraOptions, RPMOptions}, }; -use anda_config::{Docker, Flatpak, Project}; +use anda_config::Project; use color_eyre::{eyre::eyre, eyre::Context, Result}; use itertools::Itertools; use std::path::{Path, PathBuf}; @@ -85,44 +83,6 @@ pub async fn build_rpm( Ok(builder) } -/// Build a flatpak package. -/// -/// # Errors -/// - cannot create bundle -pub async fn build_flatpak( - output_dir: &Path, - manifest: &Path, - flatpak_opts: &mut FlatpakOpts, -) -> Result> { - let mut artifacts = Vec::new(); - - let out = output_dir.join("flatpak"); - - let flat_out = out.join("build"); - let flat_repo = out.join("repo"); - let flat_bundles = out.join("bundles"); - - let mut builder = FlatpakBuilder::new(flat_out, flat_repo, flat_bundles); - - for extra_source in &mut flatpak_opts.extra_sources { - builder.add_extra_source(PathBuf::from(std::mem::take(extra_source))); - } - - for extra_source_url in &mut flatpak_opts.extra_sources_url { - builder.add_extra_source_url(std::mem::take(extra_source_url)); - } - - if !flatpak_opts.dont_delete_build_dir { - builder.add_extra_args("--delete-build-dirs".to_owned()); - } - - let flatpak = builder.build(manifest).await?; - artifacts.push(FlatpakArtifact::Ref(flatpak.clone())); - artifacts.push(FlatpakArtifact::Bundle(builder.bundle(&flatpak).await?)); - - Ok(artifacts) -} - macro_rules! script { ($name:expr, $scr:expr, $( $var:ident ),*) => { let sc = andax::run( @@ -194,60 +154,6 @@ pub async fn build_rpm_call( Ok(()) } -pub async fn build_flatpak_call( - cli: &Cli, - flatpak: &Flatpak, - artifact_store: &mut Artifacts, - mut flatpak_opts: FlatpakOpts, -) -> Result<()> { - if let Some(pre_script) = &flatpak.pre_script { - script!( - flatpak.manifest.as_path().to_str().unwrap_or(""), - pre_script, - flatpak_opts - ); - } - - let art = build_flatpak(&cli.target_dir, &flatpak.manifest, &mut flatpak_opts).await.unwrap(); - - for artifact in art { - artifact_store.add(artifact.to_string(), PackageType::Flatpak); - } - - if let Some(post_script) = &flatpak.post_script { - script!(flatpak.manifest.as_path().to_str().unwrap_or(""), post_script,); - } - - Ok(()) -} - -pub fn build_oci_call( - backend: OCIBackend, - _cli: &Cli, - manifest: &mut Docker, - artifact_store: &mut Artifacts, -) { - let art_type = match backend { - OCIBackend::Docker => PackageType::Docker, - OCIBackend::Podman => PackageType::Podman, - }; - - for (tag, image) in std::mem::take(&mut manifest.image) { - let art = build_oci( - backend, - &image.dockerfile.unwrap(), - image.tag_latest.unwrap_or(false), - &tag, - &image.version.unwrap_or_else(|| "latest".into()), - &image.context, - ); - - for artifact in art { - artifact_store.add(artifact.clone(), art_type); - } - } -} - // project parser pub async fn build_project( @@ -255,8 +161,6 @@ pub async fn build_project( mut proj: Project, package: PackageType, rbopts: &RpmOpts, - fpopts: &FlatpakOpts, - _oci_opts: &OciOpts, ) -> Result<()> { let cwd = std::env::current_dir().unwrap(); @@ -308,14 +212,11 @@ pub async fn build_project( } let mut arts = Artifacts::new(); - _build_pkg(package, &mut proj, cli, rpm_opts, rbopts, &mut arts, fpopts).await?; + _build_pkg(package, &mut proj, cli, rpm_opts, rbopts, &mut arts).await?; for (path, arttype) in arts.packages { let type_string = match arttype { PackageType::Rpm => "RPM", - PackageType::Docker => "Docker image", - PackageType::Podman => "Podman image", - PackageType::Flatpak => "flatpak", // PackageType::RpmOstree => "rpm-ostree compose", PackageType::All => unreachable!(), }; @@ -340,10 +241,9 @@ async fn _build_pkg( rpm_opts: RPMOptions, rbopts: &RpmOpts, arts: &mut Artifacts, - fpopts: &FlatpakOpts, ) -> Result<(), color_eyre::Report> { match package { - PackageType::All => build_all(proj, cli, rpm_opts, rbopts, arts, fpopts).await?, + PackageType::All => build_all(proj, cli, rpm_opts, rbopts, arts).await?, PackageType::Rpm => { if let Some(rpmbuild) = &proj.rpm { build_rpm_call(cli, rpm_opts, rpmbuild, rbopts.rpm_builder.into(), arts, rbopts) @@ -353,28 +253,7 @@ async fn _build_pkg( println!("No RPM build defined for project"); } } - PackageType::Docker => { - proj.docker.as_mut().map_or_else( - || println!("No Docker build defined for project"), - |docker| build_oci_call(OCIBackend::Docker, cli, docker, arts), - ); - } - PackageType::Podman => { - proj.podman.as_mut().map_or_else( - || println!("No Podman build defined for project"), - |podman| build_oci_call(OCIBackend::Podman, cli, podman, arts), - ); - } - PackageType::Flatpak => { - if let Some(flatpak) = &proj.flatpak { - build_flatpak_call(cli, flatpak, arts, fpopts.clone()) - .await - .with_context(|| "Failed to build Flatpaks".to_owned())?; - } else { - println!("No Flatpak build defined for project"); - } - } // PackageType::RpmOstree => todo!(), - }; + } Ok(()) } @@ -384,24 +263,12 @@ async fn build_all( rpm_opts: RPMOptions, rbopts: &RpmOpts, artifacts: &mut Artifacts, - flatpak_opts: &FlatpakOpts, ) -> Result<(), color_eyre::Report> { if let Some(rpmbuild) = &project.rpm { build_rpm_call(cli, rpm_opts, rpmbuild, rbopts.rpm_builder.into(), artifacts, rbopts) .await .with_context(|| "Failed to build RPMs".to_owned())?; } - if let Some(flatpak) = &project.flatpak { - build_flatpak_call(cli, flatpak, artifacts, flatpak_opts.clone()) - .await - .with_context(|| "Failed to build Flatpaks".to_owned())?; - } - if let Some(podman) = project.podman.as_mut() { - build_oci_call(OCIBackend::Podman, cli, podman, artifacts); - } - if let Some(docker) = project.docker.as_mut() { - build_oci_call(OCIBackend::Docker, cli, docker, artifacts); - } if let Some(scripts) = &project.scripts { info!("Running build scripts"); crate::update::run_scripts( @@ -422,8 +289,6 @@ pub async fn builder( all: bool, project: Option, package: PackageType, - flatpak_opts: FlatpakOpts, - oci_opts: OciOpts, ) -> Result<()> { // Parse the project manifest // todo @@ -439,15 +304,14 @@ pub async fn builder( if all { for (name, project) in config.project { println!("Building project: {name}"); - build_project(cli, project, package, &rpm_opts, &flatpak_opts, &oci_opts).await?; + build_project(cli, project, package, &rpm_opts).await?; } } else { // find project named project if let Some(name) = project { if let Some(project) = config.get_project(&name) { // cannot take: get_project() returns immut ref - build_project(cli, project.clone(), package, &rpm_opts, &flatpak_opts, &oci_opts) - .await?; + build_project(cli, project.clone(), package, &rpm_opts).await?; } else { return Err(eyre!("Project not found: {name}")); } diff --git a/src/cli.rs b/src/cli.rs index 12a5239..db47a39 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -16,10 +16,6 @@ pub enum RPMBuilder { #[derive(Copy, Clone, ValueEnum, Debug)] pub enum PackageType { Rpm, - Docker, - Podman, - Flatpak, - // RpmOstree, All, } @@ -29,9 +25,6 @@ impl FromStr for PackageType { fn from_str(s: &str) -> Result { match s { "rpm" => Ok(Self::Rpm), - "docker" => Ok(Self::Docker), - "podman" => Ok(Self::Podman), - "flatpak" => Ok(Self::Flatpak), // "rpm-ostree" => Ok(Self::RpmOstree), "all" => Ok(Self::All), _ => Err(format!("Invalid package type: {s}")), @@ -67,38 +60,6 @@ pub struct Cli { pub target_dir: PathBuf, } -#[derive(Args, Debug, Clone, Default)] -pub struct FlatpakOpts { - /// Flatpak: Extra source directory - /// can be defined multiple times - #[clap(long, group = "extra-source")] - pub extra_sources: Vec, - - /// Flatpak: Extra source URL - /// can be defined multiple times - #[clap(long)] - pub extra_sources_url: Vec, - - /// Flatpak: Do not delete the build directory - #[clap(long, action)] - pub dont_delete_build_dir: bool, -} - -#[derive(Args, Debug, Clone, Default)] -pub struct OciOpts { - /// OCI: Labels to add to the image - #[clap(long)] - pub label: Vec, - - /// OCI: Build Arguments to pass to the build - #[clap(long)] - pub build_arg: Vec, - - /// OCI: compress the context with gzip - #[clap(long, action)] - pub compress: bool, -} - #[derive(Args, Debug, Clone, Default)] pub struct RpmOpts { /// RPM: Do not mirror repositories. @@ -159,14 +120,6 @@ pub enum Command { /// Options for RPM builds #[clap(flatten)] rpm_opts: RpmOpts, - - /// Options for Flatpak builds - #[clap(flatten)] - flatpak_opts: FlatpakOpts, - - /// Options for OCI builds - #[clap(flatten)] - oci_opts: OciOpts, }, /// Cleans up the build directory Clean, diff --git a/src/flatpak.rs b/src/flatpak.rs deleted file mode 100644 index 47af3bb..0000000 --- a/src/flatpak.rs +++ /dev/null @@ -1,136 +0,0 @@ -#![allow(dead_code)] -use crate::util::CommandLog; -use color_eyre::Report; -use flatpak::application::FlatpakApplication; -use std::{ - env, - fmt::Display, - path::{Path, PathBuf}, -}; -use tokio::process::Command; -type Result = std::result::Result; - -pub enum FlatpakArtifact { - Ref(String), - Bundle(PathBuf), -} - -impl Display for FlatpakArtifact { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::Ref(r) => write!(f, "ref {r}"), - Self::Bundle(b) => write!(f, "bundle {}", b.display()), - } - } -} - -pub struct FlatpakBuilder { - // The output directory for the flatpak build - output_dir: PathBuf, - // The output flatpak repository - output_repo: PathBuf, - - // The bundles directory - bundles_dir: PathBuf, - // Extra sources as paths - extra_sources: Vec, - // Extra sources as URLs - extra_sources_urls: Vec, - // extra arguments to pass to flatpak-builder - extra_args: Vec, -} - -impl FlatpakBuilder { - pub const fn new(output_dir: PathBuf, output_repo: PathBuf, bundles_dir: PathBuf) -> Self { - Self { - output_dir, - output_repo, - bundles_dir, - extra_sources: Vec::new(), - extra_sources_urls: Vec::new(), - extra_args: Vec::new(), - } - } - - pub fn add_extra_source(&mut self, source: PathBuf) { - self.extra_sources.push(source); - } - // Add extra sources from an iterator - pub fn extra_sources_iter>(&mut self, iter: I) { - self.extra_sources.extend(iter); - } - - pub fn extra_args_iter>(&mut self, iter: I) { - self.extra_args.extend(iter); - } - - pub fn add_extra_args(&mut self, arg: String) { - self.extra_args.push(arg); - } - - pub fn add_extra_source_url(&mut self, source: String) { - self.extra_sources_urls.push(source); - } - - // Add extra sources from an iterator - pub fn extra_sources_urls_iter>(&mut self, iter: I) { - self.extra_sources_urls.extend(iter); - } - - pub async fn build(&self, manifest: &Path) -> Result { - // we parse the flatpak metadata file - let flatpak_meta = FlatpakApplication::load_from_file(manifest.display().to_string()) - .map_err(color_eyre::Report::msg)?; - - // create the flatpak output folders - let output_dir = - env::current_dir()?.join(".flatpak-builder/build").join(&flatpak_meta.app_id); - std::fs::create_dir_all(&output_dir)?; - std::fs::create_dir_all(&self.output_repo)?; - - // build the flatpak - let mut flatpak = Command::new("flatpak-builder"); - flatpak - .arg(output_dir) - .arg(manifest) - .arg("--force-clean") - .arg("--repo") - .arg(self.output_repo.canonicalize().unwrap()); - - // add extra sources - - for source in &self.extra_sources { - flatpak.arg("--extra-sources").arg(source); - } - - for source in &self.extra_sources_urls { - flatpak.arg("--extra-sources-url").arg(source); - } - - flatpak.args(&self.extra_args); - - // run the command - flatpak.log().await?; - Ok(flatpak_meta.app_id) - } - - pub async fn bundle(&self, app_id: &str) -> Result { - std::fs::create_dir_all(&self.bundles_dir)?; - let bundle_path = self.bundles_dir.join(format!("{app_id}.flatpak")); - - let mut flatpak = Command::new("flatpak"); - - flatpak - .arg("build-bundle") - .arg(self.output_repo.canonicalize().unwrap()) - .arg(&bundle_path) - .arg(app_id); - - flatpak.log().await?; - - Ok(bundle_path) - } -} - -#[cfg(test)] -mod test_super {} diff --git a/src/main.rs b/src/main.rs index d0fa306..82a229b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,6 @@ mod artifacts; mod builder; mod cli; -mod flatpak; -mod oci; mod rpm_spec; mod update; mod util; @@ -37,14 +35,7 @@ async fn main() -> Result<()> { trace!("Matching subcommand"); match cli.command { - Command::Build { - all, - ref mut project, - ref mut package, - ref mut rpm_opts, - ref mut flatpak_opts, - ref mut oci_opts, - } => { + Command::Build { all, ref mut project, ref mut package, ref mut rpm_opts } => { if project.is_none() && !all { // print help let mut app = Cli::command(); @@ -56,11 +47,9 @@ async fn main() -> Result<()> { let project = take(project); let package = std::mem::replace(package, cli::PackageType::Rpm); - let flatpak_opts = take(flatpak_opts); - let oci_opts = take(oci_opts); let rpm_opts = take(rpm_opts); debug!("{all:?}"); - builder::builder(&cli, rpm_opts, all, project, package, flatpak_opts, oci_opts).await?; + builder::builder(&cli, rpm_opts, all, project, package).await?; } Command::Clean => { println!("Cleaning up build directory"); diff --git a/src/oci.rs b/src/oci.rs deleted file mode 100644 index 623c770..0000000 --- a/src/oci.rs +++ /dev/null @@ -1,81 +0,0 @@ -//! OCI Builder backend -//! Supports Docker and Podman -use std::process::Command; - -#[derive(Clone, Copy)] -pub enum OCIBackend { - Docker, - Podman, -} - -impl OCIBackend { - pub fn command(self) -> Command { - let cmd = match self { - Self::Docker => "docker", - Self::Podman => "podman", - }; - - Command::new(cmd) - } -} - -pub struct OCIBuilder { - context: String, - tag: String, - version: String, - label: Vec, -} - -impl OCIBuilder { - pub const fn new(context: String, tag: String, version: String) -> Self { - Self { context, tag, version, label: Vec::new() } - } - - pub fn add_label(&mut self, label: String) { - self.label.push(label); - } - - // We use string here because we want to let people use stuff like git contexts - pub fn build(&self, dockerfile: &str, backend: OCIBackend, latest: bool) { - let mut cmd = backend.command(); - - let real_tag = &format!("{}:{}", &self.tag, self.version); - - cmd.arg("build") - .arg(&self.context) - .arg("-f") - .arg(dockerfile) - .arg("-t") - .env("DOCKER_BUILDKIT", "1") - .arg(real_tag); - - if latest { - cmd.arg("-t").arg(format!("{}:latest", &self.tag)); - } - - for label in &self.label { - cmd.arg("--label").arg(label); - } - } -} - -pub fn build_oci( - backend: OCIBackend, - dockerfile: &str, - latest: bool, - tag: &str, - version: &str, - context: &str, -) -> Vec { - let mut builder = OCIBuilder::new(context.to_owned(), tag.to_owned(), version.to_owned()); - builder.add_label(format!("com.fyralabs.anda.version={}", env!("CARGO_PKG_VERSION"))); - - builder.build(dockerfile, backend, latest); - - let mut tags = vec![format!("{tag}:{version}")]; - - if latest { - tags.push(format!("{tag}:latest")); - } - tags -} diff --git a/src/util.rs b/src/util.rs index 569fb7e..daf48ce 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,5 +1,5 @@ //! Utility functions and types -use anda_config::{Docker, DockerImage, Manifest, Project, RpmBuild}; +use anda_config::{Manifest, Project, RpmBuild}; use clap_verbosity_flag::LevelFilter; use color_eyre::{eyre::eyre, Result, Section}; use console::style; @@ -279,10 +279,6 @@ pub fn init(path: &Path, yes: bool) -> Result<()> { config.project.insert(project_name.to_owned(), project); } } - b"dockerfile" => add_dockerfile_to_manifest(yes, path, &mut config)?, - _ if path.file_name().is_some_and(|f| f.eq("Dockerfile")) => { - add_dockerfile_to_manifest(yes, path, &mut config)?; - } _ => {} } } @@ -291,31 +287,6 @@ pub fn init(path: &Path, yes: bool) -> Result<()> { Ok(()) } -fn add_dockerfile_to_manifest( - yes: bool, - path: &Path, - config: &mut Manifest, -) -> Result<(), color_eyre::eyre::Error> { - let add_oci = - yes || prompt_default(format!("Add Dockerfile `{}` to manifest?", path.display()), true)?; - if add_oci { - // create a new project called docker - - let mut docker = Docker::default(); - - let image = - DockerImage { dockerfile: Some(path.display().to_string()), ..Default::default() }; - let image_name = "docker-1".to_owned(); - docker.image.insert(image_name, image); - - let project = Project { docker: Some(docker), ..Default::default() }; - - // increment counter - config.project.insert("docker".to_owned(), project); - }; - Ok(()) -} - pub const fn convert_filter(filter: LevelFilter) -> tracing_subscriber::filter::LevelFilter { match filter { LevelFilter::Off => tracing_subscriber::filter::LevelFilter::OFF, From 03362ff42549a9a91f69129f95aecc0b7c3a5b81 Mon Sep 17 00:00:00 2001 From: madonuko Date: Fri, 15 Nov 2024 15:06:13 +0800 Subject: [PATCH 3/4] chore: this should not be a library --- Cargo.lock | 33 --------------------------------- Cargo.toml | 3 +-- src/lib.rs | 1 - 3 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index a93f5ff..a00b803 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,7 +59,6 @@ dependencies = [ "clap_complete", "color-eyre", "console", - "flatpak", "git2", "ignore", "itertools", @@ -642,19 +641,6 @@ dependencies = [ "miniz_oxide 0.8.0", ] -[[package]] -name = "flatpak" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af4672ead286a68c98546a667729b6906099d1fb95f4a6dfa43e07f1f5b60759" -dependencies = [ - "lazy_static", - "regex", - "serde", - "serde_json", - "serde_yaml", -] - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1484,19 +1470,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - [[package]] name = "sha2" version = "0.10.8" @@ -1809,12 +1782,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - [[package]] name = "untrusted" version = "0.9.0" diff --git a/Cargo.toml b/Cargo.toml index 726bb4f..1cdc765 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ description = "Andaman Build toolchain" license = "MIT" repository = "https://github.com/FyraLabs/anda" readme = "README.md" -keywords = ["build", "toolchain", "rpm", "flatpak", "oci"] +keywords = ["build", "toolchain", "rpm"] exclude = [ "anda-build", "anda-config", @@ -29,7 +29,6 @@ walkdir = "2.5.0" tempfile = "3.14.0" anda-config = { workspace = true } andax = { path = "./andax", version = "0.3.1" } -flatpak = "0.18.1" clap-verbosity-flag = "2.2.2" tokio = { version = "1.41.1", features = [ "process", diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 4f77372..0000000 --- a/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod cli; From 22a85aa2c9f3fe9c9e7f2af00ef7a75e1c2cf413 Mon Sep 17 00:00:00 2001 From: madonuko Date: Fri, 15 Nov 2024 15:19:02 +0800 Subject: [PATCH 4/4] gigantic dead code purging --- src/builder.rs | 15 ++++--- src/lib.rs | 1 + src/rpm_spec.rs | 109 +--------------------------------------------- src/util.rs | 28 +++++------- xtask/src/main.rs | 4 +- 5 files changed, 25 insertions(+), 132 deletions(-) create mode 100644 src/lib.rs diff --git a/src/builder.rs b/src/builder.rs index 763b5a8..24ed7a4 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -158,13 +158,18 @@ pub async fn build_rpm_call( pub async fn build_project( cli: &Cli, - mut proj: Project, + proj: Project, package: PackageType, rbopts: &RpmOpts, ) -> Result<()> { let cwd = std::env::current_dir().unwrap(); - let mut rpm_opts = RPMOptions::new(rbopts.mock_config.clone(), cwd, cli.target_dir.clone()); + let mut rpm_opts = RPMOptions { + mock_config: rbopts.mock_config.clone(), + sources: cwd, + resultdir: cli.target_dir.clone(), + ..RPMOptions::default() + }; // export environment variables if let Some(env) = proj.env.as_ref() { @@ -212,7 +217,7 @@ pub async fn build_project( } let mut arts = Artifacts::new(); - _build_pkg(package, &mut proj, cli, rpm_opts, rbopts, &mut arts).await?; + _build_pkg(package, &proj, cli, rpm_opts, rbopts, &mut arts).await?; for (path, arttype) in arts.packages { let type_string = match arttype { @@ -236,7 +241,7 @@ pub async fn build_project( async fn _build_pkg( package: PackageType, - proj: &mut Project, + proj: &Project, cli: &Cli, rpm_opts: RPMOptions, rbopts: &RpmOpts, @@ -258,7 +263,7 @@ async fn _build_pkg( } async fn build_all( - project: &mut Project, + project: &Project, cli: &Cli, rpm_opts: RPMOptions, rbopts: &RpmOpts, diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..4f77372 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod cli; diff --git a/src/rpm_spec.rs b/src/rpm_spec.rs index 8a0c696..b029ab2 100644 --- a/src/rpm_spec.rs +++ b/src/rpm_spec.rs @@ -2,8 +2,6 @@ //! This modules provides the RPM spec builder backend, which builds RPMs //! from a spec file. -#![allow(dead_code)] - use clap::clap_derive::ValueEnum; use tempfile::TempDir; @@ -16,7 +14,7 @@ use std::{collections::BTreeMap, str::FromStr}; use tokio::process::Command; use tracing::{debug, info}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct RPMOptions { /// Mock config, only used if backend is mock pub mock_config: Option, @@ -48,53 +46,13 @@ pub struct RPMOptions { pub plugin_opts: Vec, } -impl RPMOptions { - pub const fn new(mock_config: Option, sources: PathBuf, resultdir: PathBuf) -> Self { - Self { - mock_config, - with: Vec::new(), - without: Vec::new(), - target: None, - sources, - resultdir, - extra_repos: None, - no_mirror: false, - macros: BTreeMap::new(), - config_opts: Vec::new(), - scm_enable: false, - scm_opts: Vec::new(), - plugin_opts: Vec::new(), - } - } - pub fn add_extra_repo(&mut self, repo: String) { - if let Some(ref mut repos) = self.extra_repos { - repos.push(repo); - } else { - self.extra_repos = Some(vec![repo]); - } - } - - pub fn no_mirror(&mut self, no_mirror: bool) { - self.no_mirror = no_mirror; - } -} - impl RPMExtraOptions for RPMOptions { - fn with_flags(&self) -> Vec { - self.with.clone() - } fn with_flags_mut(&mut self) -> &mut Vec { &mut self.with } - fn without_flags(&self) -> Vec { - self.without.clone() - } fn without_flags_mut(&mut self) -> &mut Vec { &mut self.without } - fn macros(&self) -> BTreeMap { - self.macros.clone() - } fn macros_mut(&mut self) -> &mut BTreeMap { &mut self.macros } @@ -188,8 +146,6 @@ pub trait RPMSpecBackend { } pub trait RPMExtraOptions { - /// Lists all macros - fn macros(&self) -> BTreeMap; /// Returns macros as a mutable reference /// This is useful for advanced macro manipulation fn macros_mut(&mut self) -> &mut BTreeMap; @@ -197,53 +153,16 @@ pub trait RPMExtraOptions { /// Set target, used for cross-compile fn set_target(&mut self, target: Option); - /// Adds a list of macros from an iterator - fn macros_iter(&mut self, iter: I) - where - I: IntoIterator, - { - self.macros_mut().extend(iter); - } - /// Defines a macro fn def_macro(&mut self, name: &str, value: &str) { self.macros_mut().insert(name.to_owned(), value.to_owned()); } - /// Undefines a macro - fn undef_macro(&mut self, name: &str) { - self.macros_mut().remove(name); - } - - // Configuration flags - // === with flags === - /// Returns a list of `with` flags - fn with_flags(&self) -> Vec; /// Returns a mutable reference to the `with` flags fn with_flags_mut(&mut self) -> &mut Vec; - /// Sets a `with` flag for the build from an iterator - fn with_flags_iter(&mut self, iter: I) - where - I: IntoIterator, - { - self.with_flags_mut().extend(iter); - } - - // === without flags === - /// Returns a list of `without` flags - fn without_flags(&self) -> Vec; - /// Returns a mutable reference to the `without` flags fn without_flags_mut(&mut self) -> &mut Vec; - - /// Sets a `without` flag for the build from an iterator - fn without_flags_iter(&mut self, iter: I) - where - I: IntoIterator, - { - self.without_flags_mut().extend(iter); - } } /// An RPM spec backend that uses Mock to build RPMs @@ -264,21 +183,12 @@ pub struct MockBackend { } impl RPMExtraOptions for MockBackend { - fn with_flags(&self) -> Vec { - self.with.clone() - } fn with_flags_mut(&mut self) -> &mut Vec { &mut self.with } - fn without_flags(&self) -> Vec { - self.without.clone() - } fn without_flags_mut(&mut self) -> &mut Vec { &mut self.without } - fn macros(&self) -> BTreeMap { - self.macros.clone() - } fn macros_mut(&mut self) -> &mut BTreeMap { &mut self.macros } @@ -310,10 +220,6 @@ impl MockBackend { self.config_opts.extend(opts); } - pub fn add_config_opt(&mut self, opt: String) { - self.config_opts.push(opt); - } - pub fn add_extra_repo(&mut self, repo: String) { self.extra_repos.push(repo); } @@ -329,10 +235,6 @@ impl MockBackend { self.scm_opts.extend(opts); } - pub fn add_scm_opt(&mut self, opt: String) { - self.scm_opts.push(opt); - } - pub fn plugin_opts(&mut self, opts: Vec) { self.plugin_opts.extend(opts); } @@ -486,21 +388,12 @@ pub struct RPMBuildBackend { } impl RPMExtraOptions for RPMBuildBackend { - fn with_flags(&self) -> Vec { - self.with.clone() - } fn with_flags_mut(&mut self) -> &mut Vec { &mut self.with } - fn without_flags(&self) -> Vec { - self.without.clone() - } fn without_flags_mut(&mut self) -> &mut Vec { &mut self.without } - fn macros(&self) -> BTreeMap { - self.macros.clone() - } fn macros_mut(&mut self) -> &mut BTreeMap { &mut self.macros } diff --git a/src/util.rs b/src/util.rs index daf48ce..9c900a9 100644 --- a/src/util.rs +++ b/src/util.rs @@ -262,24 +262,18 @@ pub fn init(path: &Path, yes: bool) -> Result<()> { continue; } - match path.extension().unwrap_or_default().as_encoded_bytes() { - b"spec" => { - debug!("Found spec file: {}", path.display()); - if yes - || prompt_default( - format!("Add spec file `{}` to manifest?", path.display()), - true, - )? - { - let project_name = path.file_stem().unwrap().to_str().unwrap(); - let project = Project { - rpm: Some(RpmBuild { spec: path.to_path_buf(), ..Default::default() }), - ..Default::default() - }; - config.project.insert(project_name.to_owned(), project); - } + if path.extension().unwrap_or_default().as_encoded_bytes() == b"spec" { + debug!("Found spec file: {}", path.display()); + if yes + || prompt_default(format!("Add spec file `{}` to manifest?", path.display()), true)? + { + let project_name = path.file_stem().unwrap().to_str().unwrap(); + let project = Project { + rpm: Some(RpmBuild { spec: path.to_path_buf(), ..Default::default() }), + ..Default::default() + }; + config.project.insert(project_name.to_owned(), project); } - _ => {} } } println!("{}", anda_config::config::to_string(&config)?); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 476751d..ea11624 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,6 +1,6 @@ use anda::cli::Cli; use anyhow::Result; -use clap::{Command, CommandFactory}; +use clap::CommandFactory; use clap_complete::{generate_to, shells::Shell}; use std::env; use std::fs::create_dir_all; @@ -29,7 +29,7 @@ completion builds shell completions } /// WARN: Consumes subcommands -fn gen_manpage(cmd: Rc, man_dir: &Path) { +fn gen_manpage(cmd: Rc, man_dir: &Path) { let name = cmd .get_display_name() .map(|s| s.to_string())