From 83b3b97fee854e19c63999e4daadf802784a1499 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 7 Dec 2020 13:23:35 +0100 Subject: Implement shebang overwriting This patch implements the shebang overwriting functionality that was in a TODO note. It adds a `Shebang` type for it, which is a String wrapper. Signed-off-by: Matthias Beyer --- src/job/job.rs | 8 ++++---- src/job/set.rs | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'src/job') diff --git a/src/job/job.rs b/src/job/job.rs index bdab657..4ad0090 100644 --- a/src/job/job.rs +++ b/src/job/job.rs @@ -3,6 +3,7 @@ use uuid::Uuid; use crate::job::JobResource; use crate::package::Package; +use crate::package::Shebang; use crate::phase::PhaseName; use crate::util::docker::ImageName; @@ -19,9 +20,8 @@ pub struct Job { #[getset(get = "pub")] pub(in super) image: ImageName, - #[getset(get = "pub")] - pub(in super) script_shebang: String, + pub(in super) script_shebang: Shebang, #[getset(get = "pub")] pub(in super) script_phases: Vec, @@ -32,14 +32,14 @@ pub struct Job { impl Job { - pub fn new(pkg: Package, image: ImageName, phases: Vec, resources: Vec) -> Self { + pub fn new(pkg: Package, script_shebang: Shebang, image: ImageName, phases: Vec, resources: Vec) -> Self { let uuid = Uuid::new_v4(); Job { uuid, package: pkg, image, - script_shebang: String::from("#!/bin/bash"), // TODO Dont hardcode + script_shebang, script_phases: phases, resources, } diff --git a/src/job/set.rs b/src/job/set.rs index e6902df..c94fb09 100644 --- a/src/job/set.rs +++ b/src/job/set.rs @@ -7,6 +7,7 @@ use crate::filestore::MergedStores; use crate::job::Job; use crate::job::JobResource; use crate::job::RunnableJob; +use crate::package::Shebang; use crate::package::Tree; use crate::phase::PhaseName; use crate::source::SourceCache; @@ -19,8 +20,8 @@ pub struct JobSet { } impl JobSet { - pub fn sets_from_tree(t: Tree, image: ImageName, phases: Vec, resources: Vec) -> Result> { - tree_into_jobsets(t, image, phases, resources) + pub fn sets_from_tree(t: Tree, shebang: Shebang, image: ImageName, phases: Vec, resources: Vec) -> Result> { + tree_into_jobsets(t, shebang, image, phases, resources) } fn is_empty(&self) -> bool { @@ -39,8 +40,8 @@ impl JobSet { } /// Get the tree as sets of jobs, the deepest level of the tree first -fn tree_into_jobsets(tree: Tree, image: ImageName, phases: Vec, resources: Vec) -> Result> { - fn inner(tree: Tree, image: &ImageName, phases: &Vec, resources: &Vec) -> Result> { +fn tree_into_jobsets(tree: Tree, shebang: Shebang, image: ImageName, phases: Vec, resources: Vec) -> Result> { + fn inner(tree: Tree, shebang: &Shebang, image: &ImageName, phases: &Vec, resources: &Vec) -> Result> { trace!("Creating jobsets for tree: {:?}", tree); let mut sets = vec![]; @@ -48,7 +49,7 @@ fn tree_into_jobsets(tree: Tree, image: ImageName, phases: Vec, resou for (package, dep) in tree.into_iter() { trace!("Recursing for package: {:?}", package); - let mut sub_sets = inner(dep, image, phases, resources)?; // recursion! + let mut sub_sets = inner(dep, shebang, image, phases, resources)?; // recursion! sets.append(&mut sub_sets); current_set.push(package); } @@ -58,7 +59,7 @@ fn tree_into_jobsets(tree: Tree, image: ImageName, phases: Vec, resou set: current_set .into_iter() .map(|package| { - Job::new(package, image.clone(), phases.clone(), resources.clone()) + Job::new(package, shebang.clone(), image.clone(), phases.clone(), resources.clone()) }) .collect(), }; @@ -76,7 +77,7 @@ fn tree_into_jobsets(tree: Tree, image: ImageName, phases: Vec, resou Ok(result) } - inner(tree, &image, &phases, &resources).map(|mut v| { + inner(tree, &shebang, &image, &phases, &resources).map(|mut v| { // reverse, because the highest level in the tree is added as first element in the vector // and the deepest level is last. // @@ -129,8 +130,9 @@ mod tests { let image = ImageName::from(String::from("test")); let phases = vec![PhaseName::from(String::from("testphase"))]; + let shebang = Shebang::from(String::from("#!/bin/bash")); - let js = JobSet::sets_from_tree(tree, image, phases, vec![]); + let js = JobSet::sets_from_tree(tree, shebang, image, phases, vec![]); assert!(js.is_ok()); let js = js.unwrap(); @@ -176,8 +178,9 @@ mod tests { let image = ImageName::from(String::from("test")); let phases = vec![PhaseName::from(String::from("testphase"))]; + let shebang = Shebang::from(String::from("#!/bin/bash")); - let js = JobSet::sets_from_tree(tree, image, phases, vec![]); + let js = JobSet::sets_from_tree(tree, shebang, image, phases, vec![]); assert!(js.is_ok()); let js = js.unwrap(); @@ -228,8 +231,9 @@ mod tests { let image = ImageName::from(String::from("test")); let phases = vec![PhaseName::from(String::from("testphase"))]; + let shebang = Shebang::from(String::from("#!/bin/bash")); - let js = JobSet::sets_from_tree(tree, image, phases, vec![]); + let js = JobSet::sets_from_tree(tree, shebang, image, phases, vec![]); assert!(js.is_ok()); let js = js.unwrap(); -- cgit v1.2.3