From 3a3a8ba8b773d36a0b3c8208e37928e3c6dbe696 Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 4 Jul 2023 01:52:55 -0700 Subject: pretty sure this gets host-preferential task assignment in place? --- src/lua/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/lua') diff --git a/src/lua/mod.rs b/src/lua/mod.rs index 1b86582..89ff4c2 100644 --- a/src/lua/mod.rs +++ b/src/lua/mod.rs @@ -152,6 +152,21 @@ mod lua_exports { Ok(result) } + pub fn check_dependencies(commands: Vec) -> Result<(), rlua::Error> { + let mut missing_deps = Vec::new(); + for command in commands.iter() { + if !has_cmd(command)? { + missing_deps.push(command.clone()); + } + } + + if missing_deps.len() > 0 { + return Err(LuaError::RuntimeError(format!("missing dependencies: {}", missing_deps.join(", ")))); + } + + Ok(()) + } + pub fn metric(name: String, value: String, job_ctx: Arc>) -> Result<(), rlua::Error> { let rt = tokio::runtime::Builder::new_current_thread() .enable_all() @@ -283,6 +298,10 @@ impl BuildEnv { Ok(()) })?; + let check_dependencies = decl_env.create_function("dependencies", move |_, job_ref, commands: Vec| { + lua_exports::check_dependencies(commands) + })?; + let build = decl_env.create_function("build", move |_, job_ref, (command, params): (LuaValue, LuaValue)| { lua_exports::build_command_impl(command, params, job_ref) })?; @@ -337,6 +356,7 @@ impl BuildEnv { vec![ ("hello", hello), ("run", build), + ("dependencies", check_dependencies), ("metric", metric), ("error", error), ("artifact", artifact), -- cgit v1.1