summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-10-30 16:20:52 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-10-30 16:51:42 +0200
commit6d77ac17b4414d30384473c667e08199f428d94e (patch)
treebd00f2b6c68f02bc9d632a46b6e1371afc05c1cb
parent831c3c543e3df14697eb3f8dc89eaf0b08dd4b66 (diff)
downloadrebel-6d77ac17b4414d30384473c667e08199f428d94e.tar
rebel-6d77ac17b4414d30384473c667e08199f428d94e.zip
driver: replace dependency cutoff with stub tasks
Instead of having the resolver decide whether a dependency is included in the rootfs, let the context replace the task definition with an empty stub.
-rw-r--r--crates/driver/src/context.rs99
-rw-r--r--crates/driver/src/resolve.rs2
-rw-r--r--crates/driver/src/task.rs6
3 files changed, 71 insertions, 36 deletions
diff --git a/crates/driver/src/context.rs b/crates/driver/src/context.rs
index 25b8e38..3e1a5eb 100644
--- a/crates/driver/src/context.rs
+++ b/crates/driver/src/context.rs
@@ -136,6 +136,7 @@ pub struct Context {
platforms: HashMap<String, Arg>,
globals: TaskArgs,
tasks: HashMap<TaskID, TaskDef>,
+ rootfs_tasks: HashMap<TaskID, TaskDef>,
}
impl Context {
@@ -170,15 +171,80 @@ impl Context {
arg("destdir", paths::TASK_DESTDIR.to_string()),
arg("sysroot", paths::TASK_SYSROOT.to_string()),
]);
+ let rootfs_tasks = Context::rootfs_tasks();
Context {
platforms,
globals,
tasks,
+ rootfs_tasks,
}
}
- fn get_with_args<'ctx>(&'ctx self, id: &'ctx TaskID, _args: &TaskArgs) -> Result<&TaskDef> {
+ fn rootfs_tasks() -> HashMap<TaskID, TaskDef> {
+ // TODO: Do not hardcode this
+ const ROOTFS_TASKS: &[((&str, &str), bool, &[&str])] = &[
+ (("gmp", "install"), false, &["default"]),
+ (("mpfr", "install"), false, &["default"]),
+ (("mpc", "install"), false, &["default"]),
+ (("zlib", "install"), false, &["default"]),
+ (("binutils", "install"), true, &["default"]),
+ (("gcc", "install"), true, &["default"]),
+ (("libgcc", "install"), true, &["default"]),
+ (("gcc-libs", "install"), false, &["default"]),
+ (("linux-uapi-headers", "install"), false, &["default"]),
+ (("glibc", "install"), false, &["default"]),
+ ];
+
+ let mut ret = HashMap::new();
+
+ for ((recipe, task), has_target, outputs) in ROOTFS_TASKS {
+ let mut task_def = TaskDef::default();
+
+ task_def.args.insert("host".to_string(), ArgType::Platform);
+ if *has_target {
+ task_def
+ .args
+ .insert("target".to_string(), ArgType::Platform);
+ }
+
+ for output in *outputs {
+ task_def
+ .output
+ .insert(output.to_string(), Output::default());
+ }
+
+ ret.insert(
+ TaskID {
+ recipe: recipe.to_string(),
+ task: task.to_string(),
+ },
+ task_def,
+ );
+ }
+
+ ret
+ }
+
+ fn rootfs_task<'ctx>(&'ctx self, id: &'ctx TaskID, args: &TaskArgs) -> Option<&TaskDef> {
+ let build = self.globals.get("build").unwrap();
+ if args.get("host") != Some(build) {
+ return None;
+ }
+
+ let task_def = self.rootfs_tasks.get(id)?;
+ if task_def.args.get("target").is_some() && args.get("target") != Some(build) {
+ return None;
+ }
+
+ Some(task_def)
+ }
+
+ fn get_with_args<'ctx>(&'ctx self, id: &'ctx TaskID, args: &TaskArgs) -> Result<&TaskDef> {
+ if let Some(rootfs_task) = self.rootfs_task(id, args) {
+ return Ok(rootfs_task);
+ }
+
self.tasks.get(id).ok_or(Error {
task: id,
kind: ErrorKind::TaskNotFound,
@@ -403,37 +469,6 @@ impl Context {
Ok(ret)
}
-
- pub fn in_rootfs<'ctx>(&'ctx self, output: &OutputRef<'ctx>) -> bool {
- let build = self.globals.get("build").unwrap();
- if output.task.args.get("host") != Some(build) {
- return false;
- }
- if let Some(target) = output.task.args.get("target") {
- if target != build {
- return false;
- }
- }
-
- // TODO: Do not hardcode this
- match (
- output.task.id.recipe.as_str(),
- output.task.id.task.as_str(),
- output.output,
- ) {
- ("gmp", "install", "default") => true,
- ("mpfr", "install", "default") => true,
- ("mpc", "install", "default") => true,
- ("zlib", "install", "default") => true,
- ("binutils", "install", "default") => true,
- ("gcc", "install", "default") => true,
- ("libgcc", "install", "default") => true,
- ("gcc-libs", "install", "default") => true,
- ("linux-uapi-headers", "install", "default") => true,
- ("glibc", "install", "default") => true,
- _ => false,
- }
- }
}
impl<'ctx> Index<&TaskRef<'ctx>> for &'ctx Context {
diff --git a/crates/driver/src/resolve.rs b/crates/driver/src/resolve.rs
index 9ff5708..35915c0 100644
--- a/crates/driver/src/resolve.rs
+++ b/crates/driver/src/resolve.rs
@@ -128,7 +128,7 @@ where
ctx: &'ctx Context,
dep: OutputRef<'ctx>,
) -> Vec<Error<'ctx>> {
- if ret.contains(&dep) || ctx.in_rootfs(&dep) {
+ if ret.contains(&dep) {
return Vec::new();
}
diff --git a/crates/driver/src/task.rs b/crates/driver/src/task.rs
index 6b9083b..8f3c7d6 100644
--- a/crates/driver/src/task.rs
+++ b/crates/driver/src/task.rs
@@ -50,14 +50,14 @@ pub struct OutputDep {
pub output: String,
}
-#[derive(Clone, Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize, Default)]
pub struct Output {
pub path: Option<String>,
#[serde(default)]
pub runtime_depends: HashSet<OutputDep>,
}
-#[derive(Clone, Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize, Default)]
pub struct Action {
#[serde(default)]
pub run: String,
@@ -69,7 +69,7 @@ impl Action {
}
}
-#[derive(Clone, Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize, Default)]
pub struct TaskDef {
#[serde(skip)]
pub meta: RecipeMeta,