From 5d45679b7892cf1370fd0ba3b12cbe361eb9b27d Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 10:56:04 -0500 Subject: [PATCH 01/39] Remove section logger from bundle list --- buildpacks/ruby/src/gem_list.rs | 10 ++-------- buildpacks/ruby/src/main.rs | 14 +++++++------- buildpacks/ruby/src/steps/get_default_process.rs | 6 +----- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/buildpacks/ruby/src/gem_list.rs b/buildpacks/ruby/src/gem_list.rs index 33ba1102..1ebd4968 100644 --- a/buildpacks/ruby/src/gem_list.rs +++ b/buildpacks/ruby/src/gem_list.rs @@ -1,8 +1,5 @@ use commons::gem_version::GemVersion; -use commons::output::{ - fmt, - section_log::{log_step_timed, SectionLogger}, -}; +use commons::output::{fmt, section_log::log_step_timed}; use core::str::FromStr; use fun_run::{CmdError, CommandWithName}; use regex::Regex; @@ -59,10 +56,7 @@ impl GemList { /// # Errors /// /// Errors if the command `bundle list` is unsuccessful. - pub(crate) fn from_bundle_list( - envs: T, - _logger: &dyn SectionLogger, - ) -> Result + pub(crate) fn from_bundle_list(envs: T) -> Result where T: IntoIterator, K: AsRef, diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index a20ce457..6136876d 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -114,7 +114,7 @@ impl Buildpack for RubyBuildpack { #[allow(deprecated)] fn build(&self, context: BuildContext) -> libcnb::Result { let mut build_output = Print::new(stdout()).h2("Heroku Ruby Buildpack"); - let logger = BuildLog::new(stdout()).without_buildpack_name(); + let mut logger = BuildLog::new(stdout()).without_buildpack_name(); let warn_later = WarnGuard::new(stdout()); // ## Set default environment @@ -185,7 +185,7 @@ impl Buildpack for RubyBuildpack { }; // ## Bundle install - (_, env) = { + (build_output, env) = { let bullet = build_output.bullet("Bundle install gems"); let (bullet, layer_env) = layers::bundle_install_layer::handle( &context, @@ -219,14 +219,14 @@ impl Buildpack for RubyBuildpack { }; // ## Detect gems - let (mut logger, gem_list, default_process) = { - let section = logger.section("Setting default processes"); + let (_, gem_list, default_process) = { + let bullet = build_output.bullet("Setting default processes"); - let gem_list = gem_list::GemList::from_bundle_list(&env, section.as_ref()) + let gem_list = gem_list::GemList::from_bundle_list(&env) .map_err(RubyBuildpackError::GemListGetError)?; - let default_process = steps::get_default_process(section.as_ref(), &context, &gem_list); + let default_process = steps::get_default_process(&context, &gem_list); - (section.end_section(), gem_list, default_process) + (bullet.done(), gem_list, default_process) }; // ## Assets install diff --git a/buildpacks/ruby/src/steps/get_default_process.rs b/buildpacks/ruby/src/steps/get_default_process.rs index b2dba89e..faf74a04 100644 --- a/buildpacks/ruby/src/steps/get_default_process.rs +++ b/buildpacks/ruby/src/steps/get_default_process.rs @@ -1,9 +1,6 @@ use crate::gem_list::GemList; use crate::RubyBuildpack; -use commons::output::{ - fmt, - section_log::{log_step, SectionLogger}, -}; +use commons::output::{fmt, section_log::log_step}; use libcnb::build::BuildContext; use libcnb::data::launch::Process; use libcnb::data::launch::ProcessBuilder; @@ -11,7 +8,6 @@ use libcnb::data::process_type; use std::path::Path; pub(crate) fn get_default_process( - _logger: &dyn SectionLogger, context: &BuildContext, gem_list: &GemList, ) -> Option { From 7a10615e250253401d53b5ea7dff2693815d28f6 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 10:56:36 -0500 Subject: [PATCH 02/39] Change top level bullet to a noun --- buildpacks/ruby/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index 6136876d..0dedd7d0 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -220,7 +220,7 @@ impl Buildpack for RubyBuildpack { // ## Detect gems let (_, gem_list, default_process) = { - let bullet = build_output.bullet("Setting default processes"); + let bullet = build_output.bullet("Default process detection"); let gem_list = gem_list::GemList::from_bundle_list(&env) .map_err(RubyBuildpackError::GemListGetError)?; From 6ebbf0547af3ce2b512e6ac12a1f373feeb43b0f Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 11:08:58 -0500 Subject: [PATCH 03/39] Refactor command to functional style --- buildpacks/ruby/src/gem_list.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/buildpacks/ruby/src/gem_list.rs b/buildpacks/ruby/src/gem_list.rs index 1ebd4968..d87fbad6 100644 --- a/buildpacks/ruby/src/gem_list.rs +++ b/buildpacks/ruby/src/gem_list.rs @@ -65,11 +65,11 @@ impl GemList { let mut cmd = Command::new("bundle"); cmd.arg("list").env_clear().envs(envs); - let output = log_step_timed(format!("Running {}", fmt::command(cmd.name())), || { + log_step_timed(format!("Running {}", fmt::command(cmd.name())), || { cmd.named_output() - })?; - - GemList::from_str(&output.stdout_lossy()) + .map(|output| output.stdout_lossy()) + .and_then(|output| GemList::from_str(&output)) + }) } #[must_use] From 7b3b12c1fde4275e736f4edde00ebecaa42b7706 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 15:41:43 -0500 Subject: [PATCH 04/39] Move logic to function --- buildpacks/ruby/src/gem_list.rs | 42 ++++++++++++++++----------------- buildpacks/ruby/src/main.rs | 4 ++-- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/buildpacks/ruby/src/gem_list.rs b/buildpacks/ruby/src/gem_list.rs index d87fbad6..da387a0f 100644 --- a/buildpacks/ruby/src/gem_list.rs +++ b/buildpacks/ruby/src/gem_list.rs @@ -15,6 +15,27 @@ pub(crate) struct GemList { pub(crate) gems: HashMap, } +/// Calls `bundle list` and returns a `GemList` struct +/// +/// # Errors +/// +/// Errors if the command `bundle list` is unsuccessful. +pub(crate) fn bundle_list(envs: T) -> Result +where + T: IntoIterator, + K: AsRef, + V: AsRef, +{ + let mut cmd = Command::new("bundle"); + cmd.arg("list").env_clear().envs(envs); + + log_step_timed(format!("Running {}", fmt::command(cmd.name())), || { + cmd.named_output() + .map(|output| output.stdout_lossy()) + .and_then(|output| GemList::from_str(&output)) + }) +} + /// Converts the output of `$ gem list` into a data structure that can be inspected and compared /// /// ``` @@ -51,27 +72,6 @@ pub(crate) struct GemList { /// ); /// ``` impl GemList { - /// Calls `bundle list` and returns a `GemList` struct - /// - /// # Errors - /// - /// Errors if the command `bundle list` is unsuccessful. - pub(crate) fn from_bundle_list(envs: T) -> Result - where - T: IntoIterator, - K: AsRef, - V: AsRef, - { - let mut cmd = Command::new("bundle"); - cmd.arg("list").env_clear().envs(envs); - - log_step_timed(format!("Running {}", fmt::command(cmd.name())), || { - cmd.named_output() - .map(|output| output.stdout_lossy()) - .and_then(|output| GemList::from_str(&output)) - }) - } - #[must_use] pub(crate) fn has(&self, str: &str) -> bool { self.gems.contains_key(&str.trim().to_lowercase()) diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index 0dedd7d0..f23d8a9b 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -222,8 +222,8 @@ impl Buildpack for RubyBuildpack { let (_, gem_list, default_process) = { let bullet = build_output.bullet("Default process detection"); - let gem_list = gem_list::GemList::from_bundle_list(&env) - .map_err(RubyBuildpackError::GemListGetError)?; + let gem_list = + gem_list::bundle_list(&env).map_err(RubyBuildpackError::GemListGetError)?; let default_process = steps::get_default_process(&context, &gem_list); (bullet.done(), gem_list, default_process) From 95c5e0f10f54e2428518c68b5410943b4db6842b Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 15:45:31 -0500 Subject: [PATCH 05/39] Replace section logger with bullet stream --- buildpacks/ruby/src/gem_list.rs | 19 ++++++++++++------- buildpacks/ruby/src/main.rs | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/buildpacks/ruby/src/gem_list.rs b/buildpacks/ruby/src/gem_list.rs index da387a0f..f680f2a8 100644 --- a/buildpacks/ruby/src/gem_list.rs +++ b/buildpacks/ruby/src/gem_list.rs @@ -1,10 +1,11 @@ +use bullet_stream::{state::SubBullet, style, Print}; use commons::gem_version::GemVersion; -use commons::output::{fmt, section_log::log_step_timed}; use core::str::FromStr; use fun_run::{CmdError, CommandWithName}; use regex::Regex; use std::collections::HashMap; use std::ffi::OsStr; +use std::io::Stdout; use std::process::Command; /// ## Gets list of an application's dependencies @@ -20,7 +21,10 @@ pub(crate) struct GemList { /// # Errors /// /// Errors if the command `bundle list` is unsuccessful. -pub(crate) fn bundle_list(envs: T) -> Result +pub(crate) fn bundle_list( + bullet: Print>, + envs: T, +) -> Result<(Print>, GemList), CmdError> where T: IntoIterator, K: AsRef, @@ -29,11 +33,12 @@ where let mut cmd = Command::new("bundle"); cmd.arg("list").env_clear().envs(envs); - log_step_timed(format!("Running {}", fmt::command(cmd.name())), || { - cmd.named_output() - .map(|output| output.stdout_lossy()) - .and_then(|output| GemList::from_str(&output)) - }) + let timer = bullet.start_timer(format!("Running {}", style::command(cmd.name()))); + let gem_list = cmd + .named_output() + .map(|output| output.stdout_lossy()) + .and_then(|output| GemList::from_str(&output))?; + Ok((timer.done(), gem_list)) } /// Converts the output of `$ gem list` into a data structure that can be inspected and compared diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index f23d8a9b..869db9a0 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -222,8 +222,8 @@ impl Buildpack for RubyBuildpack { let (_, gem_list, default_process) = { let bullet = build_output.bullet("Default process detection"); - let gem_list = - gem_list::bundle_list(&env).map_err(RubyBuildpackError::GemListGetError)?; + let (bullet, gem_list) = + gem_list::bundle_list(bullet, &env).map_err(RubyBuildpackError::GemListGetError)?; let default_process = steps::get_default_process(&context, &gem_list); (bullet.done(), gem_list, default_process) From ee7a3e048471f9505e1f3accc8f66d404eb4f8d2 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 15:52:15 -0500 Subject: [PATCH 06/39] Replace logging with bullet stream --- buildpacks/ruby/src/main.rs | 2 +- .../ruby/src/steps/get_default_process.rs | 48 +++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index 869db9a0..eeda5839 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -224,7 +224,7 @@ impl Buildpack for RubyBuildpack { let (bullet, gem_list) = gem_list::bundle_list(bullet, &env).map_err(RubyBuildpackError::GemListGetError)?; - let default_process = steps::get_default_process(&context, &gem_list); + let (bullet, default_process) = steps::get_default_process(bullet, &context, &gem_list); (bullet.done(), gem_list, default_process) }; diff --git a/buildpacks/ruby/src/steps/get_default_process.rs b/buildpacks/ruby/src/steps/get_default_process.rs index faf74a04..28caa2c8 100644 --- a/buildpacks/ruby/src/steps/get_default_process.rs +++ b/buildpacks/ruby/src/steps/get_default_process.rs @@ -1,47 +1,47 @@ use crate::gem_list::GemList; use crate::RubyBuildpack; +use bullet_stream::state::{Bullet, SubBullet}; +use bullet_stream::Print; use commons::output::{fmt, section_log::log_step}; use libcnb::build::BuildContext; use libcnb::data::launch::Process; use libcnb::data::launch::ProcessBuilder; use libcnb::data::process_type; +use std::io::Stdout; use std::path::Path; pub(crate) fn get_default_process( + bullet: Print>, context: &BuildContext, gem_list: &GemList, -) -> Option { +) -> (Print>, Option) { let config_ru = fmt::value("config.ru"); let rails = fmt::value("rails"); let rack = fmt::value("rack"); let railties = fmt::value("railties"); match detect_web(gem_list, &context.app_dir) { - WebProcess::Rails => { - log_step(format!("Detected rails app ({rails} gem found)")); - - Some(default_rails()) - } - WebProcess::RackWithConfigRU => { - log_step(format!( + WebProcess::Rails => ( + bullet.sub_bullet(format!("Detected rails app ({rails} gem found)")), + Some(default_rails()), + ), + WebProcess::RackWithConfigRU => ( + bullet.sub_bullet(format!( "Detected rack app ({rack} gem found and {config_ru} at root of application)" - )); - - Some(default_rack()) - } - WebProcess::RackMissingConfigRu => { - log_step(format!( + )), + Some(default_rack()), + ), + WebProcess::RackMissingConfigRu => ( + bullet.sub_bullet(format!( "Skipping default web process ({rack} gem found but missing {config_ru} file)" - )); - - None - } - WebProcess::Missing => { - log_step(format!( + )), + None, + ), + WebProcess::Missing => ( + bullet.sub_bullet(format!( "Skipping default web process ({rails}, {railties}, and {rack} not found)" - )); - - None - } + )), + None, + ), } } From caced429dbd6817ea9c9c70263121fe1243d81ca Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:02:04 -0500 Subject: [PATCH 07/39] Remove SectionLogger guard --- buildpacks/ruby/src/main.rs | 3 +-- buildpacks/ruby/src/rake_task_detect.rs | 7 +------ buildpacks/ruby/src/steps/detect_rake_tasks.rs | 5 ++--- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index eeda5839..65b98cbd 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -232,8 +232,7 @@ impl Buildpack for RubyBuildpack { // ## Assets install logger = { let section = logger.section("Rake assets install"); - let rake_detect = - crate::steps::detect_rake_tasks(section.as_ref(), &gem_list, &context, &env)?; + let rake_detect = crate::steps::detect_rake_tasks(&gem_list, &context, &env)?; if let Some(rake_detect) = rake_detect { crate::steps::rake_assets_install(section.as_ref(), &context, &env, &rake_detect)?; diff --git a/buildpacks/ruby/src/rake_task_detect.rs b/buildpacks/ruby/src/rake_task_detect.rs index cfdedc65..b60ceae4 100644 --- a/buildpacks/ruby/src/rake_task_detect.rs +++ b/buildpacks/ruby/src/rake_task_detect.rs @@ -1,8 +1,4 @@ -use commons::output::{ - fmt, - section_log::{log_step_timed, SectionLogger}, -}; - +use commons::output::{fmt, section_log::log_step_timed}; use core::str::FromStr; use fun_run::{CmdError, CommandWithName}; use std::{ffi::OsStr, process::Command}; @@ -30,7 +26,6 @@ impl RakeDetect { K: AsRef, V: AsRef, >( - _logger: &dyn SectionLogger, envs: T, error_on_failure: bool, ) -> Result { diff --git a/buildpacks/ruby/src/steps/detect_rake_tasks.rs b/buildpacks/ruby/src/steps/detect_rake_tasks.rs index 97126225..a1b4ac71 100644 --- a/buildpacks/ruby/src/steps/detect_rake_tasks.rs +++ b/buildpacks/ruby/src/steps/detect_rake_tasks.rs @@ -1,6 +1,6 @@ use commons::output::{ fmt::{self, HELP}, - section_log::{log_step, SectionLogger}, + section_log::log_step, }; use crate::gem_list::GemList; @@ -12,7 +12,6 @@ use libcnb::build::BuildContext; use libcnb::Env; pub(crate) fn detect_rake_tasks( - logger: &dyn SectionLogger, gem_list: &GemList, context: &BuildContext, env: &Env, @@ -69,7 +68,7 @@ pub(crate) fn detect_rake_tasks( path = fmt::value(path.to_string_lossy()) )); - let rake_detect = RakeDetect::from_rake_command(logger, env, true) + let rake_detect = RakeDetect::from_rake_command(env, true) .map_err(RubyBuildpackError::RakeDetectError)?; Ok(Some(rake_detect)) From 04c887a30b0a0f25ac9fbac8447ee2917dcb7adc Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:04:38 -0500 Subject: [PATCH 08/39] Remove SectionLogger guard --- buildpacks/ruby/src/main.rs | 3 ++- buildpacks/ruby/src/steps/rake_assets_install.rs | 5 ++--- commons/src/cache/app_cache_collection.rs | 11 +++-------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index 65b98cbd..ece947d8 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -232,10 +232,11 @@ impl Buildpack for RubyBuildpack { // ## Assets install logger = { let section = logger.section("Rake assets install"); + let rake_detect = crate::steps::detect_rake_tasks(&gem_list, &context, &env)?; if let Some(rake_detect) = rake_detect { - crate::steps::rake_assets_install(section.as_ref(), &context, &env, &rake_detect)?; + crate::steps::rake_assets_install(&context, &env, &rake_detect)?; } section.end_section() diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index 86296979..1715e161 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -4,7 +4,7 @@ use crate::RubyBuildpackError; use commons::cache::{mib, AppCacheCollection, CacheConfig, KeepPath}; use commons::output::{ fmt::{self, HELP}, - section_log::{log_step, log_step_stream, SectionLogger}, + section_log::{log_step, log_step_stream}, }; use fun_run::{self, CmdError, CommandWithName}; use libcnb::build::BuildContext; @@ -12,7 +12,6 @@ use libcnb::Env; use std::process::Command; pub(crate) fn rake_assets_install( - logger: &dyn SectionLogger, context: &BuildContext, env: &Env, rake_detect: &RakeDetect, @@ -57,7 +56,7 @@ pub(crate) fn rake_assets_install( ]; let cache = { - AppCacheCollection::new_and_load(context, cache_config, logger) + AppCacheCollection::new_and_load(context, cache_config) .map_err(RubyBuildpackError::InAppDirCacheError)? }; diff --git a/commons/src/cache/app_cache_collection.rs b/commons/src/cache/app_cache_collection.rs index fd746b36..940ca1ed 100644 --- a/commons/src/cache/app_cache_collection.rs +++ b/commons/src/cache/app_cache_collection.rs @@ -13,12 +13,11 @@ use std::fmt::Debug; /// Default logging is provided for each operation. /// #[derive(Debug)] -pub struct AppCacheCollection<'a> { - _log: &'a dyn SectionLogger, +pub struct AppCacheCollection { collection: Vec, } -impl<'a> AppCacheCollection<'a> { +impl AppCacheCollection { /// Store multiple application paths in the cache /// /// # Errors @@ -29,7 +28,6 @@ impl<'a> AppCacheCollection<'a> { pub fn new_and_load( context: &BuildContext, config: impl IntoIterator, - log: &'a dyn SectionLogger, ) -> Result { let caches = config .into_iter() @@ -46,10 +44,7 @@ impl<'a> AppCacheCollection<'a> { }) .collect::, CacheError>>()?; - Ok(Self { - collection: caches, - _log: log, - }) + Ok(Self { collection: caches }) } /// # Errors From 76af8fcfc046ffe412def166f2668587bf211d4c Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:06:13 -0500 Subject: [PATCH 09/39] Replace section logger with bullet stream --- buildpacks/ruby/src/main.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index ece947d8..fb4c3ebd 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -219,7 +219,7 @@ impl Buildpack for RubyBuildpack { }; // ## Detect gems - let (_, gem_list, default_process) = { + let (mut build_output, gem_list, default_process) = { let bullet = build_output.bullet("Default process detection"); let (bullet, gem_list) = @@ -230,18 +230,17 @@ impl Buildpack for RubyBuildpack { }; // ## Assets install - logger = { - let section = logger.section("Rake assets install"); - + build_output = { + let mut bullet = build_output.bullet("Rake assets install"); let rake_detect = crate::steps::detect_rake_tasks(&gem_list, &context, &env)?; if let Some(rake_detect) = rake_detect { crate::steps::rake_assets_install(&context, &env, &rake_detect)?; } - section.end_section() + bullet.done() }; - logger.finish_logging(); + build_output.done(); warn_later.warn_now(); if let Some(default_process) = default_process { From 960fa98b24e6eaae8a3059899fb0c28ec4d86bc9 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:08:41 -0500 Subject: [PATCH 10/39] Wire bullet stream input and output --- buildpacks/ruby/src/main.rs | 8 ++++++-- buildpacks/ruby/src/steps/detect_rake_tasks.rs | 15 ++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index fb4c3ebd..be5d9d23 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -231,8 +231,12 @@ impl Buildpack for RubyBuildpack { // ## Assets install build_output = { - let mut bullet = build_output.bullet("Rake assets install"); - let rake_detect = crate::steps::detect_rake_tasks(&gem_list, &context, &env)?; + let (bullet, rake_detect) = crate::steps::detect_rake_tasks( + build_output.bullet("Rake assets install"), + &gem_list, + &context, + &env, + )?; if let Some(rake_detect) = rake_detect { crate::steps::rake_assets_install(&context, &env, &rake_detect)?; diff --git a/buildpacks/ruby/src/steps/detect_rake_tasks.rs b/buildpacks/ruby/src/steps/detect_rake_tasks.rs index a1b4ac71..b72ed562 100644 --- a/buildpacks/ruby/src/steps/detect_rake_tasks.rs +++ b/buildpacks/ruby/src/steps/detect_rake_tasks.rs @@ -1,3 +1,7 @@ +use std::io::Stdout; + +use bullet_stream::state::SubBullet; +use bullet_stream::Print; use commons::output::{ fmt::{self, HELP}, section_log::log_step, @@ -12,10 +16,11 @@ use libcnb::build::BuildContext; use libcnb::Env; pub(crate) fn detect_rake_tasks( + mut bullet: Print>, gem_list: &GemList, context: &BuildContext, env: &Env, -) -> Result, RubyBuildpackError> { +) -> Result<(Print>, Option), RubyBuildpackError> { let rake = fmt::value("rake"); let gemfile = fmt::value("Gemfile"); let rakefile = fmt::value("Rakefile"); @@ -36,7 +41,7 @@ pub(crate) fn detect_rake_tasks( gem = fmt::value("gem 'rake'") )); - Ok(None) + Ok((bullet, None)) } RakeStatus::MissingRakefile => { log_step(format!( @@ -45,7 +50,7 @@ pub(crate) fn detect_rake_tasks( )); log_step(format!("{HELP} Add {rakefile} to your project to enable",)); - Ok(None) + Ok((bullet, None)) } RakeStatus::SkipManifestFound(paths) => { let files = paths @@ -60,7 +65,7 @@ pub(crate) fn detect_rake_tasks( )); log_step(format!("{HELP} Delete files to enable running rake tasks")); - Ok(None) + Ok((bullet, None)) } RakeStatus::Ready(path) => { log_step(format!( @@ -71,7 +76,7 @@ pub(crate) fn detect_rake_tasks( let rake_detect = RakeDetect::from_rake_command(env, true) .map_err(RubyBuildpackError::RakeDetectError)?; - Ok(Some(rake_detect)) + Ok((bullet, Some(rake_detect))) } } } From 0c03dc5014120230fa7ed94e2f32dfd44845edd4 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:10:41 -0500 Subject: [PATCH 11/39] Replace section log with bullet stream --- .../ruby/src/steps/detect_rake_tasks.rs | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/buildpacks/ruby/src/steps/detect_rake_tasks.rs b/buildpacks/ruby/src/steps/detect_rake_tasks.rs index b72ed562..20ad0b35 100644 --- a/buildpacks/ruby/src/steps/detect_rake_tasks.rs +++ b/buildpacks/ruby/src/steps/detect_rake_tasks.rs @@ -1,7 +1,7 @@ use std::io::Stdout; use bullet_stream::state::SubBullet; -use bullet_stream::Print; +use bullet_stream::{style, Print}; use commons::output::{ fmt::{self, HELP}, section_log::log_step, @@ -21,6 +21,7 @@ pub(crate) fn detect_rake_tasks( context: &BuildContext, env: &Env, ) -> Result<(Print>, Option), RubyBuildpackError> { + let help = style::important("HELP"); let rake = fmt::value("rake"); let gemfile = fmt::value("Gemfile"); let rakefile = fmt::value("Rakefile"); @@ -30,19 +31,17 @@ pub(crate) fn detect_rake_tasks( gem_list, [".sprockets-manifest-*.json", "manifest-*.json"], ) { - RakeStatus::MissingRakeGem => { - log_step(format!( - "Skipping rake tasks {}", - fmt::details(format!("no {rake} gem in {gemfile}")) - )); - - log_step(format!( - "{HELP} Add {gem} to your {gemfile} to enable", - gem = fmt::value("gem 'rake'") - )); - - Ok((bullet, None)) - } + RakeStatus::MissingRakeGem => Ok(( + bullet + .sub_bullet(format!( + "Skipping rake tasks ({rake} gem not found in {gemfile})" + )) + .sub_bullet(format!( + "{help} Add {gem} to your {gemfile} to enable", + gem = fmt::value("gem 'rake'") + )), + None, + )), RakeStatus::MissingRakefile => { log_step(format!( "Skipping rake tasks {}", From 5ffe2d51c6a1f729a842227ee148dacf8beb436d Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:11:53 -0500 Subject: [PATCH 12/39] Replace section log with bullet stream --- buildpacks/ruby/src/steps/detect_rake_tasks.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/buildpacks/ruby/src/steps/detect_rake_tasks.rs b/buildpacks/ruby/src/steps/detect_rake_tasks.rs index 20ad0b35..40002727 100644 --- a/buildpacks/ruby/src/steps/detect_rake_tasks.rs +++ b/buildpacks/ruby/src/steps/detect_rake_tasks.rs @@ -42,15 +42,12 @@ pub(crate) fn detect_rake_tasks( )), None, )), - RakeStatus::MissingRakefile => { - log_step(format!( - "Skipping rake tasks {}", - fmt::details(format!("no {rakefile}")) - )); - log_step(format!("{HELP} Add {rakefile} to your project to enable",)); - - Ok((bullet, None)) - } + RakeStatus::MissingRakefile => Ok(( + bullet + .sub_bullet(format!("Skipping rake tasks ({rakefile} not found)",)) + .sub_bullet(format!("{help} Add {rakefile} to your project to enable",)), + None, + )), RakeStatus::SkipManifestFound(paths) => { let files = paths .iter() From 49981b4aef6eacf510de8994d2efcd0e84bb2526 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:13:19 -0500 Subject: [PATCH 13/39] Replace section log with bullet stream --- buildpacks/ruby/src/steps/detect_rake_tasks.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/buildpacks/ruby/src/steps/detect_rake_tasks.rs b/buildpacks/ruby/src/steps/detect_rake_tasks.rs index 40002727..df0149a9 100644 --- a/buildpacks/ruby/src/steps/detect_rake_tasks.rs +++ b/buildpacks/ruby/src/steps/detect_rake_tasks.rs @@ -55,13 +55,14 @@ pub(crate) fn detect_rake_tasks( .collect::>() .join(", "); - log_step(format!( - "Skipping rake tasks {}", - fmt::details(format!("Manifest files found {files}")) - )); - log_step(format!("{HELP} Delete files to enable running rake tasks")); - - Ok((bullet, None)) + Ok(( + bullet + .sub_bullet(format!( + "Skipping rake tasks (Manifest files found {files})" + )) + .sub_bullet(format!("{help} Delete files to enable running rake tasks")), + None, + )) } RakeStatus::Ready(path) => { log_step(format!( From c40b5d11d7e1bee488b43f564310e1b9d29927a4 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:14:02 -0500 Subject: [PATCH 14/39] Pluralize word --- buildpacks/ruby/src/steps/detect_rake_tasks.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/buildpacks/ruby/src/steps/detect_rake_tasks.rs b/buildpacks/ruby/src/steps/detect_rake_tasks.rs index df0149a9..53c6449b 100644 --- a/buildpacks/ruby/src/steps/detect_rake_tasks.rs +++ b/buildpacks/ruby/src/steps/detect_rake_tasks.rs @@ -49,7 +49,7 @@ pub(crate) fn detect_rake_tasks( None, )), RakeStatus::SkipManifestFound(paths) => { - let files = paths + let manifest_files = paths .iter() .map(|path| fmt::value(path.to_string_lossy())) .collect::>() @@ -58,7 +58,12 @@ pub(crate) fn detect_rake_tasks( Ok(( bullet .sub_bullet(format!( - "Skipping rake tasks (Manifest files found {files})" + "Skipping rake tasks (Manifest {files} found {manifest_files})", + files = if manifest_files.len() > 1 { + "files" + } else { + "file" + } )) .sub_bullet(format!("{help} Delete files to enable running rake tasks")), None, From f6127e763049d7df1bb5f455b738fa071f80292b Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:14:48 -0500 Subject: [PATCH 15/39] Replace section log with bullet stream --- buildpacks/ruby/src/steps/detect_rake_tasks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildpacks/ruby/src/steps/detect_rake_tasks.rs b/buildpacks/ruby/src/steps/detect_rake_tasks.rs index 53c6449b..1ff7fe29 100644 --- a/buildpacks/ruby/src/steps/detect_rake_tasks.rs +++ b/buildpacks/ruby/src/steps/detect_rake_tasks.rs @@ -70,7 +70,7 @@ pub(crate) fn detect_rake_tasks( )) } RakeStatus::Ready(path) => { - log_step(format!( + bullet = bullet.sub_bullet(format!( "Detected rake ({rake} gem found, {rakefile} found at {path})", path = fmt::value(path.to_string_lossy()) )); From 8fa7ee1302cfdb47a1f250a97b3679d7c230f667 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:16:53 -0500 Subject: [PATCH 16/39] Move associated function to function --- buildpacks/ruby/src/rake_task_detect.rs | 58 +++++++++---------- .../ruby/src/steps/detect_rake_tasks.rs | 6 +- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/buildpacks/ruby/src/rake_task_detect.rs b/buildpacks/ruby/src/rake_task_detect.rs index b60ceae4..6d151348 100644 --- a/buildpacks/ruby/src/rake_task_detect.rs +++ b/buildpacks/ruby/src/rake_task_detect.rs @@ -17,40 +17,36 @@ pub(crate) struct RakeDetect { output: String, } -impl RakeDetect { - /// # Errors - /// - /// Will return `Err` if `bundle exec rake -p` command cannot be invoked by the operating system. - pub(crate) fn from_rake_command< - T: IntoIterator, - K: AsRef, - V: AsRef, - >( - envs: T, - error_on_failure: bool, - ) -> Result { - let mut cmd = Command::new("bundle"); - cmd.args(["exec", "rake", "-P", "--trace"]) - .env_clear() - .envs(envs); +/// # Errors +/// +/// Will return `Err` if `bundle exec rake -p` command cannot be invoked by the operating system. +pub(crate) fn call, K: AsRef, V: AsRef>( + envs: T, + error_on_failure: bool, +) -> Result { + let mut cmd = Command::new("bundle"); + cmd.args(["exec", "rake", "-P", "--trace"]) + .env_clear() + .envs(envs); - log_step_timed(format!("Running {}", fmt::command(cmd.name())), || { - cmd.named_output() - }) - .or_else(|error| { - if error_on_failure { - Err(error) - } else { - match error { - CmdError::SystemError(_, _) => Err(error), - CmdError::NonZeroExitNotStreamed(output) - | CmdError::NonZeroExitAlreadyStreamed(output) => Ok(output), - } + log_step_timed(format!("Running {}", fmt::command(cmd.name())), || { + cmd.named_output() + }) + .or_else(|error| { + if error_on_failure { + Err(error) + } else { + match error { + CmdError::SystemError(_, _) => Err(error), + CmdError::NonZeroExitNotStreamed(output) + | CmdError::NonZeroExitAlreadyStreamed(output) => Ok(output), } - }) - .and_then(|output| RakeDetect::from_str(&output.stdout_lossy())) - } + } + }) + .and_then(|output| RakeDetect::from_str(&output.stdout_lossy())) +} +impl RakeDetect { #[must_use] pub(crate) fn has_task(&self, string: &str) -> bool { let task_re = regex::Regex::new(&format!("\\s{string}")).expect("clippy"); diff --git a/buildpacks/ruby/src/steps/detect_rake_tasks.rs b/buildpacks/ruby/src/steps/detect_rake_tasks.rs index 1ff7fe29..0235931b 100644 --- a/buildpacks/ruby/src/steps/detect_rake_tasks.rs +++ b/buildpacks/ruby/src/steps/detect_rake_tasks.rs @@ -9,7 +9,7 @@ use commons::output::{ use crate::gem_list::GemList; use crate::rake_status::{check_rake_ready, RakeStatus}; -use crate::rake_task_detect::RakeDetect; +use crate::rake_task_detect::{self, RakeDetect}; use crate::RubyBuildpack; use crate::RubyBuildpackError; use libcnb::build::BuildContext; @@ -75,8 +75,8 @@ pub(crate) fn detect_rake_tasks( path = fmt::value(path.to_string_lossy()) )); - let rake_detect = RakeDetect::from_rake_command(env, true) - .map_err(RubyBuildpackError::RakeDetectError)?; + let rake_detect = + rake_task_detect::call(env, true).map_err(RubyBuildpackError::RakeDetectError)?; Ok((bullet, Some(rake_detect))) } From 98591696fef2e580d37092912180576c0d2bcbff Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:18:42 -0500 Subject: [PATCH 17/39] Wire up bullet stream --- buildpacks/ruby/src/rake_task_detect.rs | 7 ++++++- buildpacks/ruby/src/steps/detect_rake_tasks.rs | 16 +++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/buildpacks/ruby/src/rake_task_detect.rs b/buildpacks/ruby/src/rake_task_detect.rs index 6d151348..ec4b8d19 100644 --- a/buildpacks/ruby/src/rake_task_detect.rs +++ b/buildpacks/ruby/src/rake_task_detect.rs @@ -1,6 +1,9 @@ +use bullet_stream::state::SubBullet; +use bullet_stream::Print; use commons::output::{fmt, section_log::log_step_timed}; use core::str::FromStr; use fun_run::{CmdError, CommandWithName}; +use std::io::Stdout; use std::{ffi::OsStr, process::Command}; /// Run `rake -P` and parse output to show what rake tasks an application has @@ -21,9 +24,10 @@ pub(crate) struct RakeDetect { /// /// Will return `Err` if `bundle exec rake -p` command cannot be invoked by the operating system. pub(crate) fn call, K: AsRef, V: AsRef>( + mut bullet: Print>, envs: T, error_on_failure: bool, -) -> Result { +) -> Result<(Print>, RakeDetect), CmdError> { let mut cmd = Command::new("bundle"); cmd.args(["exec", "rake", "-P", "--trace"]) .env_clear() @@ -44,6 +48,7 @@ pub(crate) fn call, K: AsRef, V: AsRef { - bullet = bullet.sub_bullet(format!( - "Detected rake ({rake} gem found, {rakefile} found at {path})", - path = fmt::value(path.to_string_lossy()) - )); - - let rake_detect = - rake_task_detect::call(env, true).map_err(RubyBuildpackError::RakeDetectError)?; + let (bullet, rake_detect) = rake_task_detect::call( + bullet.sub_bullet(format!( + "Detected rake ({rake} gem found, {rakefile} found at {path})", + path = fmt::value(path.to_string_lossy()) + )), + env, + true, + ) + .map_err(RubyBuildpackError::RakeDetectError)?; Ok((bullet, Some(rake_detect))) } From 876b8f46db8f3b7fff52c6de2b0efb1ffe7c9dac Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:25:42 -0500 Subject: [PATCH 18/39] Use bullet stream for `rake -p` --- buildpacks/ruby/src/rake_task_detect.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/buildpacks/ruby/src/rake_task_detect.rs b/buildpacks/ruby/src/rake_task_detect.rs index ec4b8d19..2d287673 100644 --- a/buildpacks/ruby/src/rake_task_detect.rs +++ b/buildpacks/ruby/src/rake_task_detect.rs @@ -1,6 +1,7 @@ -use bullet_stream::state::SubBullet; -use bullet_stream::Print; -use commons::output::{fmt, section_log::log_step_timed}; +use bullet_stream::{ + state::SubBullet, + {style, Print}, +}; use core::str::FromStr; use fun_run::{CmdError, CommandWithName}; use std::io::Stdout; @@ -24,7 +25,7 @@ pub(crate) struct RakeDetect { /// /// Will return `Err` if `bundle exec rake -p` command cannot be invoked by the operating system. pub(crate) fn call, K: AsRef, V: AsRef>( - mut bullet: Print>, + bullet: Print>, envs: T, error_on_failure: bool, ) -> Result<(Print>, RakeDetect), CmdError> { @@ -33,10 +34,8 @@ pub(crate) fn call, K: AsRef, V: AsRef, K: AsRef, V: AsRef Ok(output), } } - }) - .and_then(|output| RakeDetect::from_str(&output.stdout_lossy())) - .map(|rake_detect| (bullet, rake_detect)) + })?; + + RakeDetect::from_str(&output.stdout_lossy()).map(|rake_detect| (timer.done(), rake_detect)) } impl RakeDetect { From 89c7cc7b5509eac158a015bbf74a816d1d8e114c Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:28:50 -0500 Subject: [PATCH 19/39] Wire bullet stream --- buildpacks/ruby/src/main.rs | 7 ++++--- buildpacks/ruby/src/steps/rake_assets_install.rs | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index be5d9d23..ca15c2e2 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -239,10 +239,11 @@ impl Buildpack for RubyBuildpack { )?; if let Some(rake_detect) = rake_detect { - crate::steps::rake_assets_install(&context, &env, &rake_detect)?; + crate::steps::rake_assets_install(bullet, &context, &env, &rake_detect)? + } else { + bullet } - - bullet.done() + .done() }; build_output.done(); warn_later.warn_now(); diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index 1715e161..8e17a1b9 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -1,6 +1,8 @@ use crate::rake_task_detect::RakeDetect; use crate::RubyBuildpack; use crate::RubyBuildpackError; +use bullet_stream::state::SubBullet; +use bullet_stream::Print; use commons::cache::{mib, AppCacheCollection, CacheConfig, KeepPath}; use commons::output::{ fmt::{self, HELP}, @@ -9,13 +11,15 @@ use commons::output::{ use fun_run::{self, CmdError, CommandWithName}; use libcnb::build::BuildContext; use libcnb::Env; +use std::io::Stdout; use std::process::Command; pub(crate) fn rake_assets_install( + mut bullet: Print>, context: &BuildContext, env: &Env, rake_detect: &RakeDetect, -) -> Result<(), RubyBuildpackError> { +) -> Result>, RubyBuildpackError> { let cases = asset_cases(rake_detect); let rake_assets_precompile = fmt::value("rake assets:precompile"); let rake_assets_clean = fmt::value("rake assets:clean"); @@ -69,7 +73,7 @@ pub(crate) fn rake_assets_install( } } - Ok(()) + Ok(bullet) } fn run_rake_assets_precompile(env: &Env) -> Result<(), CmdError> { From e429456a2999a594be885cdf8e2281909fe7ee7b Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:30:35 -0500 Subject: [PATCH 20/39] Replace section logger with bullet stream --- buildpacks/ruby/src/steps/rake_assets_install.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index 8e17a1b9..ba99b182 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -2,7 +2,7 @@ use crate::rake_task_detect::RakeDetect; use crate::RubyBuildpack; use crate::RubyBuildpackError; use bullet_stream::state::SubBullet; -use bullet_stream::Print; +use bullet_stream::{style, Print}; use commons::cache::{mib, AppCacheCollection, CacheConfig, KeepPath}; use commons::output::{ fmt::{self, HELP}, @@ -20,6 +20,7 @@ pub(crate) fn rake_assets_install( env: &Env, rake_detect: &RakeDetect, ) -> Result>, RubyBuildpackError> { + let help = style::important("HELP"); let cases = asset_cases(rake_detect); let rake_assets_precompile = fmt::value("rake assets:precompile"); let rake_assets_clean = fmt::value("rake assets:clean"); @@ -27,11 +28,9 @@ pub(crate) fn rake_assets_install( match cases { AssetCases::None => { - log_step(format!( - "Skipping {rake_assets_precompile} {}", - fmt::details(format!("task not found via {rake_detect_cmd}")) - )); - log_step(format!("{HELP} Enable compiling assets by ensuring {rake_assets_precompile} is present when running the detect command locally")); + bullet = bullet.sub_bullet(format!( + "Skipping {rake_assets_clean} (task not found via {rake_detect_cmd})", + )).sub_bullet(format!("{help} Enable cleaning assets by ensuring {rake_assets_clean} is present when running the detect command locally")); } AssetCases::PrecompileOnly => { log_step(format!( From 27fc63172713d3b7cad42461ef86bb0ccc13956f Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:31:17 -0500 Subject: [PATCH 21/39] Replace section logger with bullet stream --- buildpacks/ruby/src/steps/rake_assets_install.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index ba99b182..ad8825da 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -33,11 +33,9 @@ pub(crate) fn rake_assets_install( )).sub_bullet(format!("{help} Enable cleaning assets by ensuring {rake_assets_clean} is present when running the detect command locally")); } AssetCases::PrecompileOnly => { - log_step(format!( - "Compiling assets without cache {}", - fmt::details(format!("Clean task not found via {rake_detect_cmd}")) - )); - log_step(format!("{HELP} Enable caching by ensuring {rake_assets_clean} is present when running the detect command locally")); + bullet = bullet.sub_bullet( + format!("Compiling assets without cache (Clean task not found via {rake_detect_cmd})"), + ).sub_bullet(format!("{help} Enable caching by ensuring {rake_assets_clean} is present when running the detect command locally")); run_rake_assets_precompile(env) .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; From 8ca43595fc2eff72fbd7144d06a911ac9224fc3e Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:31:47 -0500 Subject: [PATCH 22/39] Replace section logger with bullet stream --- buildpacks/ruby/src/steps/rake_assets_install.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index ad8825da..604cdab4 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -41,7 +41,7 @@ pub(crate) fn rake_assets_install( .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; } AssetCases::PrecompileAndClean => { - log_step(format!("Compiling assets with cache {}", fmt::details(format!("detected {rake_assets_precompile} and {rake_assets_clean} via {rake_detect_cmd}")))); + bullet = bullet.sub_bullet(format!("Compiling assets with cache (detected {rake_assets_precompile} and {rake_assets_clean} via {rake_detect_cmd})")); let cache_config = [ CacheConfig { From 4fd288882eaa64cc0ba233eabb20d29bfc73d4d5 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:41:30 -0500 Subject: [PATCH 23/39] Inline AppCacheCollection logic This is a pretty useless struct that hides the underlying logic I want to deprecate it. --- .../ruby/src/steps/rake_assets_install.rs | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index 604cdab4..ecd55f46 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -3,7 +3,7 @@ use crate::RubyBuildpack; use crate::RubyBuildpackError; use bullet_stream::state::SubBullet; use bullet_stream::{style, Print}; -use commons::cache::{mib, AppCacheCollection, CacheConfig, KeepPath}; +use commons::cache::{mib, AppCache, CacheConfig, CacheError, CacheState, KeepPath, PathState}; use commons::output::{ fmt::{self, HELP}, section_log::{log_step, log_step_stream}, @@ -56,17 +56,48 @@ pub(crate) fn rake_assets_install( }, ]; - let cache = { - AppCacheCollection::new_and_load(context, cache_config) - .map_err(RubyBuildpackError::InAppDirCacheError)? - }; + let caches = cache_config + .iter() + .map(|config| AppCache::new_and_load(context, config.to_owned())) + .collect::, CacheError>>() + .map_err(RubyBuildpackError::InAppDirCacheError)?; + + for store in &caches { + let path = store.path().display(); + bullet = bullet.sub_bullet(match store.cache_state() { + CacheState::NewEmpty => format!("Creating cache for {path}"), + CacheState::ExistsEmpty => format!("Loading (empty) cache for {path}"), + CacheState::ExistsWithContents => format!("Loading cache for {path}"), + }); + } run_rake_assets_precompile_with_clean(env) .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; - cache - .save_and_clean() - .map_err(RubyBuildpackError::InAppDirCacheError)?; + for store in caches { + let path = store.path().display(); + + bullet = bullet.sub_bullet(match store.path_state() { + PathState::Empty => format!("Storing cache for (empty) {path}"), + PathState::HasFiles => format!("Storing cache for {path}"), + }); + + if let Some(removed) = store + .save_and_clean() + .map_err(RubyBuildpackError::InAppDirCacheError)? + { + let path = store.path().display(); + let limit = store.limit(); + let removed_len = removed.files.len(); + let removed_size = removed.adjusted_bytes(); + + bullet = bullet.sub_bullet(format!("Detected cache size exceeded (over {limit} limit by {removed_size}) for {path}")) + .sub_bullet( + format!("Removed {removed_len} files from the cache for {path}"), + + ); + } + } } } From 0f983c6d6f0004b28a8c98a9daf9bbe273113cd8 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:42:01 -0500 Subject: [PATCH 24/39] Remove output fmt module import --- .../ruby/src/steps/rake_assets_install.rs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index ecd55f46..86fcc9b2 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -4,10 +4,7 @@ use crate::RubyBuildpackError; use bullet_stream::state::SubBullet; use bullet_stream::{style, Print}; use commons::cache::{mib, AppCache, CacheConfig, CacheError, CacheState, KeepPath, PathState}; -use commons::output::{ - fmt::{self, HELP}, - section_log::{log_step, log_step_stream}, -}; +use commons::output::section_log::{log_step, log_step_stream}; use fun_run::{self, CmdError, CommandWithName}; use libcnb::build::BuildContext; use libcnb::Env; @@ -22,9 +19,9 @@ pub(crate) fn rake_assets_install( ) -> Result>, RubyBuildpackError> { let help = style::important("HELP"); let cases = asset_cases(rake_detect); - let rake_assets_precompile = fmt::value("rake assets:precompile"); - let rake_assets_clean = fmt::value("rake assets:clean"); - let rake_detect_cmd = fmt::value("bundle exec rake -P"); + let rake_assets_precompile = style::value("rake assets:precompile"); + let rake_assets_clean = style::value("rake assets:clean"); + let rake_detect_cmd = style::value("bundle exec rake -P"); match cases { AssetCases::None => { @@ -112,10 +109,13 @@ fn run_rake_assets_precompile(env: &Env) -> Result<(), CmdError> { .env_clear() .envs(env); - log_step_stream(format!("Running {}", fmt::command(cmd.name())), |stream| { - cmd.stream_output(stream.io(), stream.io()) - .map_err(|error| fun_run::map_which_problem(error, &mut cmd, path_env)) - })?; + log_step_stream( + format!("Running {}", style::command(cmd.name())), + |stream| { + cmd.stream_output(stream.io(), stream.io()) + .map_err(|error| fun_run::map_which_problem(error, &mut cmd, path_env)) + }, + )?; Ok(()) } @@ -133,9 +133,10 @@ fn run_rake_assets_precompile_with_clean(env: &Env) -> Result<(), CmdError> { .env_clear() .envs(env); - log_step_stream(format!("Running {}", fmt::command(cmd.name())), |stream| { - cmd.stream_output(stream.io(), stream.io()) - }) + log_step_stream( + format!("Running {}", style::command(cmd.name())), + |stream| cmd.stream_output(stream.io(), stream.io()), + ) .map_err(|error| fun_run::map_which_problem(error, &mut cmd, path_env))?; Ok(()) From 5aad895a211f404edf96c617726bce66e843dcb9 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:43:36 -0500 Subject: [PATCH 25/39] Inline command call --- .../ruby/src/steps/rake_assets_install.rs | 42 ++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index 86fcc9b2..f8374050 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -68,8 +68,24 @@ pub(crate) fn rake_assets_install( }); } - run_rake_assets_precompile_with_clean(env) - .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; + let path_env = env.get("PATH").cloned(); + let mut cmd = Command::new("bundle"); + cmd.args([ + "exec", + "rake", + "assets:precompile", + "assets:clean", + "--trace", + ]) + .env_clear() + .envs(env); + + log_step_stream( + format!("Running {}", style::command(cmd.name())), + |stream| cmd.stream_output(stream.io(), stream.io()), + ) + .map_err(|error| fun_run::map_which_problem(error, &mut cmd, path_env)) + .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; for store in caches { let path = store.path().display(); @@ -120,28 +136,6 @@ fn run_rake_assets_precompile(env: &Env) -> Result<(), CmdError> { Ok(()) } -fn run_rake_assets_precompile_with_clean(env: &Env) -> Result<(), CmdError> { - let path_env = env.get("PATH").cloned(); - let mut cmd = Command::new("bundle"); - cmd.args([ - "exec", - "rake", - "assets:precompile", - "assets:clean", - "--trace", - ]) - .env_clear() - .envs(env); - - log_step_stream( - format!("Running {}", style::command(cmd.name())), - |stream| cmd.stream_output(stream.io(), stream.io()), - ) - .map_err(|error| fun_run::map_which_problem(error, &mut cmd, path_env))?; - - Ok(()) -} - #[derive(Clone, Debug)] enum AssetCases { None, From 8b1d3faf5efa8eb94f5326f65bd087b2dde540eb Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:45:27 -0500 Subject: [PATCH 26/39] Replace section log with bullet stream --- buildpacks/ruby/src/steps/rake_assets_install.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index f8374050..96d5c156 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -80,12 +80,13 @@ pub(crate) fn rake_assets_install( .env_clear() .envs(env); - log_step_stream( - format!("Running {}", style::command(cmd.name())), - |stream| cmd.stream_output(stream.io(), stream.io()), - ) - .map_err(|error| fun_run::map_which_problem(error, &mut cmd, path_env)) - .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; + bullet + .stream_with( + format!("Running {}", style::command(cmd.name())), + |stdout, stderr| cmd.stream_output(stdout, stderr), + ) + .map_err(|error| fun_run::map_which_problem(error, &mut cmd, path_env)) + .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; for store in caches { let path = store.path().display(); From 3f1c7e0e983c3a87421d0035fd26d313b18ba33d Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:45:47 -0500 Subject: [PATCH 27/39] Use value directly instead of making a variable --- buildpacks/ruby/src/steps/rake_assets_install.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index 96d5c156..4a32a94f 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -68,7 +68,6 @@ pub(crate) fn rake_assets_install( }); } - let path_env = env.get("PATH").cloned(); let mut cmd = Command::new("bundle"); cmd.args([ "exec", @@ -85,7 +84,9 @@ pub(crate) fn rake_assets_install( format!("Running {}", style::command(cmd.name())), |stdout, stderr| cmd.stream_output(stdout, stderr), ) - .map_err(|error| fun_run::map_which_problem(error, &mut cmd, path_env)) + .map_err(|error| { + fun_run::map_which_problem(error, &mut cmd, env.get("PATH").cloned()) + }) .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; for store in caches { From f3613b1401c38aebe01387ff03f60b57c03915d1 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:46:48 -0500 Subject: [PATCH 28/39] Inline command creation --- .../ruby/src/steps/rake_assets_install.rs | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index 4a32a94f..47920df2 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -34,8 +34,21 @@ pub(crate) fn rake_assets_install( format!("Compiling assets without cache (Clean task not found via {rake_detect_cmd})"), ).sub_bullet(format!("{help} Enable caching by ensuring {rake_assets_clean} is present when running the detect command locally")); - run_rake_assets_precompile(env) - .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; + let path_env = env.get("PATH").cloned(); + let mut cmd = Command::new("bundle"); + + cmd.args(["exec", "rake", "assets:precompile", "--trace"]) + .env_clear() + .envs(env); + + log_step_stream( + format!("Running {}", style::command(cmd.name())), + |stream| { + cmd.stream_output(stream.io(), stream.io()) + .map_err(|error| fun_run::map_which_problem(error, &mut cmd, path_env)) + }, + ) + .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; } AssetCases::PrecompileAndClean => { bullet = bullet.sub_bullet(format!("Compiling assets with cache (detected {rake_assets_precompile} and {rake_assets_clean} via {rake_detect_cmd})")); @@ -119,25 +132,6 @@ pub(crate) fn rake_assets_install( Ok(bullet) } -fn run_rake_assets_precompile(env: &Env) -> Result<(), CmdError> { - let path_env = env.get("PATH").cloned(); - let mut cmd = Command::new("bundle"); - - cmd.args(["exec", "rake", "assets:precompile", "--trace"]) - .env_clear() - .envs(env); - - log_step_stream( - format!("Running {}", style::command(cmd.name())), - |stream| { - cmd.stream_output(stream.io(), stream.io()) - .map_err(|error| fun_run::map_which_problem(error, &mut cmd, path_env)) - }, - )?; - - Ok(()) -} - #[derive(Clone, Debug)] enum AssetCases { None, From 9e11414d3581fee853a19c9aaef9b1011dcbe719 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:47:13 -0500 Subject: [PATCH 29/39] Use value directly --- buildpacks/ruby/src/steps/rake_assets_install.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index 47920df2..1d347035 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -34,9 +34,7 @@ pub(crate) fn rake_assets_install( format!("Compiling assets without cache (Clean task not found via {rake_detect_cmd})"), ).sub_bullet(format!("{help} Enable caching by ensuring {rake_assets_clean} is present when running the detect command locally")); - let path_env = env.get("PATH").cloned(); let mut cmd = Command::new("bundle"); - cmd.args(["exec", "rake", "assets:precompile", "--trace"]) .env_clear() .envs(env); @@ -45,7 +43,9 @@ pub(crate) fn rake_assets_install( format!("Running {}", style::command(cmd.name())), |stream| { cmd.stream_output(stream.io(), stream.io()) - .map_err(|error| fun_run::map_which_problem(error, &mut cmd, path_env)) + .map_err(|error| { + fun_run::map_which_problem(error, &mut cmd, env.get("PATH").cloned()) + }) }, ) .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; From fd0b52d02dfb76fb8f6410d70eaba732a277a7e3 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:48:53 -0500 Subject: [PATCH 30/39] Remove log_* calls in favor of bullet stream --- .../ruby/src/steps/rake_assets_install.rs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index 1d347035..8c561a37 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -4,8 +4,7 @@ use crate::RubyBuildpackError; use bullet_stream::state::SubBullet; use bullet_stream::{style, Print}; use commons::cache::{mib, AppCache, CacheConfig, CacheError, CacheState, KeepPath, PathState}; -use commons::output::section_log::{log_step, log_step_stream}; -use fun_run::{self, CmdError, CommandWithName}; +use fun_run::{self, CommandWithName}; use libcnb::build::BuildContext; use libcnb::Env; use std::io::Stdout; @@ -39,16 +38,15 @@ pub(crate) fn rake_assets_install( .env_clear() .envs(env); - log_step_stream( - format!("Running {}", style::command(cmd.name())), - |stream| { - cmd.stream_output(stream.io(), stream.io()) - .map_err(|error| { - fun_run::map_which_problem(error, &mut cmd, env.get("PATH").cloned()) - }) - }, - ) - .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; + bullet + .stream_with( + format!("Running {}", style::command(cmd.name())), + |stdout, stderr| cmd.stream_output(stdout, stderr), + ) + .map_err(|error| { + fun_run::map_which_problem(error, &mut cmd, env.get("PATH").cloned()) + }) + .map_err(RubyBuildpackError::RakeAssetsPrecompileFailed)?; } AssetCases::PrecompileAndClean => { bullet = bullet.sub_bullet(format!("Compiling assets with cache (detected {rake_assets_precompile} and {rake_assets_clean} via {rake_detect_cmd})")); From 4cee2f2bf7e9789c8b01fe85a1ae729e1ac49eda Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:49:30 -0500 Subject: [PATCH 31/39] Revert changes to AppCacheCollection --- commons/src/cache/app_cache_collection.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/commons/src/cache/app_cache_collection.rs b/commons/src/cache/app_cache_collection.rs index 940ca1ed..fd746b36 100644 --- a/commons/src/cache/app_cache_collection.rs +++ b/commons/src/cache/app_cache_collection.rs @@ -13,11 +13,12 @@ use std::fmt::Debug; /// Default logging is provided for each operation. /// #[derive(Debug)] -pub struct AppCacheCollection { +pub struct AppCacheCollection<'a> { + _log: &'a dyn SectionLogger, collection: Vec, } -impl AppCacheCollection { +impl<'a> AppCacheCollection<'a> { /// Store multiple application paths in the cache /// /// # Errors @@ -28,6 +29,7 @@ impl AppCacheCollection { pub fn new_and_load( context: &BuildContext, config: impl IntoIterator, + log: &'a dyn SectionLogger, ) -> Result { let caches = config .into_iter() @@ -44,7 +46,10 @@ impl AppCacheCollection { }) .collect::, CacheError>>()?; - Ok(Self { collection: caches }) + Ok(Self { + collection: caches, + _log: log, + }) } /// # Errors From d74c55d129b568cc77a7233022315d07f04315da Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:50:34 -0500 Subject: [PATCH 32/39] Deprecate AppCacheCollection --- commons/src/cache.rs | 1 + commons/src/cache/app_cache_collection.rs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/commons/src/cache.rs b/commons/src/cache.rs index f7b2ce22..12e8b3b6 100644 --- a/commons/src/cache.rs +++ b/commons/src/cache.rs @@ -7,6 +7,7 @@ mod in_app_dir_cache_layer; pub use self::app_cache::{build, PathState}; pub use self::app_cache::{AppCache, CacheState}; +#[allow(deprecated)] pub use self::app_cache_collection::AppCacheCollection; pub use self::clean::FilesWithSize; pub use self::config::CacheConfig; diff --git a/commons/src/cache/app_cache_collection.rs b/commons/src/cache/app_cache_collection.rs index fd746b36..ef11e0ad 100644 --- a/commons/src/cache/app_cache_collection.rs +++ b/commons/src/cache/app_cache_collection.rs @@ -13,11 +13,15 @@ use std::fmt::Debug; /// Default logging is provided for each operation. /// #[derive(Debug)] +#[deprecated( + since = "0.1.0", + note = "Use `AppCache` directly to manage cache for a single path" +)] pub struct AppCacheCollection<'a> { _log: &'a dyn SectionLogger, collection: Vec, } - +#[allow(deprecated)] impl<'a> AppCacheCollection<'a> { /// Store multiple application paths in the cache /// From ecf77066faa7ba005fa38799ed35ea5f90696ebd Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:51:23 -0500 Subject: [PATCH 33/39] Remove commons output imports --- buildpacks/ruby/src/steps/get_default_process.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/buildpacks/ruby/src/steps/get_default_process.rs b/buildpacks/ruby/src/steps/get_default_process.rs index 28caa2c8..503ac958 100644 --- a/buildpacks/ruby/src/steps/get_default_process.rs +++ b/buildpacks/ruby/src/steps/get_default_process.rs @@ -1,8 +1,7 @@ use crate::gem_list::GemList; use crate::RubyBuildpack; -use bullet_stream::state::{Bullet, SubBullet}; -use bullet_stream::Print; -use commons::output::{fmt, section_log::log_step}; +use bullet_stream::style; +use bullet_stream::{state::SubBullet, Print}; use libcnb::build::BuildContext; use libcnb::data::launch::Process; use libcnb::data::launch::ProcessBuilder; @@ -15,10 +14,10 @@ pub(crate) fn get_default_process( context: &BuildContext, gem_list: &GemList, ) -> (Print>, Option) { - let config_ru = fmt::value("config.ru"); - let rails = fmt::value("rails"); - let rack = fmt::value("rack"); - let railties = fmt::value("railties"); + let config_ru = style::value("config.ru"); + let rails = style::value("rails"); + let rack = style::value("rack"); + let railties = style::value("railties"); match detect_web(gem_list, &context.app_dir) { WebProcess::Rails => ( bullet.sub_bullet(format!("Detected rails app ({rails} gem found)")), From f0a84db16c1205121ad75161cb9f552a9c48dfd3 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:53:08 -0500 Subject: [PATCH 34/39] Remove commons output imports --- .../ruby/src/steps/detect_rake_tasks.rs | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/buildpacks/ruby/src/steps/detect_rake_tasks.rs b/buildpacks/ruby/src/steps/detect_rake_tasks.rs index c428df7d..4f71f4cc 100644 --- a/buildpacks/ruby/src/steps/detect_rake_tasks.rs +++ b/buildpacks/ruby/src/steps/detect_rake_tasks.rs @@ -1,30 +1,24 @@ -use std::io::Stdout; - -use bullet_stream::state::SubBullet; -use bullet_stream::{style, Print}; -use commons::output::{ - fmt::{self, HELP}, - section_log::log_step, -}; - use crate::gem_list::GemList; use crate::rake_status::{check_rake_ready, RakeStatus}; use crate::rake_task_detect::{self, RakeDetect}; use crate::RubyBuildpack; use crate::RubyBuildpackError; +use bullet_stream::state::SubBullet; +use bullet_stream::{style, Print}; use libcnb::build::BuildContext; use libcnb::Env; +use std::io::Stdout; pub(crate) fn detect_rake_tasks( - mut bullet: Print>, + bullet: Print>, gem_list: &GemList, context: &BuildContext, env: &Env, ) -> Result<(Print>, Option), RubyBuildpackError> { let help = style::important("HELP"); - let rake = fmt::value("rake"); - let gemfile = fmt::value("Gemfile"); - let rakefile = fmt::value("Rakefile"); + let rake = style::value("rake"); + let gemfile = style::value("Gemfile"); + let rakefile = style::value("Rakefile"); match check_rake_ready( &context.app_dir, @@ -38,7 +32,7 @@ pub(crate) fn detect_rake_tasks( )) .sub_bullet(format!( "{help} Add {gem} to your {gemfile} to enable", - gem = fmt::value("gem 'rake'") + gem = style::value("gem 'rake'") )), None, )), @@ -51,7 +45,7 @@ pub(crate) fn detect_rake_tasks( RakeStatus::SkipManifestFound(paths) => { let manifest_files = paths .iter() - .map(|path| fmt::value(path.to_string_lossy())) + .map(|path| style::value(path.to_string_lossy())) .collect::>() .join(", "); @@ -73,7 +67,7 @@ pub(crate) fn detect_rake_tasks( let (bullet, rake_detect) = rake_task_detect::call( bullet.sub_bullet(format!( "Detected rake ({rake} gem found, {rakefile} found at {path})", - path = fmt::value(path.to_string_lossy()) + path = style::value(path.to_string_lossy()) )), env, true, From a7acbe537cb625d02809f5354024ef9a1cfae1d7 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 16:53:48 -0500 Subject: [PATCH 35/39] Remove unused --- buildpacks/ruby/src/main.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index ca15c2e2..5f29d484 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -2,9 +2,6 @@ use bullet_stream::{style, Print}; use commons::cache::CacheError; use commons::gemfile_lock::GemfileLock; use commons::metadata_digest::MetadataDigest; -#[allow(clippy::wildcard_imports)] -use commons::output::build_log::*; -use commons::output::warn_later::WarnGuard; use core::str::FromStr; use fs_err::PathExt; use fun_run::CmdError; @@ -114,8 +111,6 @@ impl Buildpack for RubyBuildpack { #[allow(deprecated)] fn build(&self, context: BuildContext) -> libcnb::Result { let mut build_output = Print::new(stdout()).h2("Heroku Ruby Buildpack"); - let mut logger = BuildLog::new(stdout()).without_buildpack_name(); - let warn_later = WarnGuard::new(stdout()); // ## Set default environment let (mut env, store) = @@ -246,7 +241,6 @@ impl Buildpack for RubyBuildpack { .done() }; build_output.done(); - warn_later.warn_now(); if let Some(default_process) = default_process { BuildResultBuilder::new() From 2b8a261d68366b2881a811d9d38ab00ceb141aa6 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 19:15:03 -0500 Subject: [PATCH 36/39] Remove clippy allow --- buildpacks/ruby/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index 5f29d484..62e42c29 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -108,7 +108,6 @@ impl Buildpack for RubyBuildpack { } #[allow(clippy::too_many_lines)] - #[allow(deprecated)] fn build(&self, context: BuildContext) -> libcnb::Result { let mut build_output = Print::new(stdout()).h2("Heroku Ruby Buildpack"); From dcd03fdd54c529dd8cfe4f5b53d30d3770d7259b Mon Sep 17 00:00:00 2001 From: Richard Schneeman Date: Tue, 15 Oct 2024 12:24:59 -0500 Subject: [PATCH 37/39] Update buildpacks/ruby/src/steps/rake_assets_install.rs Co-authored-by: Rune Soerensen --- buildpacks/ruby/src/steps/rake_assets_install.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildpacks/ruby/src/steps/rake_assets_install.rs b/buildpacks/ruby/src/steps/rake_assets_install.rs index 8c561a37..58938d35 100644 --- a/buildpacks/ruby/src/steps/rake_assets_install.rs +++ b/buildpacks/ruby/src/steps/rake_assets_install.rs @@ -65,8 +65,8 @@ pub(crate) fn rake_assets_install( ]; let caches = cache_config - .iter() - .map(|config| AppCache::new_and_load(context, config.to_owned())) + .into_iter() + .map(|config| AppCache::new_and_load(context, config)) .collect::, CacheError>>() .map_err(RubyBuildpackError::InAppDirCacheError)?; From c0471752954d2eecbce1db7979bb320efeb46d9a Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 15 Oct 2024 12:26:34 -0500 Subject: [PATCH 38/39] Changelog entry --- commons/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commons/CHANGELOG.md b/commons/CHANGELOG.md index 4d5a51b2..1a476af4 100644 --- a/commons/CHANGELOG.md +++ b/commons/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog for commons features +## 2024-08-15 + +- Deprecate `AppCacheCollection` (https://github.com/heroku/buildpacks-ruby/pull/334) + ## 1.0.0 ### Changed From 4f2c9ea654be91b7fe946cf643ff78775998463a Mon Sep 17 00:00:00 2001 From: Richard Schneeman Date: Tue, 15 Oct 2024 13:39:49 -0500 Subject: [PATCH 39/39] Update commons/CHANGELOG.md Co-authored-by: Rune Soerensen --- commons/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commons/CHANGELOG.md b/commons/CHANGELOG.md index 1a476af4..5889f3cc 100644 --- a/commons/CHANGELOG.md +++ b/commons/CHANGELOG.md @@ -2,6 +2,8 @@ ## 2024-08-15 +### Changed + - Deprecate `AppCacheCollection` (https://github.com/heroku/buildpacks-ruby/pull/334) ## 1.0.0