Skip to content

Commit

Permalink
Update spk cli to use workspaces to find spec files
Browse files Browse the repository at this point in the history
Although the concept is largely hidden (aside from the new flags) this
adds the ability to define a workspace in the current directory and
modify the default behavior of only loading spk.yaml files from the
current directory.

Signed-off-by: Ryan Bottriell <[email protected]>
  • Loading branch information
rydrman committed Jan 14, 2025
1 parent 086dad0 commit 4ff5b28
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 283 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ spk-solve-package-iterator = { path = "crates/spk-solve/crates/package-iterator"
spk-solve-solution = { path = "crates/spk-solve/crates/solution" }
spk-solve-validation = { path = "crates/spk-solve/crates/validation" }
spk-storage = { path = "crates/spk-storage" }
spk-workspace = { path = "crates/spk-workspace" }
static_assertions = "1.1"
strip-ansi-escapes = "0.2.0"
strum = { version = "0.26.3", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test:

.PHONY: converters
converters:
$(MAKE) -C packages spk-convert-pip/spk-convert-pip.spk
spk build spk-convert-pip

.PHONY: rpms
rpms: spk-rpm spfs-rpm
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ SPK/SPFS are distributed using the [Apache-2.0 license](LICENSE).

`spk` is the software packaging system built on top of SPFS.

The `packages` directory contains a collection of recipes that can be used as examples or to build out common open source software packages.

## Contributing

Please read [Contributing to SPK](CONTRIBUTING.md).
Expand Down
1 change: 1 addition & 0 deletions crates/spk-cli/cmd-make-recipe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ clap = { workspace = true, features = ["derive", "env"] }
spk-cli-common = { workspace = true }
spk-schema = { workspace = true }
spk-schema-tera = { workspace = true }
spk-workspace = { workspace = true }
tracing = "0.1.35"
22 changes: 10 additions & 12 deletions crates/spk-cli/cmd-make-recipe/src/cmd_make_recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
// https://github.com/spkenv/spk

use std::sync::Arc;

use clap::Args;
use miette::{Context, IntoDiagnostic, Result};
use spk_cli_common::{flags, CommandArgs, Run};
use spk_schema::foundation::format::FormatOptionMap;
use spk_schema::{SpecFileData, SpecTemplate, Template, TemplateExt};
use spk_schema::{SpecFileData, Template};

/// Render a package spec template into a recipe
///
Expand All @@ -20,6 +18,9 @@ pub struct MakeRecipe {
#[clap(flatten)]
pub options: flags::Options,

#[clap(flatten)]
pub workspace: flags::Workspace,

#[clap(short, long, global = true, action = clap::ArgAction::Count)]
pub verbose: u8,

Expand All @@ -44,16 +45,13 @@ impl Run for MakeRecipe {

async fn run(&mut self) -> Result<Self::Output> {
let options = self.options.get_options()?;
let workspace = self.workspace.load_or_default()?;

let template = match flags::find_package_template(self.package.as_ref())? {
flags::FindPackageTemplateResult::NotFound(name) => {
Arc::new(SpecTemplate::from_file(name.as_ref())?)
}
res => {
let (_, template) = res.must_be_found();
template
}
};
let template = match self.package.as_ref() {
None => workspace.default_package_template(),
Some(p) => workspace.find_package_template(p),
}
.must_be_found();

if let Some(name) = template.name() {
tracing::info!("rendering template for {name}");
Expand Down
13 changes: 10 additions & 3 deletions crates/spk-cli/cmd-test/src/cmd_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct CmdTest {
pub runtime: flags::Runtime,
#[clap(flatten)]
pub repos: flags::Repositories,
#[clap(flatten)]
pub workspace: flags::Workspace,

#[clap(short, long, global = true, action = clap::ArgAction::Count)]
pub verbose: u8,
Expand Down Expand Up @@ -73,6 +75,7 @@ impl Run for CmdTest {
.into_iter()
.map(|(_, r)| Arc::new(r))
.collect::<Vec<_>>();
let mut workspace = self.workspace.load_or_default()?;

let source = if self.here { Some(".".into()) } else { None };

Expand Down Expand Up @@ -100,9 +103,13 @@ impl Run for CmdTest {
}
};

let (spec_data, filename) =
flags::find_package_recipe_from_template_or_repo(Some(&name), &options, &repos)
.await?;
let (spec_data, filename) = flags::find_package_recipe_from_workspace_or_repo(
Some(&name),
&options,
&mut workspace,
&repos,
)
.await?;
let recipe = spec_data.into_recipe().wrap_err_with(|| {
format!(
"{filename} was expected to contain a recipe",
Expand Down
1 change: 1 addition & 0 deletions crates/spk-cli/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ spk-exec = { workspace = true }
spk-solve = { workspace = true }
spk-schema = { workspace = true }
spk-storage = { workspace = true }
spk-workspace = { workspace = true }
statsd = { version = "0.15.0", optional = true }
strip-ansi-escapes = { version = "0.1.1", optional = true }
thiserror = { workspace = true }
Expand Down
Loading

0 comments on commit 4ff5b28

Please sign in to comment.