Skip to content

Commit dc13a1a

Browse files
committed
docs(package): describe the stack policy, solve outcome, and lock types
The types a site operator and a lock reader deal with. Each says what it is for rather than restating its name: an exclusion carries a reason so a reader is not left guessing why an obvious candidate was skipped, a pin outcome records that only a Preferred pin can fall back because a Locked one fails the solve instead, and a locked dependency flags build-only so the runtime closure can be told from the build closure.
1 parent 3c9b23a commit dc13a1a

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

‎src/package.rs‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,134 +21,207 @@ use std::path::PathBuf;
2121
use std::str::FromStr;
2222
use thiserror::Error;
2323

24+
/// Schema version of a package plan document.
2425
pub const PACKAGE_SCHEMA_VERSION: u32 = 1;
26+
/// Schema version of a per-profile dependency lock.
2527
pub const PROFILE_LOCK_SCHEMA_VERSION: u32 = 1;
28+
/// Schema version of a stack policy document.
2629
pub const STACK_POLICY_SCHEMA_VERSION: u32 = 1;
2730

2831
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
2932
#[serde(rename_all = "kebab-case")]
33+
/// How strictly a stack pin binds the solve.
3034
pub enum StackPinMode {
35+
/// Take this version when it is available, otherwise fall back and say so.
3136
Preferred,
37+
/// Take this version or fail; no fallback is acceptable.
3238
Locked,
3339
}
3440

3541
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3642
#[serde(deny_unknown_fields)]
43+
/// A version constraint the site imposes on one dependency.
3744
pub struct StackPin {
45+
/// Package the pin applies to.
3846
pub name: String,
47+
/// Version requirement, e.g. an exact version or a range.
3948
pub version_requirement: String,
4049
#[serde(default, skip_serializing_if = "Option::is_none")]
50+
/// Restrict the pin to one toolchain. `None` matches any.
4151
pub toolchain: Option<Toolchain>,
4252
#[serde(default, skip_serializing_if = "Option::is_none")]
53+
/// Restrict the pin to one versionsuffix. `None` matches any.
4354
pub versionsuffix: Option<String>,
55+
/// Whether a fallback is permitted when the pin cannot be met.
4456
pub mode: StackPinMode,
4557
#[serde(default, skip_serializing_if = "Option::is_none")]
58+
/// Where the pin came from, carried through for auditability.
4659
pub source: Option<String>,
4760
}
4861

4962
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5063
#[serde(deny_unknown_fields)]
64+
/// A candidate the solve must not choose, and why.
5165
pub struct CandidateExclusion {
66+
/// Package excluded.
5267
pub name: String,
68+
/// Versions excluded, as a requirement expression.
5369
pub version_requirement: String,
70+
/// Why it is excluded. Recorded in the lock so a reader is not left
71+
/// guessing why an obvious candidate was skipped.
5472
pub reason: String,
5573
#[serde(default, skip_serializing_if = "Option::is_none")]
74+
/// Where the exclusion applies, when it is not global.
5675
pub scope: Option<String>,
5776
}
5877

5978
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6079
#[serde(deny_unknown_fields)]
80+
/// Site rules a dependency solve must respect.
6181
pub struct StackPolicy {
82+
/// Must equal [`STACK_POLICY_SCHEMA_VERSION`].
6283
pub schema_version: u32,
84+
/// Policy name, for messages and provenance.
6385
pub name: String,
86+
/// Toolchain generation the policy governs.
6487
pub toolchain: Toolchain,
6588
#[serde(default)]
89+
/// Version constraints imposed on individual packages.
6690
pub pins: Vec<StackPin>,
6791
#[serde(default)]
92+
/// Candidates the solve must not choose.
6893
pub exclusions: Vec<CandidateExclusion>,
6994
}
7095

7196
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7297
#[serde(deny_unknown_fields)]
98+
/// What a pin actually achieved, recorded per solve.
7399
pub struct StackPinOutcome {
100+
/// Package the pin named.
74101
pub name: String,
102+
/// Version requirement as requested.
75103
pub requested: String,
76104
#[serde(default, skip_serializing_if = "Option::is_none")]
105+
/// Toolchain requested, when the pin restricted one.
77106
pub requested_toolchain: Option<Toolchain>,
78107
#[serde(default, skip_serializing_if = "Option::is_none")]
108+
/// Versionsuffix requested, when the pin restricted one.
79109
pub requested_versionsuffix: Option<String>,
110+
/// Version chosen. `None` when nothing satisfied the pin.
80111
pub selected_version: Option<String>,
81112
#[serde(default, skip_serializing_if = "Option::is_none")]
113+
/// Toolchain of the chosen candidate.
82114
pub selected_toolchain: Option<Toolchain>,
83115
#[serde(default, skip_serializing_if = "Option::is_none")]
116+
/// Versionsuffix of the chosen candidate.
84117
pub selected_versionsuffix: Option<String>,
118+
/// Whether the solve had to fall back off the pin. Only a `Preferred`
119+
/// pin can reach this; a `Locked` pin fails the solve instead.
85120
pub fallback: bool,
86121
#[serde(default, skip_serializing_if = "Option::is_none")]
122+
/// Why the fallback happened, when one did.
87123
pub fallback_reason: Option<String>,
88124
}
89125

