Skip to content

Commit

Permalink
Revert "[2/n] add newtype wrappers to ensure config identifier validi…
Browse files Browse the repository at this point in the history
…ty (#69)"

This reverts commit d0ecc79.
  • Loading branch information
sunshowers authored Dec 21, 2024
1 parent d0ecc79 commit 0f038f5
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 460 deletions.
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,3 @@ tokio = { version = "1.26", features = [ "full" ] }
toml = "0.7.3"
topological-sort = "0.2.2"
walkdir = "2.3"

[dev-dependencies]
proptest = "1.6.0"
test-strategy = "0.4.0"
34 changes: 15 additions & 19 deletions src/config/imp.rs → src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ use std::path::Path;
use thiserror::Error;
use topological_sort::TopologicalSort;

use super::PackageName;

/// Describes a set of packages to act upon.
///
/// This structure maps "package name" to "package"
pub struct PackageMap<'a>(pub BTreeMap<&'a PackageName, &'a Package>);
pub struct PackageMap<'a>(pub BTreeMap<&'a String, &'a Package>);

// The name of a file which should be created by building a package.
#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
Expand Down Expand Up @@ -70,12 +68,12 @@ impl<'a> PackageMap<'a> {
///
/// Returns packages in batches that may be built concurrently.
pub struct PackageDependencyIter<'a> {
lookup_by_output: BTreeMap<OutputFile, (&'a PackageName, &'a Package)>,
lookup_by_output: BTreeMap<OutputFile, (&'a String, &'a Package)>,
outputs: TopologicalSort<OutputFile>,
}

impl<'a> Iterator for PackageDependencyIter<'a> {
type Item = Vec<(&'a PackageName, &'a Package)>;
type Item = Vec<(&'a String, &'a Package)>;

fn next(&mut self) -> Option<Self::Item> {
if self.outputs.is_empty() {
Expand All @@ -101,11 +99,11 @@ impl<'a> Iterator for PackageDependencyIter<'a> {
}

/// Describes the configuration for a set of packages.
#[derive(Clone, Deserialize, Debug)]
#[derive(Deserialize, Debug)]
pub struct Config {
/// Packages to be built and installed.
#[serde(default, rename = "package")]
pub packages: BTreeMap<PackageName, Package>,
pub packages: BTreeMap<String, Package>,
}

impl Config {
Expand Down Expand Up @@ -156,24 +154,22 @@ pub fn parse<P: AsRef<Path>>(path: P) -> Result<Config, ParseError> {

#[cfg(test)]
mod test {
use crate::config::ServiceName;

use super::*;

#[test]
fn test_order() {
let pkg_a_name = PackageName::new_const("pkg-a");
let pkg_a_name = String::from("pkg-a");
let pkg_a = Package {
service_name: ServiceName::new_const("a"),
service_name: String::from("a"),
source: PackageSource::Manual,
output: PackageOutput::Tarball,
only_for_targets: None,
setup_hint: None,
};

let pkg_b_name = PackageName::new_const("pkg-b");
let pkg_b_name = String::from("pkg-b");
let pkg_b = Package {
service_name: ServiceName::new_const("b"),
service_name: String::from("b"),
source: PackageSource::Composite {
packages: vec![pkg_a.get_output_file(&pkg_a_name)],
},
Expand Down Expand Up @@ -202,10 +198,10 @@ mod test {
#[test]
#[should_panic(expected = "cyclic dependency in package manifest")]
fn test_cyclic_dependency() {
let pkg_a_name = PackageName::new_const("pkg-a");
let pkg_b_name = PackageName::new_const("pkg-b");
let pkg_a_name = String::from("pkg-a");
let pkg_b_name = String::from("pkg-b");
let pkg_a = Package {
service_name: ServiceName::new_const("a"),
service_name: String::from("a"),
source: PackageSource::Composite {
packages: vec![String::from("pkg-b.tar")],
},
Expand All @@ -214,7 +210,7 @@ mod test {
setup_hint: None,
};
let pkg_b = Package {
service_name: ServiceName::new_const("b"),
service_name: String::from("b"),
source: PackageSource::Composite {
packages: vec![String::from("pkg-a.tar")],
},
Expand All @@ -240,9 +236,9 @@ mod test {
#[test]
#[should_panic(expected = "Could not find a package which creates 'pkg-b.tar'")]
fn test_missing_dependency() {
let pkg_a_name = PackageName::new_const("pkg-a");
let pkg_a_name = String::from("pkg-a");
let pkg_a = Package {
service_name: ServiceName::new_const("a"),
service_name: String::from("a"),
source: PackageSource::Composite {
packages: vec![String::from("pkg-b.tar")],
},
Expand Down
Loading

0 comments on commit 0f038f5

Please sign in to comment.