From 855d2daea1e4d22cc9b62417875c90619e553500 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 12 Oct 2021 23:05:29 +0200 Subject: context: allow passing host and target arguments when parsing tasks --- Cargo.lock | 34 ++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/context.rs | 30 ++++++++++++++++++++++++------ 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fea8e57..a3f963e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. 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" @@ -528,6 +537,12 @@ version = "2.0.0" 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" @@ -818,10 +833,12 @@ dependencies = [ "hex", "indoc", "ipc-channel", + "lazy_static", "libc", "nix", "oci-spec", "olpc-cjson", + "regex", "scoped-tls-hkt", "serde", "serde_json", @@ -840,6 +857,23 @@ dependencies = [ "bitflags", ] +[[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" diff --git a/Cargo.toml b/Cargo.toml index f89ed59..e3bfa0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 { - 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[[:word:]-]+):(?P[[:word:]-]+)(?:@(?P[[:word:]-]+))?(?:/(?P[[: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() } -- cgit v1.2.3