90126
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
91127
#[serde(deny_unknown_fields)]
128+
/// The result of applying a stack policy to a candidate set.
92129
pub struct StackPolicySolve {
130+
/// Candidates the policy allows, after pins and exclusions.
93131
pub selected: Vec<Candidate>,
132+
/// One outcome per pin, including the ones that fell back.
94133
pub pin_outcomes: Vec<StackPinOutcome>,
134+
/// Exclusions that were applied, echoed for the lock.
95135
pub exclusions: Vec<CandidateExclusion>,
96136
}
97137

98138
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
99139
#[serde(deny_unknown_fields)]
140+
/// The conditions a profile evaluates against.
100141
pub struct ProfileEnvironment {
101142
#[serde(default)]
143+
/// Feature flags per dependency, keyed by dependency then flag.
102144
pub dependency_features: BTreeMap<String, BTreeMap<String, bool>>,
103145
#[serde(default, skip_serializing_if = "Option::is_none")]
146+
/// Compiler in play, when a condition depends on it.
104147
pub compiler: Option<NamedVersion>,
105148
#[serde(default, skip_serializing_if = "Option::is_none")]
149+
/// Target platform, when a condition depends on it.
106150
pub platform: Option<String>,
107151
#[serde(default, skip_serializing_if = "Option::is_none")]
152+
/// Target architecture, when a condition depends on it.
108153
pub architecture: Option<String>,
109154
#[serde(default)]
155+
/// Free-form variables conditions may test.
110156
pub variables: BTreeMap<String, String>,
111157
}
112158

113159
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
114160
#[serde(deny_unknown_fields)]
161+
/// One profile with every condition resolved: what will actually be built.
115162
pub struct MaterializedProfile {
163+
/// Package identity and metadata.
116164
pub package: PackageMetadata,
165+
/// Build system and easyconfig parameters.
117166
pub build: BuildSpec,
167+
/// Source artifacts this profile downloads.
118168
pub sources: Vec<SourceArtifact>,
169+
/// The profile this was materialized from.
119170
pub profile: ProductProfile,
171+
/// Concatenated versionsuffix for the emitted recipe.
120172
pub versionsuffix: String,
173+
/// Dependencies whose conditions held for this profile.
121174
pub dependencies: Vec<DependencyIntent>,
175+
/// Rules whose conditions held for this profile.
122176
pub rules: Vec<PackageRule>,
123177
}
124178

125179
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
126180
#[serde(deny_unknown_fields)]
181+
/// One dependency as resolved into a lock.
127182
pub struct LockedDependency {
183+
/// Package name.
128184
pub name: String,
185+
/// Version selected.
129186
pub version: String,
130187
#[serde(default, skip_serializing_if = "Option::is_none")]
188+
/// Versionsuffix of the selected variant, when it has one.
131189
pub versionsuffix: Option<String>,
190+
/// Toolchain the selected easyconfig builds against.
132191
pub toolchain: Toolchain,
192+
/// Easyconfig the selection came from.
133193
pub easyconfig_path: String,
194+
/// True for a build-time-only dependency, so a consumer can tell the
195+
/// runtime closure from the build closure.
134196
pub build: bool,
135197
}
136198

137199
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
138200
#[serde(deny_unknown_fields)]
201+
/// The reproducible dependency selection for one profile.
139202
pub struct ProfileLock {
203+
/// Must equal [`PROFILE_LOCK_SCHEMA_VERSION`].
140204
pub schema_version: u32,
205+
/// Package this lock belongs to.
141206
pub package: String,
207+
/// Package version.
142208
pub version: String,
209+
/// Profile name.
143210
pub profile: String,
211+
/// Toolchain the profile targets.
144212
pub toolchain: Toolchain,
213+
/// Versionsuffix of the emitted recipe.
145214
pub versionsuffix: String,
146215
#[serde(default)]
216+
/// Every dependency selected, build and runtime alike.
147217
pub dependencies: Vec<LockedDependency>,
148218
#[serde(default)]
219+
/// What each policy pin achieved.
149220
pub pin_outcomes: Vec<StackPinOutcome>,
150221
#[serde(default)]
222+
/// Exclusions the policy applied.
151223
pub exclusions: Vec<CandidateExclusion>,
224+
/// Solver that produced the lock.
152225
pub solver: String,
153226
}
154227

0 commit comments

Comments
 (0)