summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-20 17:11:34 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-20 17:12:02 +0200
commit7164660d63052bfa47a082711a64529b026b35f2 (patch)
treeaa1358f85c6afe9ce50676d8e1f439fc97517367
parent801f049969be0ca907b74e53597bec33cba97af4 (diff)
downloadrebel-7164660d63052bfa47a082711a64529b026b35f2.tar
rebel-7164660d63052bfa47a082711a64529b026b35f2.zip
Move rebel-parse dependency from rebel-resolve to rebel
-rw-r--r--Cargo.lock3
-rw-r--r--crates/rebel-parse/Cargo.toml2
-rw-r--r--crates/rebel-parse/src/lib.rs18
-rw-r--r--crates/rebel-resolve/Cargo.toml1
-rw-r--r--crates/rebel-resolve/src/context.rs23
-rw-r--r--crates/rebel/Cargo.toml1
-rw-r--r--crates/rebel/src/main.rs7
7 files changed, 27 insertions, 28 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 540988e..e2b4cee 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -488,6 +488,7 @@ dependencies = [
"lazy_static",
"nix",
"rebel-common",
+ "rebel-parse",
"rebel-resolve",
"rebel-runner",
"serde",
@@ -508,6 +509,7 @@ name = "rebel-parse"
version = "0.1.0"
dependencies = [
"peg",
+ "rebel-common",
]
[[package]]
@@ -517,7 +519,6 @@ dependencies = [
"deb-version",
"enum-kinds",
"rebel-common",
- "rebel-parse",
"serde",
]
diff --git a/crates/rebel-parse/Cargo.toml b/crates/rebel-parse/Cargo.toml
index 29dc1ed..f75e382 100644
--- a/crates/rebel-parse/Cargo.toml
+++ b/crates/rebel-parse/Cargo.toml
@@ -8,4 +8,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+rebel-common = { path = "../rebel-common" }
+
peg = "0.8.2"
diff --git a/crates/rebel-parse/src/lib.rs b/crates/rebel-parse/src/lib.rs
index fa72b42..d9a59cf 100644
--- a/crates/rebel-parse/src/lib.rs
+++ b/crates/rebel-parse/src/lib.rs
@@ -1,15 +1,13 @@
+use rebel_common::types::TaskIDRef;
+
+pub use rules::*;
+
#[derive(Debug, Clone, Copy)]
pub struct TaskRef<'a> {
- pub id: TaskID<'a>,
+ pub id: TaskIDRef<'a>,
pub args: TaskArgs<'a>,
}
-#[derive(Debug, Clone, Copy)]
-pub struct TaskID<'a> {
- pub recipe: &'a str,
- pub task: &'a str,
-}
-
#[derive(Debug, Clone, Copy, Default)]
pub struct TaskArgs<'a> {
pub host: Option<&'a str>,
@@ -37,9 +35,9 @@ peg::parser! {
rule recipe_id() -> &'input str
= $(name() ("/" name())?)
- rule task_id() -> TaskID<'input>
+ rule task_id() -> TaskIDRef<'input>
= recipe:recipe_id() "::" task:name() {
- TaskID { recipe, task }
+ TaskIDRef { recipe, task }
}
rule task_args() -> TaskArgs<'input>
@@ -65,5 +63,3 @@ peg::parser! {
= tag() v:value() { v }
}
}
-
-pub use rules::*;
diff --git a/crates/rebel-resolve/Cargo.toml b/crates/rebel-resolve/Cargo.toml
index 65eae78..4b3e113 100644
--- a/crates/rebel-resolve/Cargo.toml
+++ b/crates/rebel-resolve/Cargo.toml
@@ -9,7 +9,6 @@ edition = "2021"
[dependencies]
rebel-common = { path = "../rebel-common" }
-rebel-parse = { path = "../rebel-parse" }
deb-version = "0.1.1"
enum-kinds = "0.5.1"
diff --git a/crates/rebel-resolve/src/context.rs b/crates/rebel-resolve/src/context.rs
index 88d5deb..996d981 100644
--- a/crates/rebel-resolve/src/context.rs
+++ b/crates/rebel-resolve/src/context.rs
@@ -14,7 +14,6 @@ use rebel_common::{
string_hash::ArchiveHash,
types::TaskIDRef,
};
-use rebel_parse::{self as parse, TaskFlags};
use crate::{
args::*,
@@ -362,16 +361,12 @@ impl Context {
})
}
- pub fn parse(&self, s: &str) -> error::Result<(TaskRef, TaskFlags)> {
- let (parsed, flags) = parse::task_ref_with_flags(s)
- .ok()
- .context("Invalid task syntax")?;
-
- let id = TaskIDRef {
- recipe: parsed.id.recipe,
- task: parsed.id.task,
- };
-
+ pub fn lookup(
+ &self,
+ id: TaskIDRef,
+ host: Option<&str>,
+ target: Option<&str>,
+ ) -> error::Result<TaskRef> {
let (ctx_recipe, recipe_tasks) = self
.tasks
.get_key_value(id.recipe)
@@ -386,7 +381,7 @@ impl Context {
let mut args = self.globals.clone();
- if let Some(host) = parsed.args.host {
+ if let Some(host) = host {
let plat = self
.platforms
.get(host)
@@ -394,7 +389,7 @@ impl Context {
args.set("host", Some(plat));
args.set("target", Some(plat));
}
- if let Some(target) = parsed.args.target {
+ if let Some(target) = target {
let plat = self
.platforms
.get(target)
@@ -406,7 +401,7 @@ impl Context {
.task_ref(ctx_id, &args)
.with_context(|| format!("Failed to instantiate task {}", id))?;
- Ok((task_ref, flags))
+ Ok(task_ref)
}
fn map_args<'ctx, 'args>(
diff --git a/crates/rebel/Cargo.toml b/crates/rebel/Cargo.toml
index e9a399e..9eba0fa 100644
--- a/crates/rebel/Cargo.toml
+++ b/crates/rebel/Cargo.toml
@@ -9,6 +9,7 @@ edition = "2021"
[dependencies]
rebel-common = { path = "../rebel-common" }
+rebel-parse = { path = "../rebel-parse" }
rebel-resolve = { path = "../rebel-resolve" }
rebel-runner = { path = "../rebel-runner" }
diff --git a/crates/rebel/src/main.rs b/crates/rebel/src/main.rs
index fe0671b..214e6ef 100644
--- a/crates/rebel/src/main.rs
+++ b/crates/rebel/src/main.rs
@@ -7,6 +7,7 @@ use std::{collections::HashSet, fs::File, path::Path};
use clap::Parser;
use rebel_common::error::*;
+use rebel_parse as parse;
use rebel_resolve::{self as resolve, context, pin};
use rebel_runner::{self as runner, Runner};
@@ -48,7 +49,11 @@ fn main() {
let mut force_run = HashSet::new();
for task in opts.tasks {
- let (task_ref, flags) = match ctx.parse(&task) {
+ let Ok((parsed, flags)) = parse::task_ref_with_flags(&task) else {
+ eprintln!("Invalid task syntax");
+ std::process::exit(1);
+ };
+ let task_ref = match ctx.lookup(parsed.id, parsed.args.host, parsed.args.target) {
Ok(task_ref) => task_ref,
Err(err) => {
eprintln!("{}", err);