Skip to content

Commit

Permalink
Correct the data model for BuildpackToml (heroku#248)
Browse files Browse the repository at this point in the history
The CNB spec states that a `buildpack.toml` must contain exactly one of the tables
`stacks` or `order`, but not both - since they relate to different buildpack types
(single buildpacks and meta-buildpacks respectively):
https://github.com/buildpacks/spec/blob/main/buildpack.md#buildpack-implementations

Previously `BuildpackToml` attempted to represent both of these as a single type,
which both meant the type wasn't an accurate representation, but also that invalid
`buildpack.toml` files would pass `libcnb package` validation only to fail later at
runtime with a Pack CLI error message.

Now `BuildpackToml` has been replaced with the enum `BuildpackDescriptor`,
which has `Single` and `Meta` variants that wrap new `SingleBuildpackDescriptor`
and `MetaBuildpackDescriptor` types.

Consumers of libcnb-data can now either parse `buildpack.toml` files using
`BuildpackDescriptor` when they wish to support both variants, or else use the
specific sub-types when a specific buildpack type is required for improved error
messages.

Fixes heroku#211.
GUS-W-10289129.
  • Loading branch information
edmorley authored Jan 7, 2022
1 parent 8c15e13 commit c570bb1
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 92 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Remove `LayerContentMetadata::Default()` ([#236](https://github.com/Malax/libcnb.rs/pull/236)).
- Switch `Buildpack.version` from type `semver::Version` to `BuildpackVersion`, in order to validate versions more strictly against the CNB spec ([#241](https://github.com/Malax/libcnb.rs/pull/241)).
- All libcnb-data struct types now reject unrecognised fields when deserializing ([#252](https://github.com/Malax/libcnb.rs/pull/252)).
- `BuildpackToml` has been replaced by `BuildpackDescriptor`, which is an enum with `Single` and `Meta` variants that wrap new `SingleBuildpackDescriptor` and `MetaBuildpackDescriptor` types. The new types now reject `buildpack.toml` files where both `stacks` and `order` are present ([#248](https://github.com/Malax/libcnb.rs/pull/248)).

## [0.4.0] 2021/12/08

Expand Down
8 changes: 5 additions & 3 deletions libcnb-cargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
pub mod cross_compile;

use cargo_metadata::MetadataCommand;
use libcnb_data::buildpack::BuildpackToml;
use libcnb_data::buildpack::SingleBuildpackDescriptor;
use std::ffi::OsStr;
use std::fs;
use std::io;
Expand Down Expand Up @@ -139,7 +139,7 @@ pub enum BuildpackDataError {

pub struct BuildpackData<BM> {
pub buildpack_toml_path: PathBuf,
pub buildpack_toml: BuildpackToml<BM>,
pub buildpack_toml: SingleBuildpackDescriptor<BM>,
}

/// Creates a buildpack directory and copies all buildpack assets to it.
Expand Down Expand Up @@ -202,6 +202,8 @@ fn create_file_symlink<P: AsRef<Path>, Q: AsRef<Path>>(
///
/// This function ensures the resulting name is valid and does not contain problematic characters
/// such as `/`.
pub fn default_buildpack_directory_name<BM>(buildpack_toml: &BuildpackToml<BM>) -> String {
pub fn default_buildpack_directory_name<BM>(
buildpack_toml: &SingleBuildpackDescriptor<BM>,
) -> String {
buildpack_toml.buildpack.id.replace("/", "_")
}
Loading

0 comments on commit c570bb1

Please sign in to comment.