Skip to content

Commit

Permalink
introduce "meta" fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Feb 13, 2024
1 parent a7f529f commit 670430f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
8 changes: 8 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern crate serde_yaml;

use indexmap::{IndexMap, IndexSet};
use itertools::Itertools;
use serde_yaml::Value;
use std::collections::{HashMap, HashSet};
use std::fs::read_to_string;
use std::time::Instant;
Expand Down Expand Up @@ -90,6 +91,8 @@ struct YamlFile {
included_by: Option<usize>,
#[serde(skip)]
import_root: Option<ImportRoot>,
#[serde(rename = "meta")]
_meta: Option<Value>,
}

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -106,6 +109,8 @@ struct YamlContext {
tasks: Option<HashMap<String, Task>>,
#[serde(skip)]
_is_builder: bool,
#[serde(rename = "meta")]
_meta: Option<Value>,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -143,6 +148,8 @@ struct YamlModule {
is_global_build_dep: bool,
#[serde(skip)]
_is_binary: bool,
#[serde(rename = "meta")]
_meta: Option<Value>,
}

impl YamlModule {
Expand All @@ -168,6 +175,7 @@ impl YamlModule {
is_build_dep: false,
is_global_build_dep: false,
_is_binary: is_binary,
_meta: None,
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/model/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::collections::HashMap;
use std::convert::From;
use std::hash::{Hash, Hasher};

use serde_yaml::Value;

use crate::serde_bool_helpers::default_as_false;

#[derive(Debug, Serialize, Deserialize, Eq, Clone)]
Expand All @@ -26,6 +28,9 @@ pub struct Rule {

#[serde(default = "default_as_false")]
pub always: bool,

#[serde(rename = "meta")]
_meta: Option<Value>,
}

impl Rule {
Expand Down
54 changes: 29 additions & 25 deletions src/model/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::path::Path;

use anyhow::{Error, Result};
use serde_yaml::Value;

use crate::nested_env;
use crate::serde_bool_helpers::{default_as_false, default_as_true};
Expand All @@ -19,6 +20,8 @@ pub struct Task {
build: bool,
#[serde(default = "default_as_false")]
ignore_ctrl_c: bool,
#[serde(rename = "meta")]
_meta: Option<Value>,
}

impl Task {
Expand Down Expand Up @@ -96,6 +99,7 @@ impl Task {
} else {
self.export.clone()
},
_meta: None,
})
}

Expand All @@ -122,30 +126,30 @@ impl Task {
//
// ... to export `FOO=value`, `BAR=bar` and `FOOBAR=other_value`.

self.export.as_ref().map(|exports| exports
.iter()
.map(|entry| match entry {
StringOrMapString::String(s) => {
StringOrMapString::Map(HashMap::from_iter([(
s.clone(),
nested_env::expand_eval(
format!("${{{s}}}"),
env,
nested_env::IfMissing::Empty,
)
.unwrap(),
)]))
}
StringOrMapString::Map(m) => {
StringOrMapString::Map(HashMap::from_iter(m.iter().map(|(k, v)| {
(
k.clone(),
nested_env::expand_eval(v, env, nested_env::IfMissing::Empty)
.unwrap(),
)
})))
}
})
.collect())
self.export.as_ref().map(|exports| {
exports
.iter()
.map(|entry| match entry {
StringOrMapString::String(s) => StringOrMapString::Map(HashMap::from_iter([(
s.clone(),
nested_env::expand_eval(
format!("${{{s}}}"),
env,
nested_env::IfMissing::Empty,
)
.unwrap(),
)])),
StringOrMapString::Map(m) => {
StringOrMapString::Map(HashMap::from_iter(m.iter().map(|(k, v)| {
(
k.clone(),
nested_env::expand_eval(v, env, nested_env::IfMissing::Empty)
.unwrap(),
)
})))
}
})
.collect()
})
}
}

0 comments on commit 670430f

Please sign in to comment.