Skip to content

Commit 77f8db0

Browse files
committed
Replace Spec with RecipeSpec and PackageSpec
This is the first step towards having separate types for the different variations of specs that are valid in specific contexts. These changes will be done in a series of PRs to limit the diff size of each change. In this PR the focus is on embedded packages. In a recipe, an embedded package spec in a recipe spec is expected to be given a `VersionIdent`, as in: ```yaml install: embedded: - pkg: example/1.0.0 ``` It is now illegal to specify a build id for an embedded package in a recipe. When the package is built, the embedded package in a package spec is a `BuildIdent` to reflect the idea that the embedded package is "built", such as: ```yaml install: embedded: - pkg: example/1.0.0/embedded ``` Test content has been updated appropriately since this was not enforced previously. What is allowed in the `build:` and `install:` sections of an embedded package is different from a regular package, so `EmbeddedRecipeSpec` and `EmbeddedPackageSpec` model those differences. These contain `EmbeddedBuildSpec` and `EmbeddedInstallSpec`. An `EmbeddedInstallSpec` does not contain an `embedded` field, making it impossible to nest embedded packages. `EmbeddedPackagesList` gained a generic parameter for the type of spec it contains so it can be reused for the two flavors of embedded specs. `Package::components()` was moved to its own trait to make is possible to not have `Package` implemented for embedded packages. Note that when embedded packages are turned into stubs, the stubs are normal packages that implement `Package`. All the new types were created in the `v0` module since they are part of the `v0/package` API. The types like `BuildSpec` and `InstallSpec` should arguably have been defined in `v0` as well. These new types were created by copying and modifying the existing types (and tests) and I haven't (at this point) done the work to remove duplicate or unused code. Signed-off-by: J Robert Ray <jrray@jrray.org>
1 parent d2855f0 commit 77f8db0

Some content is hidden

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

56 files changed

+3586
-637
lines changed

Cargo.lock

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

