From ae56b01ea46740069757bb7ce56be4a6be6acbcf Mon Sep 17 00:00:00 2001 From: Toby Davis Date: Sun, 6 Oct 2024 16:07:13 +0200 Subject: [PATCH] Allow specification of `make_root` for Make builder --- Cargo.lock | 2 +- src/archive.rs | 2 +- src/builders/make.rs | 28 ++++++++++++++++++++++++++-- src/sccmod/builders.py | 10 +++++++++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5702ecb..478bab9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -414,7 +414,7 @@ dependencies = [ [[package]] name = "sccmod" -version = "0.5.5" +version = "0.5.6" dependencies = [ "anstyle", "clap", diff --git a/src/archive.rs b/src/archive.rs index b38d800..5791990 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -11,7 +11,7 @@ pub fn extract>( archive_type: &str, ) -> Result<(), String> { let mut command = match archive_type.to_lowercase().as_ref() { - "tar" | "tar.gz" | "targz" | "tgz" => { + "tar" | "tar.gz" | "targz" | "tgz" | "tar.xz" | "txz" | "tarxz" => { let mut cmd = Command::new("tar"); cmd.arg("-xvf"); // Extract verbose file cmd.arg(name); // File name diff --git a/src/builders/make.rs b/src/builders/make.rs index e4e19a1..b8dd5a9 100644 --- a/src/builders/make.rs +++ b/src/builders/make.rs @@ -12,6 +12,7 @@ pub struct Make { pub jobs: usize, pub prefix_args: Option>, pub configure_flags: Option>, + pub make_root: Option, } impl Make { @@ -150,7 +151,17 @@ impl BuilderImpl for Make { .extract() .map_err(|_| "Failed to convert attribute 'configure_flags' to Rust Vec")?; - Ok(Self { configure, jobs, prefix_args, configure_flags }) + let make_root: Option = object + .getattr("make_root") + .map_err(|_| { + "Failed to read attribute 'make_root' of Builder object" + })? + .extract() + .map_err(|_| { + "Failed to convert attribute 'make_root' to Rust String" + })?; + + Ok(Self { configure, jobs, prefix_args, configure_flags, make_root }) } fn build< @@ -164,7 +175,20 @@ impl BuilderImpl for Make { install_path: &P2, dependencies: &[String], ) -> Result<(), String> { - self.configure(source_path, build_path, install_path, dependencies)?; + let make_source_path = if let Some(root) = &self.make_root { + source_path.as_ref().to_str().unwrap().to_owned() + + PATH_SEP.to_string().as_ref() + + root + } else { + source_path.as_ref().to_str().unwrap().to_owned() + }; + + self.configure( + &make_source_path, + build_path, + install_path, + dependencies, + )?; self.compile(build_path, dependencies)?; Ok(()) } diff --git a/src/sccmod/builders.py b/src/sccmod/builders.py index 4108663..30f83f7 100644 --- a/src/sccmod/builders.py +++ b/src/sccmod/builders.py @@ -9,8 +9,16 @@ def __init__( class Make: - def __init__(self, configure=True, jobs=8, prefix_args=None, configure_flags=None): + def __init__( + self, + configure=True, + jobs=8, + prefix_args=None, + configure_flags=None, + make_root=None, + ): self.configure = configure self.jobs = jobs self.prefix_args = prefix_args or [] self.configure_flags = configure_flags or [] + self.make_root = make_root