Skip to content

Commit

Permalink
[4/n] add configuration for target presets (#72)
Browse files Browse the repository at this point in the history
Add a `target.preset` table which can be used to define presets for target
configuration. This will be used within omicron-package.

For how this will eventually be used, see
oxidecomputer/omicron#7288.
  • Loading branch information
sunshowers authored Dec 21, 2024
1 parent cf283ea commit ac5c649
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/config/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ impl FromStr for ConfigIdent {
}
}

// The `Deserialize` implementation for `ConfigIdent` must be manually
// implemented, because it must go through validation. The `Serialize`
// implementation can be derived because `ConfigIdent` serializes as a regular
// string.
impl<'de> Deserialize<'de> for ConfigIdent {
fn deserialize<D>(deserializer: D) -> Result<ConfigIdent, D::Error>
where
Expand Down
17 changes: 16 additions & 1 deletion src/config/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::path::Path;
use thiserror::Error;
use topological_sort::TopologicalSort;

use super::PackageName;
use super::{PackageName, PresetName};

/// Describes a set of packages to act upon.
///
Expand Down Expand Up @@ -106,6 +106,10 @@ pub struct Config {
/// Packages to be built and installed.
#[serde(default, rename = "package")]
pub packages: BTreeMap<PackageName, Package>,

/// Target configuration.
#[serde(default)]
pub target: TargetConfig,
}

impl Config {
Expand Down Expand Up @@ -134,6 +138,14 @@ impl Config {
}
}

/// Configuration for targets, including preset configuration.
#[derive(Clone, Deserialize, Debug, Default)]
pub struct TargetConfig {
/// Preset configuration for targets.
#[serde(default, rename = "preset")]
pub presets: BTreeMap<PresetName, TargetMap>,
}

/// Errors which may be returned when parsing the server configuration.
#[derive(Error, Debug)]
pub enum ParseError {
Expand Down Expand Up @@ -187,6 +199,7 @@ mod test {
(pkg_a_name.clone(), pkg_a.clone()),
(pkg_b_name.clone(), pkg_b.clone()),
]),
target: TargetConfig::default(),
};

let mut order = cfg.packages_to_build(&TargetMap::default()).build_order();
Expand Down Expand Up @@ -228,6 +241,7 @@ mod test {
(pkg_a_name.clone(), pkg_a.clone()),
(pkg_b_name.clone(), pkg_b.clone()),
]),
target: TargetConfig::default(),
};

let mut order = cfg.packages_to_build(&TargetMap::default()).build_order();
Expand All @@ -253,6 +267,7 @@ mod test {

let cfg = Config {
packages: BTreeMap::from([(pkg_a_name.clone(), pkg_a.clone())]),
target: TargetConfig::default(),
};

let mut order = cfg.packages_to_build(&TargetMap::default()).build_order();
Expand Down

0 comments on commit ac5c649

Please sign in to comment.