crates/spk-build/src/build/binary.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use spk_schema::{
2929
BuildIdent,
3030
ComponentFileMatchMode,
3131
ComponentSpecList,
32+
Components,
3233
InputVariant,
3334
Package,
3435
PackageMut,

crates/spk-build/src/build/binary_test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ use spk_schema::foundation::fixtures::*;
1212
use spk_schema::foundation::ident_component::Component;
1313
use spk_schema::foundation::{opt_name, option_map};
1414
use spk_schema::ident::{PkgRequest, RangeIdent, Request};
15-
use spk_schema::{ComponentSpecList, FromYaml, OptionMap, Package, Recipe, SpecRecipe, recipe};
15+
use spk_schema::{
16+
ComponentSpecList,
17+
Components,
18+
FromYaml,
19+
OptionMap,
20+
Package,
21+
Recipe,
22+
SpecRecipe,
23+
recipe,
24+
};
1625
use spk_solve::{Solution, SolverImpl};
1726
use spk_storage::fixtures::*;
1827
use spk_storage::{self as storage, Repository};

crates/spk-build/src/build/sources_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async fn test_sources_subdir(tmpdir: tempfile::TempDir) {
119119
let file_source = LocalSource::new(source_file).set_subdir("local");
120120

121121
let dest_dir = rt.tmpdir.path().join("dest");
122-
let mut spec = v0::Spec::new("test-pkg/1.0.0/src".parse().unwrap());
122+
let mut spec = v0::PackageSpec::new("test-pkg/1.0.0/src".parse().unwrap());
123123
spec.sources = vec![
124124
SourceSpec::Git(git_source),
125125
SourceSpec::Tar(tar_source),
@@ -145,7 +145,7 @@ async fn test_sources_subdir(tmpdir: tempfile::TempDir) {
145145
#[tokio::test]
146146
async fn test_sources_environment(_tmpdir: tempfile::TempDir) {
147147
let rt = spfs_runtime().await;
148-
let mut spec = v0::Spec::new(build_ident!("sources-test/0.1.0/src"));
148+
let mut spec = v0::PackageSpec::new(build_ident!("sources-test/0.1.0/src"));
149149
let expected = [
150150
"SPK_PKG=sources-test/0.1.0/src",
151151
"SPK_PKG_NAME=sources-test",

crates/spk-build/src/validation/alter_existing_files_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::validation::Validator;
1212

1313
#[tokio::test]
1414
async fn test_validate_build_changeset_modified() {
15-
let package = v0::Spec::new("test-pkg/1.0.0/3I42H3S6".parse().unwrap());
15+
let package = v0::PackageSpec::new("test-pkg/1.0.0/3I42H3S6".parse().unwrap());
1616
let report = BuildReport {
1717
output: BuildOutputReport {
1818
collected_changes: vec![spfs::tracking::Diff {

crates/spk-build/src/validation/collect_all_files_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::validation::Validator;
1212

1313
#[tokio::test]
1414
async fn test_validate_build_changeset_collected() {
15-
let mut package = v0::Spec::new("test-pkg/1.0.0/3I42H3S6".parse().unwrap());
15+
let mut package = v0::PackageSpec::new("test-pkg/1.0.0/3I42H3S6".parse().unwrap());
1616
// the default components are added and collect all files,
1717
// so we remove them to ensure nothing is collected
1818
let _ = package.install.components.drain(..);

crates/spk-build/src/validation/collect_existing_files_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::validation::Validator;
1212

1313
#[tokio::test]
1414
async fn test_validate_build_changeset_collect_existing() {
15-
let dependency_package = v0::Spec::new("dep-pkg/1.0.0/3I42H3S6".parse().unwrap());
16-
let package = v0::Spec::new("test-pkg/1.0.0/3I42H3S6".parse().unwrap());
15+
let dependency_package = v0::PackageSpec::new("dep-pkg/1.0.0/3I42H3S6".parse().unwrap());
16+
let package = v0::PackageSpec::new("test-pkg/1.0.0/3I42H3S6".parse().unwrap());
1717

1818
let mut environment_filesystem = Manifest::new(
1919
spfs::tracking::Entry::empty_dir_with_open_perms_with_data(package.ident().clone()),

crates/spk-build/src/validation/empty_package_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::validation::Validator;
1212

1313
#[tokio::test]
1414
async fn test_validate_build_changeset_nothing() {
15-
let package = v0::Spec::new("test-pkg/1.0.0/3I42H3S6".parse().unwrap());
15+
let package = v0::PackageSpec::new("test-pkg/1.0.0/3I42H3S6".parse().unwrap());
1616
let report = BuildReport {
1717
setup: BuildSetupReport {
1818
environment: Solution::default(),

crates/spk-exec/src/exec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use spfs::graph::object::EncodingFormat;
1313
use spfs::prelude::*;
1414
use spfs::sync::reporter::SyncReporters;
1515
use spfs::tracking::{Entry, EntryKind};
16-
use spk_schema::Spec;
1716
use spk_schema::foundation::format::{FormatIdent, FormatOptionMap};
1817
use spk_schema::foundation::ident_component::Component;
1918
use spk_schema::prelude::*;
19+
use spk_schema::{Components, Spec};
2020
use spk_solve::solution::{PackageSource, SPK_SOLVE_EXTRA_DATA_KEY, Solution};
2121
use spk_solve::{BuildIdent, RepositoryHandle};
2222
use spk_storage as storage;

crates/spk-schema/src/build_spec.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl IsDefault for AutoHostVars {
134134
}
135135

136136
/// A set of structured inputs used to build a package.
137-
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
137+
#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
138138
pub struct BuildSpec {
139139
pub script: Script,
140140
#[serde(default, skip_serializing_if = "Vec::is_empty")]
@@ -152,19 +152,6 @@ pub struct BuildSpec {
152152
pub auto_host_vars: AutoHostVars,
153153
}
154154

155-
impl Default for BuildSpec {
156-
fn default() -> Self {
157-
Self {
158-
script: Script(vec!["sh ./build.sh".into()]),
159-
options: Vec::new(),
160-
raw_variants: Vec::new(),
161-
variants: Vec::new(),
162-
validation: ValidationSpec::default(),
163-
auto_host_vars: AutoHostVars::default(),
164-
}
165-
}
166-
}
167-
168155
impl BuildSpec {
169156
/// Returns this build's options, plus any additional ones needed
170157
/// for building the given variant
@@ -342,6 +329,20 @@ impl IsDefault for BuildSpec {
342329
}
343330
}
344331

332+
impl From<v0::EmbeddedBuildSpec> for BuildSpec {
333+
fn from(value: v0::EmbeddedBuildSpec) -> Self {
334+
BuildSpec {
335+
options: value.options,
336+
// Other fields are not part of the embedded build spec
337+
auto_host_vars: Default::default(),
338+
raw_variants: Default::default(),
339+
script: Script::default(),
340+
validation: Default::default(),
341+
variants: Default::default(),
342+
}
343+
}
344+
}
345+
345346
impl TryFrom<UncheckedBuildSpec> for BuildSpec {
346347
type Error = crate::Error;
347348

@@ -527,6 +528,12 @@ impl Script {
527528
}
528529
}
529530

531+
impl Default for Script {
532+
fn default() -> Self {
533+
Self(vec!["sh ./build.sh".into()])
534+
}
535+
}
536+
530537
impl From<Vec<String>> for Script {
531538
fn from(v: Vec<String>) -> Self {
532539
Self(v)

0 commit comments

Comments
 (0)