aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2023-01-13 23:42:56 -0500
committerGalen Guyer <galen@galenguyer.com>2023-01-13 23:42:56 -0500
commitb3f6218cb39c4b906e25a7da0ec8c106274dd1d2 (patch)
tree53f2e7a91623fe8646b495fb8e0b11304b4daa1c
parent498df4745e36e5c679221f03845207a2cb1b40db (diff)
build package in chroot
-rw-r--r--Cargo.lock63
-rw-r--r--Cargo.toml1
-rw-r--r--src/bin/build-pkg.rs65
3 files changed, 129 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e39e400..105cb3c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -114,6 +114,26 @@ dependencies = [
]
[[package]]
+name = "dirs"
+version = "4.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
+dependencies = [
+ "dirs-sys",
+]
+
+[[package]]
+name = "dirs-sys"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
+dependencies = [
+ "libc",
+ "redox_users",
+ "winapi",
+]
+
+[[package]]
name = "encoding_rs"
version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -211,6 +231,17 @@ dependencies = [
]
[[package]]
+name = "getrandom"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "wasi",
+]
+
+[[package]]
name = "h2"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -528,6 +559,7 @@ version = "0.1.0"
dependencies = [
"alpm",
"anyhow",
+ "dirs",
"reqwest",
"serde",
"serde_json",
@@ -562,6 +594,17 @@ dependencies = [
]
[[package]]
+name = "redox_users"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
+dependencies = [
+ "getrandom",
+ "redox_syscall",
+ "thiserror",
+]
+
+[[package]]
name = "remove_dir_all"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -735,6 +778,26 @@ dependencies = [
]
[[package]]
+name = "thiserror"
+version = "1.0.38"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.38"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "tinyvec"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index b3727ac..80afed7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,6 +10,7 @@ edition = "2021"
[dependencies]
alpm = "2.2.1"
anyhow = "1.0.68"
+dirs = "4.0.0"
reqwest = { version = "0.11.13", features = ["json", "gzip"] }
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.91"
diff --git a/src/bin/build-pkg.rs b/src/bin/build-pkg.rs
index 1ec422f..23bd5d7 100644
--- a/src/bin/build-pkg.rs
+++ b/src/bin/build-pkg.rs
@@ -1,3 +1,5 @@
+use std::process::{Child, Command, Output};
+
#[tokio::main]
async fn main() {
let package_name = std::env::args().nth(1).expect("No package name given");
@@ -19,4 +21,67 @@ async fn main() {
}) {
dbg!(dependency);
}
+
+ let mut command = Command::new("mkdir");
+ command.arg("-p").arg(format!(
+ "{}/pkgbuild/",
+ dirs::cache_dir().unwrap().to_str().unwrap()
+ ));
+ dbg!(&command);
+ print_status(command.spawn());
+
+ let mut command = Command::new("git");
+ command
+ .arg("clone")
+ .arg("--single-branch")
+ .arg("--branch")
+ .arg(&package_name)
+ .arg(format!(
+ "{}/aur.git",
+ dirs::home_dir().unwrap().to_str().unwrap()
+ ))
+ .arg(format!(
+ "{}/pkgbuild/{}",
+ dirs::cache_dir().unwrap().to_str().unwrap(),
+ package_name
+ ));
+ dbg!(&command);
+ print_status(command.spawn());
+
+ let chroot_dir = std::env::var("PKGBUILD_CHROOT_DIR")
+ .unwrap_or_else(|_| String::from("/var/lib/pkgbuild"))
+ .trim_end_matches('/')
+ .to_string();
+
+ let mut command = Command::new("makechrootpkg");
+ command
+ .current_dir(format!(
+ "{}/pkgbuild/{}",
+ dirs::cache_dir().unwrap().to_str().unwrap(),
+ package_name
+ ))
+ .arg("-l")
+ .arg(package_name)
+ .arg("-r")
+ .arg(chroot_dir)
+ .arg("--")
+ .args(["--skippgpcheck", "--syncdeps"]);
+ dbg!(&command);
+ print_status(command.spawn());
+}
+
+fn print_status(output: Result<Child, std::io::Error>) {
+ match output {
+ Ok(mut child) => match child.wait() {
+ Ok(status) => {
+ println!("STATUS: {}", status.code().unwrap_or(-1));
+ }
+ Err(e) => {
+ println!("ERROR: {e}");
+ }
+ },
+ Err(e) => {
+ println!("ERROR: {e}");
+ }
+ }
}