Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The last commit here fails to compile pushing it here to reference from an issue #369

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = ["buildpacks/ruby", "commons"]

[workspace.package]
edition = "2021"
rust-version = "1.80"
rust-version = "1.82"

[workspace.lints.rust]
unreachable_pub = "warn"
Expand Down
1 change: 1 addition & 0 deletions buildpacks/ruby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ureq = { version = "2", default-features = false, features = ["tls"] }
url = "2"
magic_migrate = "0.2"
toml = "0.8"
cache_diff = { version = "1.0.0", features = ["bullet_stream"] }

[dev-dependencies]
libcnb-test = "=0.26.1"
26 changes: 11 additions & 15 deletions buildpacks/ruby/src/layers/bundle_download_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::RubyBuildpack;
use crate::RubyBuildpackError;
use bullet_stream::state::SubBullet;
use bullet_stream::{style, Print};
use cache_diff::CacheDiff;
use commons::gemfile_lock::ResolvedBundlerVersion;
use fun_run::{self, CommandWithName};
use libcnb::data::layer_name;
Expand Down Expand Up @@ -59,20 +60,13 @@ try_migrate_deserializer_chain!(

impl MetadataDiff for Metadata {
fn diff(&self, other: &Self) -> Vec<String> {
let mut differences = Vec::new();
if self.version != other.version {
differences.push(format!(
"Bundler version ({old} to {now})",
old = style::value(other.version.to_string()),
now = style::value(self.version.to_string())
));
}
differences
<Self as CacheDiff>::diff(self, other)
}
}

#[derive(Deserialize, Serialize, Debug, Clone)]
#[derive(Deserialize, Serialize, Debug, Clone, CacheDiff)]
pub(crate) struct MetadataV1 {
#[cache_diff(rename = "Bundler version")]
pub(crate) version: ResolvedBundlerVersion,
}

Expand Down Expand Up @@ -141,12 +135,14 @@ mod test {
let old = Metadata {
version: ResolvedBundlerVersion("2.3.5".to_string()),
};
assert!(old.diff(&old).is_empty());
assert!(CacheDiff::diff(&old, &old).is_empty());

let diff = Metadata {
version: ResolvedBundlerVersion("2.3.6".to_string()),
}
.diff(&old);
let diff = CacheDiff::diff(
&Metadata {
version: ResolvedBundlerVersion("2.3.6".to_string()),
},
&old,
);
assert_eq!(
diff.iter().map(strip_ansi).collect::<Vec<String>>(),
vec!["Bundler version (`2.3.5` to `2.3.6`)"]
Expand Down
25 changes: 24 additions & 1 deletion buildpacks/ruby/src/layers/bundle_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub(crate) fn handle(

pub(crate) type Metadata = MetadataV2;
try_migrate_deserializer_chain!(
chain: [MetadataV1, MetadataV2],
chain: [MetadataV1, MetadataV2, MetadataV3],
error: MetadataMigrateError,
deserializer: toml::Deserializer::new,
);
Expand Down Expand Up @@ -176,6 +176,15 @@ pub(crate) struct MetadataV2 {
pub(crate) cpu_architecture: String,
pub(crate) ruby_version: ResolvedRubyVersion,
pub(crate) force_bundle_install_key: String,
pub(crate) digest: MetadataDigest, // Must be last for serde to be happy https://github.com/toml-rs/toml-rs/issues/142
}

#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
pub(crate) struct MetadataV3 {
pub(crate) os_distribution: String,
pub(crate) cpu_architecture: String,
pub(crate) ruby_version: ResolvedRubyVersion,
pub(crate) force_bundle_install_key: String,

/// A struct that holds the cryptographic hash of components that can
/// affect the result of `bundle install`. When these values do not
Expand Down Expand Up @@ -217,6 +226,20 @@ impl TryFrom<MetadataV1> for MetadataV2 {
}
}

impl TryFrom<MetadataV2> for MetadataV3 {
type Error = Infallible;

fn try_from(v2: MetadataV2) -> Result<Self, Self::Error> {
Ok(Self {
os_distribution: format!("{} {}", v2.distro_name, v2.distro_version),
cpu_architecture: v2.cpu_architecture,
ruby_version: v2.ruby_version,
force_bundle_install_key: v2.force_bundle_install_key,
digest: v2.digest,
})
}
}

#[derive(Debug)]
enum InstallState {
/// Holds message indicating the reason why we want to run 'bundle install'
Expand Down
Loading