Skip to content

Commit e76d237

Browse files
committed
refactor(package): expose package config layers
1 parent a37bbe3 commit e76d237

8 files changed

Lines changed: 67 additions & 62 deletions

File tree

‎src/main.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use eb_stack::campaign::{
77
CampaignStatus, FindingResolution,
88
};
99
use eb_stack::package::{StackPolicy, STACK_POLICY_SCHEMA_VERSION};
10-
use eb_stack::package_config::ProfileConfigLayer;
10+
use eb_stack::package_config::PackageConfigLayer;
1111
use eb_stack::target::{doctor_target, resolve_target_layers, BuildTarget, TargetConfigLayer};
1212
use eb_stack::{
1313
check_recipe_deps, format_style, format_style_file, inspect_new_package, lint_style,
@@ -82,8 +82,8 @@ struct PackageInspectArgs {
8282
toolchain_name: String,
8383
#[arg(long)]
8484
toolchain_version: String,
85-
#[arg(long = "profile-config")]
86-
profile_configs: Vec<PathBuf>,
85+
#[arg(long = "package-config")]
86+
package_configs: Vec<PathBuf>,
8787
#[arg(long)]
8888
out_dir: PathBuf,
8989
}
@@ -273,7 +273,7 @@ fn run_package(command: PackageCommand) -> Result<()> {
273273
match command {
274274
PackageCommand::Inspect(args) => {
275275
let toolchain = toolchain(&args.toolchain_name, &args.toolchain_version);
276-
let layers = load_profile_layers(&args.profile_configs)?;
276+
let layers = load_package_layers(&args.package_configs)?;
277277
let (plan, sbom) = inspect_new_package(
278278
&args.source,
279279
parse_format(&args.format)?,
@@ -304,7 +304,7 @@ fn run_package(command: PackageCommand) -> Result<()> {
304304
format: parse_format(&args.inspect.format)?,
305305
toolchain,
306306
source_checksums: args.source_checksums,
307-
profile_layers: load_profile_layers(&args.inspect.profile_configs)?,
307+
package_layers: load_package_layers(&args.inspect.package_configs)?,
308308
easyconfig_roots: args.easyconfigs,
309309
stack_policy,
310310
})?;
@@ -581,11 +581,11 @@ fn parse_format(value: &str) -> Result<Option<ForeignFormat>> {
581581
}
582582
}
583583

584-
fn load_profile_layers(paths: &[PathBuf]) -> Result<Vec<ProfileConfigLayer>> {
584+
fn load_package_layers(paths: &[PathBuf]) -> Result<Vec<PackageConfigLayer>> {
585585
paths
586586
.iter()
587587
.map(|path| {
588-
ProfileConfigLayer::from_path(path)
588+
PackageConfigLayer::from_path(path)
589589
.with_context(|| format!("load profile config {}", path.display()))
590590
})
591591
.collect()

‎src/mcp.rs‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::eb_parse::{
1111
use crate::eb_style::{format_style_file, lint_style};
1212
use crate::foreign::ForeignFormat;
1313
use crate::package::{StackPolicy, STACK_POLICY_SCHEMA_VERSION};
14-
use crate::package_config::ProfileConfigLayer;
14+
use crate::package_config::PackageConfigLayer;
1515
use crate::package_workflow::{
1616
inspect_new_package, plan_new_package, plan_package_bump, write_package_bundle,
1717
BumpPackageRequest, NewPackageRequest, PackageBundle,
@@ -96,14 +96,19 @@ pub fn handle_message(message: &Value) -> Option<Value> {
9696

9797
fn tool_catalog() -> Vec<Value> {
9898
vec![
99-
tool(
99+
tool_with_optional(
100100
"eb_package_inspect",
101101
"Parse a conda-forge or Spack recipe into a canonical build manifest and planned CycloneDX SBOM.",
102102
&[
103103
("source", "string"),
104104
("toolchain_version", "string"),
105105
("out_dir", "string"),
106106
],
107+
&[
108+
("format", "string"),
109+
("toolchain_name", "string"),
110+
("package_configs", "array"),
111+
],
107112
),
108113
tool_with_optional(
109114
"eb_package_plan",
@@ -118,7 +123,7 @@ fn tool_catalog() -> Vec<Value> {
118123
&[
119124
("format", "string"),
120125
("toolchain_name", "string"),
121-
("profile_configs", "array"),
126+
("package_configs", "array"),
122127
("source_checksums", "array"),
123128
],
124129
),
@@ -252,9 +257,9 @@ fn call_tool(name: &str, arguments: &Value) -> Result<Value, String> {
252257
fn package_inspect(arguments: &Value) -> Result<Value, String> {
253258
let source = required_path(arguments, "source")?;
254259
let toolchain = toolchain(arguments)?;
255-
let profiles = profile_layers(arguments)?;
260+
let configs = package_layers(arguments)?;
256261
let (plan, sbom) =
257-
inspect_new_package(&source, foreign_format(arguments)?, &toolchain, &profiles)
262+
inspect_new_package(&source, foreign_format(arguments)?, &toolchain, &configs)
258263
.map_err(|error| error.to_string())?;
259264
let output = required_path(arguments, "out_dir")?;
260265
let written = write_package_bundle(
@@ -283,7 +288,7 @@ fn package_plan(arguments: &Value) -> Result<Value, String> {
283288
format: foreign_format(arguments)?,
284289
toolchain: toolchain(arguments)?,
285290
source_checksums: string_array(arguments, "source_checksums")?,
286-
profile_layers: profile_layers(arguments)?,
291+
package_layers: package_layers(arguments)?,
287292
easyconfig_roots: path_array(arguments, "easyconfigs")?,
288293
stack_policy,
289294
};
@@ -474,11 +479,11 @@ fn load_targets(arguments: &Value) -> Result<Vec<BuildTarget>, String> {
474479
resolve_target_layers(&layers).map_err(|error| error.to_string())
475480
}
476481

477-
fn profile_layers(arguments: &Value) -> Result<Vec<ProfileConfigLayer>, String> {
478-
string_array(arguments, "profile_configs")?
482+
fn package_layers(arguments: &Value) -> Result<Vec<PackageConfigLayer>, String> {
483+
string_array(arguments, "package_configs")?
479484
.iter()
480485
.map(|path| {
481-
ProfileConfigLayer::from_path(Path::new(path)).map_err(|error| error.to_string())
486+
PackageConfigLayer::from_path(Path::new(path)).map_err(|error| error.to_string())
482487
})
483488
.collect()
484489
}

‎src/package_config.rs‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use std::collections::BTreeMap;
66
use std::path::Path;
77
use thiserror::Error;
88

9-
pub const PROFILE_CONFIG_SCHEMA_VERSION: u32 = 1;
9+
pub const PACKAGE_CONFIG_SCHEMA_VERSION: u32 = 1;
1010

1111
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1212
#[serde(deny_unknown_fields)]
13-
pub struct ProfileConfigLayer {
13+
pub struct PackageConfigLayer {
1414
pub schema_version: u32,
1515
#[serde(default, skip_serializing_if = "Option::is_none")]
1616
pub package: Option<PackagePatch>,
@@ -72,26 +72,26 @@ pub struct ProfilePatch {
7272
pub verification_commands: Option<Vec<VerificationCommand>>,
7373
}
7474

75-
impl ProfileConfigLayer {
76-
pub fn from_toml_str(input: &str) -> Result<Self, ProfileConfigError> {
75+
impl PackageConfigLayer {
76+
pub fn from_toml_str(input: &str) -> Result<Self, PackageConfigError> {
7777
let layer: Self = toml::from_str(input)?;
7878
layer.validate()?;
7979
Ok(layer)
8080
}
8181

82-
pub fn from_path(path: &Path) -> Result<Self, ProfileConfigError> {
82+
pub fn from_path(path: &Path) -> Result<Self, PackageConfigError> {
8383
let input = std::fs::read_to_string(path)
84-
.map_err(|error| ProfileConfigError::Io(path.display().to_string(), error))?;
84+
.map_err(|error| PackageConfigError::Io(path.display().to_string(), error))?;
8585
Self::from_toml_str(&input)
8686
}
8787

88-
fn validate(&self) -> Result<(), ProfileConfigError> {
89-
if self.schema_version != PROFILE_CONFIG_SCHEMA_VERSION {
90-
return Err(ProfileConfigError::UnsupportedSchema(self.schema_version));
88+
fn validate(&self) -> Result<(), PackageConfigError> {
89+
if self.schema_version != PACKAGE_CONFIG_SCHEMA_VERSION {
90+
return Err(PackageConfigError::UnsupportedSchema(self.schema_version));
9191
}
9292
for profile in &self.profiles {
9393
if profile.name.trim().is_empty() {
94-
return Err(ProfileConfigError::EmptyProfileName);
94+
return Err(PackageConfigError::EmptyProfileName);
9595
}
9696
}
9797
if self
@@ -100,40 +100,40 @@ impl ProfileConfigLayer {
100100
.and_then(|package| package.name.as_deref())
101101
.is_some_and(|name| name.trim().is_empty())
102102
{
103-
return Err(ProfileConfigError::EmptyPackageName);
103+
return Err(PackageConfigError::EmptyPackageName);
104104
}
105105
if self
106106
.package
107107
.as_ref()
108108
.and_then(|package| package.version.as_deref())
109109
.is_some_and(|version| version.trim().is_empty())
110110
{
111-
return Err(ProfileConfigError::EmptyPackageVersion);
111+
return Err(PackageConfigError::EmptyPackageVersion);
112112
}
113113
if self
114114
.build
115115
.as_ref()
116116
.and_then(|build| build.easyblock.as_deref())
117117
.is_some_and(|easyblock| easyblock.trim().is_empty())
118118
{
119-
return Err(ProfileConfigError::EmptyEasyblock);
119+
return Err(PackageConfigError::EmptyEasyblock);
120120
}
121121
if self
122122
.build
123123
.as_ref()
124124
.and_then(|build| build.moduleclass.as_deref())
125125
.is_some_and(|moduleclass| moduleclass.trim().is_empty())
126126
{
127-
return Err(ProfileConfigError::EmptyModuleclass);
127+
return Err(PackageConfigError::EmptyModuleclass);
128128
}
129129
Ok(())
130130
}
131131
}
132132

133-
pub fn apply_profile_layers(
133+
pub fn apply_package_layers(
134134
plan: &mut PackagePlan,
135-
layers: &[ProfileConfigLayer],
136-
) -> Result<(), ProfileConfigError> {
135+
layers: &[PackageConfigLayer],
136+
) -> Result<(), PackageConfigError> {
137137
for layer in layers {
138138
layer.validate()?;
139139
if let Some(package) = &layer.package {
@@ -183,7 +183,7 @@ pub fn apply_profile_layers(
183183
.iter()
184184
.find(|profile| profile.name == parent)
185185
.cloned()
186-
.ok_or_else(|| ProfileConfigError::MissingParent {
186+
.ok_or_else(|| PackageConfigError::MissingParent {
187187
profile: patch.name.clone(),
188188
parent: parent.to_string(),
189189
})?;
@@ -234,7 +234,7 @@ pub fn apply_profile_layers(
234234
.filter(|profile| profile.default)
235235
.count();
236236
if default_count != 1 {
237-
return Err(ProfileConfigError::DefaultProfileCount(default_count));
237+
return Err(PackageConfigError::DefaultProfileCount(default_count));
238238
}
239239
let stack = plan.build.toolchain.label();
240240
plan.outputs = plan
@@ -249,12 +249,12 @@ pub fn apply_profile_layers(
249249
}
250250

251251
#[derive(Debug, Error)]
252-
pub enum ProfileConfigError {
253-
#[error("unsupported profile config schema version {0}")]
252+
pub enum PackageConfigError {
253+
#[error("unsupported package config schema version {0}")]
254254
UnsupportedSchema(u32),
255-
#[error("profile config TOML: {0}")]
255+
#[error("package config TOML: {0}")]
256256
Toml(#[from] toml::de::Error),
257-
#[error("read profile config {0}: {1}")]
257+
#[error("read package config {0}: {1}")]
258258
Io(String, std::io::Error),
259259
#[error("profile name cannot be empty")]
260260
EmptyProfileName,

‎src/package_workflow.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::package::{
1313
Residual, ResidualSeverity, ResidualStage, SourceArtifact, StackPin, StackPinMode, StackPolicy,
1414
PACKAGE_SCHEMA_VERSION,
1515
};
16-
use crate::package_config::{apply_profile_layers, ProfileConfigLayer};
16+
use crate::package_config::{apply_package_layers, PackageConfigLayer};
1717
use crate::package_emit::{emit_profile_easyconfigs, EmittedEasyconfig};
1818
use crate::package_solve::{solve_package_profile, solve_package_profile_with_hierarchy};
1919
use serde_json::Value;
@@ -28,7 +28,7 @@ pub struct NewPackageRequest {
2828
pub toolchain: Toolchain,
2929
/// Positional SHA-256 overrides, one for every canonical source artifact.
3030
pub source_checksums: Vec<String>,
31-
pub profile_layers: Vec<ProfileConfigLayer>,
31+
pub package_layers: Vec<PackageConfigLayer>,
3232
pub easyconfig_roots: Vec<PathBuf>,
3333
pub stack_policy: StackPolicy,
3434
}
@@ -65,13 +65,13 @@ pub fn inspect_new_package(
6565
source: &Path,
6666
format: Option<ForeignFormat>,
6767
toolchain: &Toolchain,
68-
profile_layers: &[ProfileConfigLayer],
68+
package_layers: &[PackageConfigLayer],
6969
) -> Result<(PackagePlan, Value), PackageWorkflowError> {
7070
let recipe = parse_foreign_path(source, format)
7171
.map_err(|error| PackageWorkflowError::Foreign(error.to_string()))?;
7272
let mut plan = package_plan_from_foreign(&recipe, toolchain);
73-
if !profile_layers.is_empty() {
74-
apply_profile_layers(&mut plan, profile_layers)
73+
if !package_layers.is_empty() {
74+
apply_package_layers(&mut plan, package_layers)
7575
.map_err(|error| PackageWorkflowError::Config(error.to_string()))?;
7676
}
7777
let sbom = package_plan_to_cyclonedx(&plan)
@@ -89,7 +89,7 @@ pub fn plan_new_package(
8989
&request.source,
9090
request.format,
9191
&request.toolchain,
92-
&request.profile_layers,
92+
&request.package_layers,
9393
)?;
9494
if !request.source_checksums.is_empty() {
9595
apply_source_checksums(&mut plan, &request.source_checksums)?;

‎tests/goal_scenario.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! End-to-end acceptance for the two motivating foreign package workflows.
22
33
use eb_stack::package::{StackPolicy, STACK_POLICY_SCHEMA_VERSION};
4-
use eb_stack::package_config::ProfileConfigLayer;
4+
use eb_stack::package_config::PackageConfigLayer;
55
use eb_stack::version::matches_req;
66
use eb_stack::{
77
inspect_new_package, plan_new_package, resolve_easyconfig_file, write_package_bundle,
@@ -84,7 +84,7 @@ fn run_package(
8484
source_checksums: Vec<String>,
8585
) {
8686
let source = repo().join(source);
87-
let profile = ProfileConfigLayer::from_path(&repo().join(profile_config)).expect("profiles");
87+
let profile = PackageConfigLayer::from_path(&repo().join(profile_config)).expect("profiles");
8888
let (inspected, inspected_sbom) = inspect_new_package(
8989
&source,
9090
Some(format),
@@ -105,7 +105,7 @@ fn run_package(
105105
format: Some(format),
106106
toolchain: toolchain(),
107107
source_checksums,
108-
profile_layers: vec![profile],
108+
package_layers: vec![profile],
109109
easyconfig_roots: vec![robot],
110110
stack_policy: policy(),
111111
})

‎tests/manifest_requires_resolvo.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ dependencies = [('zlib', '1.2')]
5454
format: Some(ForeignFormat::CondaForge),
5555
toolchain: toolchain.clone(),
5656
source_checksums: Vec::new(),
57-
profile_layers: Vec::new(),
57+
package_layers: Vec::new(),
5858
easyconfig_roots: vec![robot],
5959
stack_policy: StackPolicy {
6060
schema_version: STACK_POLICY_SCHEMA_VERSION,

0 commit comments

Comments
 (0)