diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-10-12 23:05:29 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-10-12 23:05:49 +0200 |
commit | 855d2daea1e4d22cc9b62417875c90619e553500 (patch) | |
tree | 9d247fac92e0b617a9b2e38f5d479631023dbeef | |
parent | 0709dcf3a153b6d48c42663029aa44f2baf31274 (diff) | |
download | rebel-855d2daea1e4d22cc9b62417875c90619e553500.tar rebel-855d2daea1e4d22cc9b62417875c90619e553500.zip |
context: allow passing host and target arguments when parsing tasks
-rw-r--r-- | Cargo.lock | 34 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/context.rs | 30 |
3 files changed, 60 insertions, 6 deletions
@@ -3,6 +3,15 @@ version = 3 [[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] name = "arrayref" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -529,6 +538,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] name = "memoffset" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -818,10 +833,12 @@ dependencies = [ "hex", "indoc", "ipc-channel", + "lazy_static", "libc", "nix", "oci-spec", "olpc-cjson", + "regex", "scoped-tls-hkt", "serde", "serde_json", @@ -841,6 +858,23 @@ dependencies = [ ] [[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] name = "remove_dir_all" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -16,10 +16,12 @@ handlebars = "4.1.3" hex = { version = "0.4.3", features = ["std", "serde"] } indoc = "1.0.3" ipc-channel = { git = "https://github.com/servo/ipc-channel.git" } +lazy_static = "1.4.0" libc = "0.2.84" nix = "0.23.0" oci-spec = "0.5.1" olpc-cjson = "0.1.0" +regex = "1.5.4" scoped-tls-hkt = "0.1.2" serde = { version = "1", features = ["derive"] } serde_json = "1.0.62" diff --git a/src/context.rs b/src/context.rs index 67db982..3562f26 100644 --- a/src/context.rs +++ b/src/context.rs @@ -9,6 +9,8 @@ use std::{ result, }; +use lazy_static::lazy_static; +use regex::Regex; use serde::Serialize; use crate::{ @@ -242,15 +244,31 @@ impl Context { } pub fn parse<'ctx>(&'ctx self, s: &str) -> Option<TaskRef> { - let (recipe, task) = s.split_once(":")?; - let id = TaskID { - recipe: recipe.to_string(), - task: task.to_string(), - }; + lazy_static! { + static ref RE: Regex = Regex::new( + r"^(?P<recipe>[[:word:]-]+):(?P<task>[[:word:]-]+)(?:@(?P<host>[[:word:]-]+))?(?:/(?P<target>[[:word:]-]+))?$", + ).unwrap(); + } + + let cap = RE.captures(s)?; + + let recipe = cap["recipe"].to_string(); + let task = cap["task"].to_string(); + + let id = TaskID { recipe, task }; let (ctx_id, _) = self.tasks.get_key_value(&id)?; let mut args = self.globals.clone(); - args.set("host", Some(self.platforms["aarch64"].clone())); + + if let Some(host) = cap.name("host") { + let plat = self.platforms.get(host.as_str())?; + args.set("host", Some(plat.clone())); + args.set("target", Some(plat.clone())); + } + if let Some(target) = cap.name("target") { + let plat = self.platforms.get(target.as_str())?; + args.set("target", Some(plat.clone())); + } self.task_ref(ctx_id, &args).ok() } |