fix: refactored entire git strategy

This commit is contained in:
Gabriele Musco 2023-10-16 06:06:44 +00:00
parent bfd374fe81
commit 30873c4969
7 changed files with 42 additions and 97 deletions

View file

@ -1,7 +1,4 @@
use crate::{
profile::Profile,
ui::job_worker::job::{FuncWorkerOut, WorkerJob},
};
use crate::ui::job_worker::job::{FuncWorkerOut, WorkerJob};
use git2::Repository;
use std::path::Path;
@ -9,6 +6,7 @@ use std::path::Path;
pub struct Git {
pub repo: String,
pub dir: String,
pub default_branch: String,
}
impl Git {
@ -72,13 +70,8 @@ impl Git {
}))
}
pub fn get_pull_jobs(&self) -> Vec<WorkerJob> {
let mut res = vec![self.cmd(vec!["fetch".into()])];
if let Some(checkout_j) = self.get_checkout_ref_job() {
res.push(checkout_j);
}
res.push(self.cmd(vec!["merge".into()]));
res
pub fn get_pull_job(&self) -> WorkerJob {
self.cmd(vec!["pull".into()])
}
pub fn get_clone_job(&self) -> WorkerJob {
@ -94,26 +87,37 @@ impl Git {
)
}
pub fn get_checkout_ref_job(&self) -> Option<WorkerJob> {
self.get_ref().map(|r| self.cmd(vec!["checkout".into(), r]))
pub fn get_checkout_ref_job(&self) -> WorkerJob {
let gref = self.get_ref().unwrap_or(self.default_branch.clone());
self.cmd(vec!["checkout".into(), gref])
}
pub fn get_clone_or_not_job(&self) -> Option<WorkerJob> {
pub fn get_fetch_job(&self) -> WorkerJob {
self.cmd(vec!["fetch".into()])
}
pub fn get_merge_job(&self) -> WorkerJob {
self.cmd(vec!["merge".into(), "--ff-only".into()])
}
pub fn clone_exists(&self) -> bool {
let path_s = format!("{}/.git", self.dir.clone());
let path = Path::new(&path_s);
if path.is_dir() {
return None;
}
Some(self.get_clone_job())
Path::new(&path_s).is_dir()
}
pub fn get_clone_or_pull_jobs(&self, profile: &Profile) -> Option<Vec<WorkerJob>> {
match self.get_clone_or_not_job() {
Some(j) => Some(vec![j]),
None => match profile.pull_on_build {
true => Some(self.get_pull_jobs().into()),
false => None,
},
pub fn get_pre_build_jobs(&self, pull_on_build: bool) -> Vec<WorkerJob> {
let mut jobs = Vec::<WorkerJob>::new();
if self.clone_exists() {
jobs.push(self.get_override_remote_url_job());
jobs.push(self.get_fetch_job());
jobs.push(self.get_checkout_ref_job());
if pull_on_build {
jobs.push(self.get_pull_job());
}
} else {
jobs.push(self.get_clone_job());
jobs.push(self.get_checkout_ref_job());
}
jobs
}
}

View file

@ -18,20 +18,10 @@ pub fn get_build_basalt_jobs(profile: &Profile, clean_build: bool) -> VecDeque<W
None => "https://gitlab.freedesktop.org/mateosss/basalt.git".into(),
},
dir: profile.features.basalt.path.as_ref().unwrap().clone(),
default_branch: "main".into(),
};
jobs.push_back(git.get_override_remote_url_job());
git.get_clone_or_pull_jobs(profile).map(|j| {
jobs.extend(j);
});
git.get_checkout_ref_job().map(|j| {
jobs.push_back(j);
if profile.pull_on_build {
jobs.extend(git.get_pull_jobs());
}
});
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
let build_dir = format!("{}/build", profile.features.basalt.path.as_ref().unwrap());
let mut cmake_vars: HashMap<String, String> = HashMap::new();

View file

@ -18,20 +18,10 @@ pub fn get_build_libsurvive_jobs(profile: &Profile, clean_build: bool) -> VecDeq
None => "https://github.com/cntools/libsurvive".into(),
},
dir: profile.features.libsurvive.path.as_ref().unwrap().clone(),
default_branch: "master".into(),
};
jobs.push_back(git.get_override_remote_url_job());
git.get_clone_or_pull_jobs(profile).map(|j| {
jobs.extend(j);
});
git.get_checkout_ref_job().map(|j| {
jobs.push_back(j);
if profile.pull_on_build {
jobs.extend(git.get_pull_jobs());
}
});
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
let build_dir = format!(
"{}/build",

View file

@ -22,19 +22,10 @@ pub fn get_build_monado_jobs(
None => "https://gitlab.freedesktop.org/monado/monado".into(),
},
dir: profile.xrservice_path.clone(),
default_branch: "main".into(),
};
jobs.push_back(git.get_override_remote_url_job());
git.get_clone_or_pull_jobs(profile).map(|j| {
jobs.extend(j);
});
git.get_checkout_ref_job().map(|j| {
jobs.push_back(j);
if profile.pull_on_build {
jobs.extend(git.get_pull_jobs());
}
});
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
let build_dir = format!("{}/build", profile.xrservice_path);
let mut env: HashMap<String, String> = HashMap::new();

View file

@ -18,20 +18,10 @@ pub fn get_build_opencomposite_jobs(profile: &Profile, clean_build: bool) -> Vec
None => "https://gitlab.com/znixian/OpenOVR.git".into(),
},
dir: profile.opencomposite_path.clone(),
default_branch: "openxr".into(),
};
jobs.push_back(git.get_override_remote_url_job());
git.get_clone_or_pull_jobs(profile).map(|j| {
jobs.extend(j);
});
git.get_checkout_ref_job().map(|j| {
jobs.push_back(j);
if profile.pull_on_build {
jobs.extend(git.get_pull_jobs());
}
});
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
let build_dir = format!("{}/build", profile.opencomposite_path);
let mut cmake_vars: HashMap<String, String> = HashMap::new();

View file

@ -18,20 +18,10 @@ pub fn get_build_openhmd_jobs(profile: &Profile, clean_build: bool) -> VecDeque<
None => "https://github.com/OpenHMD/OpenHMD".into(),
},
dir: profile.features.openhmd.path.as_ref().unwrap().clone(),
default_branch: "master".into(),
};
jobs.push_back(git.get_override_remote_url_job());
git.get_clone_or_pull_jobs(profile).map(|j| {
jobs.extend(j);
});
git.get_checkout_ref_job().map(|j| {
jobs.push_back(j);
if profile.pull_on_build {
jobs.extend(git.get_pull_jobs());
}
});
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
let build_dir = format!("{}/build", profile.features.openhmd.path.as_ref().unwrap());
let mut cmake_vars: HashMap<String, String> = HashMap::new();

View file

@ -22,20 +22,10 @@ pub fn get_build_wivrn_jobs(
None => "https://github.com/Meumeu/WiVRn".into(),
},
dir: profile.xrservice_path.clone(),
default_branch: "master".into(),
};
jobs.push_back(git.get_override_remote_url_job());
git.get_clone_or_pull_jobs(profile).map(|j| {
jobs.extend(j);
});
git.get_checkout_ref_job().map(|j| {
jobs.push_back(j);
if profile.pull_on_build {
jobs.extend(git.get_pull_jobs());
}
});
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
let build_dir = format!("{}/build", profile.xrservice_path);
let mut cmake_vars: HashMap<String, String> = HashMap::new();