Skip to content

Commit f97a007

Browse files
author
Grant Wuerker
committed
Resolution handler API and ingot graph resolution.
1 parent b187a23 commit f97a007

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1496
-614
lines changed

Cargo.lock

Lines changed: 129 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ tracing = "0.1.41"
3434
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
3535
tracing-tree = "0.4.0"
3636
wasm-bindgen-test = "0.3"
37+
semver = "1.0.26"
3738

3839
[profile.dev]
3940
# Set to 0 to make the build faster and debugging more difficult.

crates/common/src/config.rs

Lines changed: 149 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,155 @@
1-
use serde_semver::semver::Version;
1+
use camino::Utf8PathBuf;
22
use smol_str::SmolStr;
3+
use toml::Value;
34

4-
#[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
5+
use crate::ingot::Version;
6+
7+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
8+
pub struct Config {
9+
pub ingot: IngotMetadata,
10+
pub dependencies: Vec<Dependency>,
11+
pub diagnostics: Vec<ConfigDiagnostics>,
12+
}
13+
14+
impl Config {
15+
pub fn from_string(content: String) -> Self {
16+
let mut diagnostics = Vec::new();
17+
let mut ingot = IngotMetadata::default();
18+
let mut dependencies = Vec::new();
19+
20+
let parsed: Value = match content.parse() {
21+
Ok(v) => v,
22+
Err(_) => {
23+
diagnostics.push(ConfigDiagnostics::UnrecognizedField);
24+
return Self {
25+
ingot,
26+
dependencies,
27+
diagnostics,
28+
};
29+
}
30+
};
31+
32+
// Parse [ingot] section
33+
if let Some(table) = parsed.get("ingot").and_then(|v| v.as_table()) {
34+
if let Some(name_val) = table.get("name") {
35+
match name_val.as_str() {
36+
Some(name) => ingot.name = Some(SmolStr::new(name)),
37+
None => diagnostics.push(ConfigDiagnostics::InvalidName),
38+
}
39+
} else {
40+
diagnostics.push(ConfigDiagnostics::MissingName);
41+
}
42+
43+
if let Some(version_val) = table.get("version") {
44+
match version_val.as_str().and_then(|v| v.parse().ok()) {
45+
Some(ver) => ingot.version = Some(ver),
46+
None => diagnostics.push(ConfigDiagnostics::InvalidVersion),
47+
}
48+
} else {
49+
diagnostics.push(ConfigDiagnostics::MissingVersion);
50+
}
51+
} else {
52+
diagnostics.push(ConfigDiagnostics::MissingName);
53+
diagnostics.push(ConfigDiagnostics::MissingVersion);
54+
}
55+
56+
// Parse [dependencies]
57+
if let Some(deps) = parsed.get("dependencies").and_then(|v| v.as_table()) {
58+
for (alias, value) in deps {
59+
match value {
60+
Value::String(path) => {
61+
dependencies.push(Dependency::path(alias.into(), Utf8PathBuf::from(path)));
62+
}
63+
Value::Table(tbl) => {
64+
let path = tbl.get("path").and_then(|v| v.as_str());
65+
if let Some(path_str) = path {
66+
let mut args = IngotArguments::default();
67+
if let Some(name) = tbl.get("name").and_then(|v| v.as_str()) {
68+
args.name = Some(SmolStr::new(name));
69+
}
70+
if let Some(version_str) = tbl.get("version").and_then(|v| v.as_str()) {
71+
if let Ok(ver) = version_str.parse() {
72+
args.version = Some(ver);
73+
} else {
74+
diagnostics.push(ConfigDiagnostics::InvalidVersion);
75+
}
76+
}
77+
dependencies.push(Dependency::path_with_arguments(
78+
alias.into(),
79+
Utf8PathBuf::from(path.unwrap()),
80+
args,
81+
));
82+
} else {
83+
diagnostics.push(ConfigDiagnostics::InvalidDependencyDescription);
84+
}
85+
}
86+
_ => diagnostics.push(ConfigDiagnostics::InvalidDependencyDescription),
87+
}
88+
}
89+
}
90+
91+
Config {
92+
ingot,
93+
dependencies,
94+
diagnostics,
95+
}
96+
}
97+
}
98+
99+
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
5100
pub struct IngotMetadata {
6101
pub name: Option<SmolStr>,
7102
pub version: Option<Version>,
8103
}
104+
105+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
106+
pub enum DependencyDescription {
107+
Path(Utf8PathBuf),
108+
PathWithArguments {
109+
path: Utf8PathBuf,
110+
arguments: IngotArguments,
111+
},
112+
}
113+
114+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
115+
pub struct Dependency {
116+
pub alias: SmolStr,
117+
pub description: DependencyDescription,
118+
}
119+
120+
impl Dependency {
121+
pub fn path(alias: SmolStr, path: Utf8PathBuf) -> Self {
122+
Self {
123+
alias,
124+
description: DependencyDescription::Path(path),
125+
}
126+
}
127+
128+
pub fn path_with_arguments(
129+
alias: SmolStr,
130+
path: Utf8PathBuf,
131+
arguments: IngotArguments,
132+
) -> Self {
133+
Self {
134+
alias,
135+
description: DependencyDescription::PathWithArguments { path, arguments },
136+
}
137+
}
138+
}
139+
140+
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
141+
pub struct IngotArguments {
142+
pub name: Option<SmolStr>,
143+
pub version: Option<Version>,
144+
}
145+
146+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
147+
pub enum ConfigDiagnostics {
148+
MissingName,
149+
MissingVersion,
150+
InvalidName,
151+
InvalidVersion,
152+
InvalidDependencyAlias,
153+
InvalidDependencyDescription,
154+
UnrecognizedField,
155+
}

0 commit comments

Comments
 (0)