Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ toml = { version = "0.9.8" }
minreq = { version = "2.14.1", features = ["https", "json-using-serde"] }

electrsd = { version = "0.29.0", features = ["legacy"] }
simplicityhl = { version = "0.5.0" }
#simplicityhl = { version = "0.5.0" }
Comment thread
LesterEvSe marked this conversation as resolved.
Outdated
simplicityhl = { git = "https://github.com/LesterEvSe/SimplicityHL.git", branch = "feature/dependency-builder" }

[workspace.lints.rust]
rust_2018_idioms = "warn"
Expand Down
1 change: 1 addition & 0 deletions crates/build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ toml = { workspace = true }
serde = { workspace = true }
simplicityhl = { workspace = true }

regex = "1"
Comment thread
LesterEvSe marked this conversation as resolved.
Outdated
syn = { version = "2.0.114", default-features = false, features = ["proc-macro", "full", "parsing", "derive", "clone-impls", "extra-traits", "printing"] }
proc-macro2 = { version = "1.0.106", features = ["span-locations"] }
quote = { version = "1.0.44" }
Expand Down
49 changes: 49 additions & 0 deletions crates/build/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::fs::OpenOptions;
use std::io::Read;
use std::path::Path;
Expand Down Expand Up @@ -38,3 +39,51 @@ impl Default for BuildConfig {
}
}
}

#[derive(Debug, Default, Clone, Deserialize)]
#[serde(default)]
pub struct DependencyConfig {
Comment thread
LesterEvSe marked this conversation as resolved.
Outdated
#[serde(flatten)]
pub inner: HashMap<String, Dependency>,
}

impl DependencyConfig {
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, BuildError> {
let mut content = String::new();
let mut file = OpenOptions::new().read(true).open(path)?;
file.read_to_string(&mut content)?;

let table: toml::Table = toml::from_str(&content)?;
let res = if let Some(deps_section) = table.get("dependencies") {
deps_section.clone().try_into()?
} else {
DependencyConfig::default()
};

if let Err(err) = res.validate() {
Err(BuildError::InvalidDependency(err))
} else {
Ok(res)
}
}

/// When error occured, returned, return drp_name of the invalid dependency
pub fn validate(&self) -> Result<(), String> {
for (drp_name, dep) in &self.inner {
if dep.path.is_none() && dep.git.is_none() {
return Err(drp_name.clone());
}
}
Ok(())
}
}

#[derive(Debug, Default, Clone, Deserialize)]
#[serde(default)]
pub struct Dependency {
/// Exact path to dir, where `Simplex.toml` file was located
pub path: Option<String>,

/// Link to git repo
pub git: Option<String>,
}
15 changes: 15 additions & 0 deletions crates/build/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ pub enum BuildError {

#[error("Failed to find prefix for a file: {0}")]
NoBasePathForGeneration(#[from] std::path::StripPrefixError),

#[error("Invalid dependency '{0}': you must specify either a 'path' or a 'git' repository")]
InvalidDependency(String),

#[error("Dependency '{dep_name}' is missing its configuration manifest at: {expected_path}")]
MissingDependencyConfig { dep_name: String, expected_path: PathBuf },

#[error("{0}")]
PathCanonicalization(String),

#[error("Failed to build dependency map: {0}")]
DependencyMap(String),

#[error("Failed to flatten program: {0}")]
Flattening(String),
}
Loading
Loading