summaryrefslogtreecommitdiffstats
path: root/src/paths.rs
blob: 708413d56de6ce99571163c55b39ad1fa878ed29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! Build directory structure used through rebel
//!
//! # Current structure
//!
//! ```text
//! build/
//! ├── rootfs.tar
//! ├── downloads/
//! │   └── ...
//! ├── state/
//! │   ├── output/
//! │   │   ├── <input hash>.tar.tmp  # during packing
//! │   │   ├── <archive hash>.tar    # files are renamed when packing is finished
//! │   │   └── ...
//! │   ├── layer/
//! │   │   ├── <layer hash>/         # overlayfs layer dir of finished tasks
//! │   │   └── ...
//! │   └── task/
//! │       ├── <input hash>/
//! │       │   ├── layer/            # overlayfs layer dir (moved to layer/ after build)
//! │       │   ├── work/             # overlayfs work dir (discarded after build)
//! │       │   ├── task.json.tmp     # during write
//! │       │   └── task.json         # after write
//! │       └── ...
//! └── tmp/                          # tmpfs (mounted on start of rebel)
//!     ├── rootfs/                   # unpacked rootfs.tar
//!     ├── task/
//!     │   └── <input hash>/
//!     │       ├── config.json       # container runtime config
//!     │       ├── build/            # mount point for /build directory
//!     │       │   ├── downloads/    # downloaded sources
//!     │       │   ├── dest/         # collected as output after build
//!     │       │   ├── sysroot/      # sysroot mountpoint
//!     │       │   └── work/         # build overlay mountpoint
//!     │       ├── rootfs/           # rootfs overlay mountpoint
//!     │       └── depends/          # overlayed on rootfs in container
//!     └── containers/               # container state
//! ```

use crate::types::*;

pub const ROOTFS_ARCHIVE: &str = "build/rootfs.tar";

pub const DOWNLOADS_DIR: &str = "build/downloads";

pub const TMP_DIR: &str = "build/tmp";
pub const ROOTFS_DIR: &str = "build/tmp/rootfs";
pub const TASK_TMP_DIR: &str = "build/tmp/task";

pub const TASK_TMP_ROOTFS_SUBDIR: &str = "rootfs";
pub const TASK_TMP_DEPENDS_SUBDIR: &str = "depends";

pub const TASK_TMP_CONTAINERS_ROOT_SUBDIR: &str = "../../containers";

pub const OUTPUT_STATE_DIR: &str = "build/state/output";
pub const TASK_STATE_DIR: &str = "build/state/task";
pub const LAYER_STATE_DIR: &str = "build/state/layer";

pub const TASK_STATE_LAYER_SUBDIR: &str = "layer";
pub const TASK_STATE_WORK_SUBDIR: &str = "work";

pub const TASK_BUILDDIR: &str = "build";
pub const TASK_DESTDIR: &str = "build/dest";
pub const TASK_DLDIR: &str = "build/downloads";
pub const TASK_WORKDIR: &str = "build/work";
pub const TASK_SYSROOT: &str = "opt/toolchain/sysroot";

pub fn join(paths: &[&str]) -> String {
	paths.join("/")
}

pub fn abs(path: &str) -> String {
	join(&["", path])
}

pub fn task_tmp_dir(hash: &InputHash) -> String {
	join(&[TASK_TMP_DIR, &hash.to_string()])
}

pub fn task_state_dir(hash: &InputHash) -> String {
	join(&[TASK_STATE_DIR, &hash.to_string()])
}

pub fn task_meta_tmp_filename(hash: &InputHash) -> String {
	join(&[TASK_STATE_DIR, &hash.to_string(), "task.json.tmp"])
}

pub fn task_meta_filename(hash: &InputHash) -> String {
	join(&[TASK_STATE_DIR, &hash.to_string(), "task.json"])
}

pub fn task_log_filename(hash: &InputHash) -> String {
	join(&[TASK_STATE_DIR, &hash.to_string(), "task.log"])
}

pub fn layer_dir(hash: &LayerHash) -> String {
	join(&[LAYER_STATE_DIR, &hash.to_string()])
}

pub fn archive_tmp_filename(hash: &InputHash) -> String {
	join(&[OUTPUT_STATE_DIR, &format!("{}.tar.tmp", hash)])
}

pub fn archive_filename(hash: &ArchiveHash) -> String {
	join(&[OUTPUT_STATE_DIR, &format!("{}.tar", hash)])
}