2 use std::path::PathBuf;
4 #[derive(Debug, Clone)]
5 pub(crate) struct Dirs {
6 pub(crate) source_dir: PathBuf,
7 pub(crate) download_dir: PathBuf,
8 pub(crate) build_dir: PathBuf,
9 pub(crate) dist_dir: PathBuf,
13 #[derive(Debug, Copy, Clone)]
14 pub(crate) enum PathBase {
22 fn to_path(self, dirs: &Dirs) -> PathBuf {
24 PathBase::Source => dirs.source_dir.clone(),
25 PathBase::Download => dirs.download_dir.clone(),
26 PathBase::Build => dirs.build_dir.clone(),
27 PathBase::Dist => dirs.dist_dir.clone(),
32 #[derive(Debug, Copy, Clone)]
33 pub(crate) enum RelPath {
35 Join(&'static RelPath, &'static str),
39 pub(crate) const SOURCE: RelPath = RelPath::Base(PathBase::Source);
40 pub(crate) const DOWNLOAD: RelPath = RelPath::Base(PathBase::Download);
41 pub(crate) const BUILD: RelPath = RelPath::Base(PathBase::Build);
42 pub(crate) const DIST: RelPath = RelPath::Base(PathBase::Dist);
44 pub(crate) const SCRIPTS: RelPath = RelPath::SOURCE.join("scripts");
45 pub(crate) const BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot");
46 pub(crate) const PATCHES: RelPath = RelPath::SOURCE.join("patches");
48 pub(crate) const fn join(&'static self, suffix: &'static str) -> RelPath {
49 RelPath::Join(self, suffix)
52 pub(crate) fn to_path(&self, dirs: &Dirs) -> PathBuf {
54 RelPath::Base(base) => base.to_path(dirs),
55 RelPath::Join(base, suffix) => base.to_path(dirs).join(suffix),
59 pub(crate) fn ensure_exists(&self, dirs: &Dirs) {
60 fs::create_dir_all(self.to_path(dirs)).unwrap();
63 pub(crate) fn ensure_fresh(&self, dirs: &Dirs) {
64 let path = self.to_path(dirs);
66 fs::remove_dir_all(&path).unwrap();
68 fs::create_dir_all(path).unwrap();