Skip to content

Commit

Permalink
Adds support to spk commands for requests files (#1130)
Browse files Browse the repository at this point in the history
Adds support to spk commands to take a path to yaml files of requests. 

Signed-off-by: David Gilligan-Cook <[email protected]>
  • Loading branch information
dcookspi authored Nov 7, 2024
1 parent d9c1bb4 commit 34f9a80
Show file tree
Hide file tree
Showing 23 changed files with 468 additions and 196 deletions.
3 changes: 2 additions & 1 deletion crates/spk-cli/cmd-env/src/cmd_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ impl Run for Env {

let mut solver = self.solver.get_solver(&self.options).await?;

let requests = self
let (requests, extra_options) = self
.requests
.parse_requests(&self.requested, &self.options, solver.repositories())
.await?;
solver.update_options(extra_options);
for request in requests {
solver.add_request(request)
}
Expand Down
3 changes: 2 additions & 1 deletion crates/spk-cli/cmd-explain/src/cmd_explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ impl Run for Explain {

let mut solver = self.solver.get_solver(&self.options).await?;

let requests = self
let (requests, extra_options) = self
.requests
.parse_requests(&self.requested, &self.options, solver.repositories())
.await?;
solver.update_options(extra_options);
for request in requests {
solver.add_request(request)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/spk-cli/cmd-install/src/cmd_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ impl Run for Install {
current_env().map_err(|err| err.into())
)?;

let requests = self
let (requests, extra_options) = self
.requests
.parse_requests(&self.packages, &self.options, solver.repositories())
.await?;

solver.update_options(extra_options);
for solved in env.items() {
solver.add_request(solved.request.clone().into());
}
Expand Down
8 changes: 7 additions & 1 deletion crates/spk-cli/cmd-make-binary/src/cmd_make_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,18 @@ impl Run for MakeBinary {
(!self.options.no_host).then(|| HOST_OPTIONS.get().unwrap_or_default());

for package in packages {
let (recipe, filename) = flags::find_package_recipe_from_template_or_repo(
let (spec_data, filename) = flags::find_package_recipe_from_template_or_repo(
package.as_ref().map(|p| p.get_specifier()),
&options,
&repos,
)
.await?;
let recipe = spec_data.into_recipe().wrap_err_with(|| {
format!(
"{filename} was expected to contain a recipe",
filename = filename.to_string_lossy()
)
})?;
let ident = recipe.ident();

tracing::info!("saving package recipe for {}", ident.format_ident());
Expand Down
17 changes: 13 additions & 4 deletions crates/spk-cli/cmd-make-recipe/src/cmd_make_recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use clap::Args;
use miette::{Context, IntoDiagnostic, Result};
use spk_cli_common::{flags, CommandArgs, Run};
use spk_schema::foundation::format::FormatOptionMap;
use spk_schema::foundation::spec_ops::Named;
use spk_schema::{SpecTemplate, Template, TemplateExt};
use spk_schema::{SpecFileData, SpecTemplate, Template, TemplateExt};

/// Render a package spec template into a recipe
///
Expand Down Expand Up @@ -56,7 +55,11 @@ impl Run for MakeRecipe {
}
};

tracing::info!("rendering template for {}", template.name());
if let Some(name) = template.name() {
tracing::info!("rendering template for {name}");
} else {
tracing::info!("rendering template without a name");
}
tracing::info!("using options {}", options.format_option_map());
let data = spk_schema::TemplateData::new(&options);
tracing::debug!("full template data: {data:#?}");
Expand All @@ -74,10 +77,16 @@ impl Run for MakeRecipe {
tracing::error!("This template did not render into a valid spec {err}");
Ok(1)
}
Ok(_) => {
Ok(SpecFileData::Recipe(_)) => {
tracing::info!("Successfully rendered a valid spec");
Ok(0)
}
Ok(SpecFileData::Requests(_)) => {
tracing::error!(
"This template did not render into a valid recipe spec. It is a requests spec"
);
Ok(2)
}
}
}
}
25 changes: 17 additions & 8 deletions crates/spk-cli/cmd-make-source/src/cmd_make_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use miette::{bail, Context, Result};
use spk_build::SourcePackageBuilder;
use spk_cli_common::{flags, BuildArtifact, BuildResult, CommandArgs, Run};
use spk_schema::foundation::format::FormatIdent;
use spk_schema::foundation::spec_ops::Named;
use spk_schema::ident::LocatedBuildIdent;
use spk_schema::{Package, Recipe, SpecTemplate, Template, TemplateExt};
use spk_storage as storage;
Expand Down Expand Up @@ -87,19 +86,29 @@ impl MakeSource {
.parent()
.map(ToOwned::to_owned)
.unwrap_or_else(|| std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")));

tracing::info!("rendering template for {}", template.name());
let recipe = template.render(&options)?;
if let Some(name) = template.name() {
tracing::info!("rendering template for {name}");
} else {
tracing::info!("rendering template without a name");
}
let rendered_data = template.render(&options)?;
let recipe = rendered_data.into_recipe().wrap_err_with(|| {
format!(
"{filename} was expected to contain a recipe",
filename = template.file_path().to_string_lossy()
)
})?;
let ident = recipe.ident();

tracing::info!("saving package recipe for {}", ident.format_ident());
local.force_publish_recipe(&recipe).await?;

tracing::info!("collecting sources for {}", ident.format_ident());
let (out, _components) = SourcePackageBuilder::from_recipe(recipe)
.build_and_publish(root, &local)
.await
.wrap_err("Failed to collect sources")?;
let (out, _components) =
SourcePackageBuilder::from_recipe(Arc::unwrap_or_clone(recipe))
.build_and_publish(root, &local)
.await
.wrap_err("Failed to collect sources")?;
tracing::info!("created {}", out.ident().format_ident());
self.created_src.push(
template.file_path().display().to_string(),
Expand Down
3 changes: 2 additions & 1 deletion crates/spk-cli/cmd-render/src/cmd_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ impl Run for Render {
async fn run(&mut self) -> Result<Self::Output> {
let mut solver = self.solver.get_solver(&self.options).await?;

let requests = self
let (requests, extra_options) = self
.requests
.parse_requests(&self.packages, &self.options, solver.repositories())
.await?;
solver.update_options(extra_options);
for name in requests {
solver.add_request(name);
}
Expand Down
8 changes: 7 additions & 1 deletion crates/spk-cli/cmd-test/src/cmd_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,15 @@ impl Run for CmdTest {
}
};

let (recipe, filename) =
let (spec_data, filename) =
flags::find_package_recipe_from_template_or_repo(Some(&name), &options, &repos)
.await?;
let recipe = spec_data.into_recipe().wrap_err_with(|| {
format!(
"{filename} was expected to contain a recipe",
filename = filename.to_string_lossy()
)
})?;

for stage in stages {
tracing::info!("Testing {}@{stage}...", filename.display());
Expand Down
Loading

0 comments on commit 34f9a80

Please sign in to comment.