mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-04-20 19:44:50 +00:00
Merge branch 'fix/better-pull-strategy' into 'main'
fix: better pull/checkout strategy with fetch, checkout and merge Closes #65 See merge request gabmus/envision!17
This commit is contained in:
commit
15543619fb
7 changed files with 48 additions and 111 deletions
|
@ -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,9 +6,16 @@ use std::path::Path;
|
|||
pub struct Git {
|
||||
pub repo: String,
|
||||
pub dir: String,
|
||||
pub default_branch: String,
|
||||
}
|
||||
|
||||
impl Git {
|
||||
fn cmd(&self, args: Vec<String>) -> WorkerJob {
|
||||
let mut nargs = vec!["-C".into(), self.dir.clone()];
|
||||
nargs.extend(args);
|
||||
WorkerJob::new_cmd(None, "git".into(), Some(nargs))
|
||||
}
|
||||
|
||||
fn get_repo(&self) -> String {
|
||||
self.repo
|
||||
.split('#')
|
||||
|
@ -27,16 +31,7 @@ impl Git {
|
|||
}
|
||||
|
||||
pub fn get_reset_job(&self) -> WorkerJob {
|
||||
WorkerJob::new_cmd(
|
||||
None,
|
||||
"git".into(),
|
||||
Some(vec![
|
||||
"-C".into(),
|
||||
self.dir.clone(),
|
||||
"reset".into(),
|
||||
"--hard".into(),
|
||||
]),
|
||||
)
|
||||
self.cmd(vec!["reset".into(), "--hard".into()])
|
||||
}
|
||||
|
||||
pub fn get_override_remote_url_job(&self) -> WorkerJob {
|
||||
|
@ -76,11 +71,7 @@ impl Git {
|
|||
}
|
||||
|
||||
pub fn get_pull_job(&self) -> WorkerJob {
|
||||
WorkerJob::new_cmd(
|
||||
None,
|
||||
"git".into(),
|
||||
Some(vec!["-C".into(), self.dir.clone(), "pull".into()]),
|
||||
)
|
||||
self.cmd(vec!["pull".into()])
|
||||
}
|
||||
|
||||
pub fn get_clone_job(&self) -> WorkerJob {
|
||||
|
@ -96,32 +87,37 @@ impl Git {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn get_checkout_ref_job(&self) -> Option<WorkerJob> {
|
||||
self.get_ref().map(|r| {
|
||||
WorkerJob::new_cmd(
|
||||
None,
|
||||
"git".into(),
|
||||
Some(vec!["-C".into(), self.dir.clone(), "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_job(&self, profile: &Profile) -> Option<WorkerJob> {
|
||||
match self.get_clone_or_not_job() {
|
||||
Some(j) => Some(j),
|
||||
None => match profile.pull_on_build {
|
||||
true => Some(self.get_pull_job()),
|
||||
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() {
|
||||
if pull_on_build {
|
||||
jobs.push(self.get_override_remote_url_job());
|
||||
jobs.push(self.get_fetch_job());
|
||||
jobs.push(self.get_checkout_ref_job());
|
||||
jobs.push(self.get_pull_job());
|
||||
}
|
||||
} else {
|
||||
jobs.push(self.get_clone_job());
|
||||
jobs.push(self.get_checkout_ref_job());
|
||||
}
|
||||
jobs
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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_job(profile).map(|j| {
|
||||
jobs.push_back(j);
|
||||
});
|
||||
|
||||
git.get_checkout_ref_job().map(|j| {
|
||||
jobs.push_back(j);
|
||||
if profile.pull_on_build {
|
||||
jobs.push_back(git.get_pull_job());
|
||||
}
|
||||
});
|
||||
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();
|
||||
|
|
|
@ -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_job(profile).map(|j| {
|
||||
jobs.push_back(j);
|
||||
});
|
||||
|
||||
git.get_checkout_ref_job().map(|j| {
|
||||
jobs.push_back(j);
|
||||
if profile.pull_on_build {
|
||||
jobs.push_back(git.get_pull_job());
|
||||
}
|
||||
});
|
||||
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
|
||||
|
||||
let build_dir = format!(
|
||||
"{}/build",
|
||||
|
|
|
@ -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_job(profile).map(|j| {
|
||||
jobs.push_back(j);
|
||||
});
|
||||
|
||||
git.get_checkout_ref_job().map(|j| {
|
||||
jobs.push_back(j);
|
||||
if profile.pull_on_build {
|
||||
jobs.push_back(git.get_pull_job());
|
||||
}
|
||||
});
|
||||
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();
|
||||
|
|
|
@ -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_job(profile).map(|j| {
|
||||
jobs.push_back(j);
|
||||
});
|
||||
|
||||
git.get_checkout_ref_job().map(|j| {
|
||||
jobs.push_back(j);
|
||||
if profile.pull_on_build {
|
||||
jobs.push_back(git.get_pull_job());
|
||||
}
|
||||
});
|
||||
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();
|
||||
|
|
|
@ -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_job(profile).map(|j| {
|
||||
jobs.push_back(j);
|
||||
});
|
||||
|
||||
git.get_checkout_ref_job().map(|j| {
|
||||
jobs.push_back(j);
|
||||
if profile.pull_on_build {
|
||||
jobs.push_back(git.get_pull_job());
|
||||
}
|
||||
});
|
||||
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();
|
||||
|
|
|
@ -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_job(profile).map(|j| {
|
||||
jobs.push_back(j);
|
||||
});
|
||||
|
||||
git.get_checkout_ref_job().map(|j| {
|
||||
jobs.push_back(j);
|
||||
if profile.pull_on_build {
|
||||
jobs.push_back(git.get_pull_job());
|
||||
}
|
||||
});
|
||||
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();
|
||||
|
|
Loading…
Add table
Reference in a new issue