summaryrefslogtreecommitdiffstats
path: root/src/job
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-12-07 13:23:35 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-12-07 13:26:16 +0100
commit83b3b97fee854e19c63999e4daadf802784a1499 (patch)
treeaadb169bde50d4497110a7f8989fde755d255c92 /src/job
parent5ff10cdad822300a04ffe3cb2482e20c37d7c2bd (diff)
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 <mail@beyermatthias.de>
Diffstat (limited to 'src/job')
-rw-r--r--src/job/job.rs8
-rw-r--r--src/job/set.rs24
2 files changed, 18 insertions, 14 deletions
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<PhaseName>,
@@ -32,14 +32,14 @@ pub struct Job {
impl Job {
- pub fn new(pkg: Package, image: ImageName, phases: Vec<PhaseName>, resources: Vec<JobResource>) -> Self {
+ pub fn new(pkg: Package, script_shebang: Shebang, image: ImageName, phases: Vec<PhaseName>, resources: Vec<JobResource>) -> 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<PhaseName>, resources: Vec<JobResource>) -> Result<Vec<JobSet>> {
- tree_into_jobsets(t, image, phases, resources)
+ pub fn sets_from_tree(t: Tree, shebang: Shebang, image: ImageName, phases: Vec<PhaseName>, resources: Vec<JobResource>) -> Result<Vec<JobSet>> {
+ 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<PhaseName>, resources: Vec<JobResource>) -> Result<Vec<JobSet>> {
- fn inner(tree: Tree, image: &ImageName, phases: &Vec<PhaseName>, resources: &Vec<JobResource>) -> Result<Vec<JobSet>> {
+fn tree_into_jobsets(tree: Tree, shebang: Shebang, image: ImageName, phases: Vec<PhaseName>, resources: Vec<JobResource>) -> Result<Vec<JobSet>> {
+ fn inner(tree: Tree, shebang: &Shebang, image: &ImageName, phases: &Vec<PhaseName>, resources: &Vec<JobResource>) -> Result<Vec<JobSet>> {
trace!("Creating jobsets for tree: {:?}", tree);
let mut sets = vec![];
@@ -48,7 +49,7 @@ fn tree_into_jobsets(tree: Tree, image: ImageName, phases: Vec<PhaseName>, 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<PhaseName>, 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<PhaseName>, 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();