Merge commit '57845a397e
' into sync_cg_clif-2024-12-06
This commit is contained in:
commit
b3d837afe1
29 changed files with 396 additions and 428 deletions
|
@ -1,8 +1,5 @@
|
|||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::utils::ensure_empty_dir;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct Dirs {
|
||||
pub(crate) source_dir: PathBuf,
|
||||
|
@ -16,54 +13,34 @@ pub(crate) struct Dirs {
|
|||
#[derive(Debug, Copy, Clone)]
|
||||
pub(crate) enum PathBase {
|
||||
Source,
|
||||
Download,
|
||||
Build,
|
||||
Dist,
|
||||
}
|
||||
|
||||
impl PathBase {
|
||||
fn to_path(self, dirs: &Dirs) -> PathBuf {
|
||||
match self {
|
||||
PathBase::Source => dirs.source_dir.clone(),
|
||||
PathBase::Download => dirs.download_dir.clone(),
|
||||
PathBase::Build => dirs.build_dir.clone(),
|
||||
PathBase::Dist => dirs.dist_dir.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub(crate) enum RelPath {
|
||||
Base(PathBase),
|
||||
Join(&'static RelPath, &'static str),
|
||||
pub(crate) struct RelPath {
|
||||
base: PathBase,
|
||||
suffix: &'static str,
|
||||
}
|
||||
|
||||
impl RelPath {
|
||||
pub(crate) const SOURCE: RelPath = RelPath::Base(PathBase::Source);
|
||||
pub(crate) const DOWNLOAD: RelPath = RelPath::Base(PathBase::Download);
|
||||
pub(crate) const BUILD: RelPath = RelPath::Base(PathBase::Build);
|
||||
pub(crate) const DIST: RelPath = RelPath::Base(PathBase::Dist);
|
||||
pub(crate) const fn source(suffix: &'static str) -> RelPath {
|
||||
RelPath { base: PathBase::Source, suffix }
|
||||
}
|
||||
|
||||
pub(crate) const SCRIPTS: RelPath = RelPath::SOURCE.join("scripts");
|
||||
pub(crate) const PATCHES: RelPath = RelPath::SOURCE.join("patches");
|
||||
|
||||
pub(crate) const fn join(&'static self, suffix: &'static str) -> RelPath {
|
||||
RelPath::Join(self, suffix)
|
||||
pub(crate) const fn build(suffix: &'static str) -> RelPath {
|
||||
RelPath { base: PathBase::Build, suffix }
|
||||
}
|
||||
|
||||
pub(crate) fn to_path(&self, dirs: &Dirs) -> PathBuf {
|
||||
match self {
|
||||
RelPath::Base(base) => base.to_path(dirs),
|
||||
RelPath::Join(base, suffix) => base.to_path(dirs).join(suffix),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn ensure_exists(&self, dirs: &Dirs) {
|
||||
fs::create_dir_all(self.to_path(dirs)).unwrap();
|
||||
}
|
||||
|
||||
pub(crate) fn ensure_fresh(&self, dirs: &Dirs) {
|
||||
let path = self.to_path(dirs);
|
||||
ensure_empty_dir(&path);
|
||||
self.base.to_path(dirs).join(self.suffix)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue