diff --git a/backend/aurcache/src/builder/build.rs b/backend/aurcache/src/builder/build.rs index c52a7153..07d7f575 100644 --- a/backend/aurcache/src/builder/build.rs +++ b/backend/aurcache/src/builder/build.rs @@ -84,7 +84,7 @@ impl Builder { ); let pkgname = self.package_model.name.get()?; - let host_active_build_path = create_active_build_path(pkgname.to_string())?; + let host_active_build_path = create_active_build_path(pkgname)?; let create_info = self .create_build_container(target_platform, BUILDER_IMAGE) @@ -139,7 +139,7 @@ impl Builder { "Build {}: Remove shared build folder", self.build_model.id.get()? ); - fs::remove_dir(host_active_build_path)?; + fs::remove_dir_all(host_active_build_path)?; Ok(()) } @@ -266,7 +266,7 @@ impl Builder { /// move built files from build container to host and add them to the repo async fn move_and_add_pkgs(&self, host_build_path: PathBuf) -> anyhow::Result<()> { - let archive_paths = fs::read_dir(host_build_path.clone())?.collect::>(); + let archive_paths: Vec<_> = fs::read_dir(&host_build_path)?.collect::>()?; if archive_paths.is_empty() { bail!("No files found in build directory"); } @@ -299,18 +299,23 @@ impl Builder { } for archive in archive_paths { - let archive = archive?; let archive_name = archive .file_name() .to_str() .ok_or(anyhow!("Failed to get string from filename"))? .to_string(); + + // Archives could end in .tar, .tar.zst, .tar.lz4, ... + if !archive_name.contains(".pkg.tar") { + continue; + } + let pkg_path = format!( "./repo/{}/{}", self.build_model.platform.get()?, archive_name ); - fs::copy(archive.path(), pkg_path.clone())?; + fs::copy(archive.path(), &pkg_path)?; // remove old file from shared path fs::remove_file(archive.path())?; diff --git a/backend/aurcache/src/builder/docker.rs b/backend/aurcache/src/builder/docker.rs index 9200df50..25c62430 100644 --- a/backend/aurcache/src/builder/docker.rs +++ b/backend/aurcache/src/builder/docker.rs @@ -120,12 +120,12 @@ impl Builder { let build_flags = self.package_model.build_flags.get()?.split(";").join(" "); // create new docker container for current build - let build_dir_base = "/var/cache/makepkg/pkg"; - let host_build_path_docker = match get_build_mode() { + let host_build_dir = match get_build_mode() { BuildMode::DinD(cfg) => cfg.aurcache_build_path, BuildMode::Host(cfg) => cfg.build_artifact_dir_host, }; - let mountpoints = vec![format!("{}:{}", host_build_path_docker, build_dir_base)]; + let container_build_dir = "/build"; + let mountpoints = vec![format!("{}/{name}:{}", host_build_dir, container_build_dir)]; let mut mounts = vec![]; @@ -176,13 +176,22 @@ impl Builder { mounts.push(mnt); } - let (makepkg_config, makepkg_config_path) = - create_makepkg_config(name.clone(), build_dir_base)?; + let (makepkg_config, makepkg_config_path) = create_makepkg_config(container_build_dir)?; + + // Note that `paru -G {name}` will download the pkgbase of {name}, + // which might be a different name if it's a split package. let build_cmd = format!( - "sudo pacman-key --init && sudo pacman-key --populate archlinux && paru {build_flags} {name}" + " + cd {container_build_dir} + paru -G {name} + paru {build_flags} * + " ); info!("Build command: {build_cmd}"); - let cmd = format!("cat < {makepkg_config_path}\n{makepkg_config}\nEOF\n{build_cmd}"); + let cmd = format!( + "cat < {makepkg_config_path}\n{makepkg_config}\nEOF + {build_cmd}" + ); let (cpu_limit, memory_limit) = limits_from_env(); @@ -191,23 +200,16 @@ impl Builder { let build_id = self.build_model.id.get()?; let container_name = format!("aurcache_build_{filtered_name}_{build_id}"); + let auto_remove = cfg!(not(debug_assertions)); let conf = ContainerCreateBody { image: Some(image_name.to_string()), attach_stdout: Some(true), attach_stderr: Some(true), open_stdin: Some(false), user: Some("ab".to_string()), - cmd: Some(vec![ - "sh".to_string(), - "-l".to_string(), - "-c".to_string(), - cmd, - ]), + cmd: Some(vec!["sh".to_string(), "-lec".to_string(), cmd]), host_config: Some(HostConfig { - #[cfg(debug_assertions)] - auto_remove: Some(false), - #[cfg(not(debug_assertions))] - auto_remove: Some(true), + auto_remove: Some(auto_remove), nano_cpus: Some(cpu_limit as i64), memory_swap: Some(memory_limit), binds: Some(mountpoints), diff --git a/backend/aurcache/src/builder/makepkg_utils.rs b/backend/aurcache/src/builder/makepkg_utils.rs index 762eee8e..33ac116e 100644 --- a/backend/aurcache/src/builder/makepkg_utils.rs +++ b/backend/aurcache/src/builder/makepkg_utils.rs @@ -1,11 +1,9 @@ -pub fn create_makepkg_config( - name: String, - build_dir_base: &str, -) -> anyhow::Result<(String, String)> { +pub fn create_makepkg_config(build_dir_base: &str) -> anyhow::Result<(String, String)> { let makepkg_config = format!( - "\ + " MAKEFLAGS=-j$(nproc) -PKGDEST={build_dir_base}/{name}" +PKGDEST={build_dir_base} + " ); let makepkg_config_path = "/var/ab/.config/pacman/makepkg.conf"; Ok((makepkg_config, makepkg_config_path.to_string())) diff --git a/backend/aurcache/src/builder/path_utils.rs b/backend/aurcache/src/builder/path_utils.rs index cca82ab5..30efbb87 100644 --- a/backend/aurcache/src/builder/path_utils.rs +++ b/backend/aurcache/src/builder/path_utils.rs @@ -3,13 +3,11 @@ use std::os::unix::fs::PermissionsExt; use std::path::PathBuf; use std::{env, fs}; -pub fn create_active_build_path(pkg_name: String) -> anyhow::Result { +pub fn create_active_build_path(pkg_name: &str) -> anyhow::Result { // this path is hardcoded at /app/builds/ - let mut path = env::current_dir()?; - path.push("builds"); - path.push(pkg_name); - fs::create_dir_all(path.clone())?; - fs::set_permissions(path.clone(), Permissions::from_mode(0o777))?; + let path = env::current_dir()?.join("builds").join(pkg_name); + fs::create_dir_all(&path)?; + fs::set_permissions(&path, Permissions::from_mode(0o777))?; Ok(path) } diff --git a/backend/aurcache/src/package/add.rs b/backend/aurcache/src/package/add.rs index 3f14f13f..b5a3b818 100644 --- a/backend/aurcache/src/package/add.rs +++ b/backend/aurcache/src/package/add.rs @@ -26,7 +26,7 @@ pub async fn package_add( }; let build_flags = build_flags.unwrap_or_else(|| { vec![ - "-Syu".to_string(), + "-B".to_string(), "--noconfirm".to_string(), "--noprogressbar".to_string(), "--color never".to_string(),