Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Oct 3, 2023
1 parent 5155a44 commit 751a363
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 54 deletions.
27 changes: 27 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions buildpacks/ruby/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Update build logging style (https://github.com/heroku/buildpacks-ruby/pull/198)

## [2.1.0] - 2023-09-26

### Added
Expand Down
4 changes: 2 additions & 2 deletions buildpacks/ruby/src/layers/bundle_download_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ impl<'a> Layer for BundleDownloadLayer<'a> {
let short_name = fun_run::display(&mut cmd);

// Arguments we don't need in the output
cmd.mut_cmd().args([
cmd.args([
"--install-dir", // Directory where bundler's contents will live
&layer_path.to_string_lossy(),
"--bindir", // Directory where `bundle` executable lives
&bin_dir.to_string_lossy(),
"--force",
"--force", // Overwrite if it already exists
"--no-document", // Don't install ri or rdoc documentation, which takes extra time
"--env-shebang", // Start the `bundle` executable with `#! /usr/bin/env ruby`
]);
Expand Down
9 changes: 4 additions & 5 deletions buildpacks/ruby/src/layers/bundle_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,16 @@ impl Layer for BundleInstallLayer<'_> {
bundle_install(&env).map_err(RubyBuildpackError::BundleInstallCommandError)?;
}
UpdateState::Skip(checked) => {
let checked = SentenceList::new(&checked).join_str("or");
let bundle_install = fmt::value("bundle install");
let env_var = fmt::value(format!("{HEROKU_SKIP_BUNDLE_DIGEST}=1"));

log_step(format!(
"Skipping {bundle_install} {}",
fmt::details(format!("no changes found in {checked}"))
"Skipping {bundle_install} (no changes found in {sources})",
sources = SentenceList::new(&checked).join_str("or")
));

log_step(format!(
"{HELP} To force run {bundle_install} set {env_var}",
"{HELP} To force run {bundle_install} set {}",
fmt::value(format!("{HEROKU_SKIP_BUNDLE_DIGEST}=1"))
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/ruby/src/layers/metrics_agent_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'a> Layer for MetricsAgentInstall<'a> {
LayerResultBuilder::new(Metadata {
download_url: Some(DOWNLOAD_URL.to_string()),
})
.exec_d_program("spawn agentmon", execd)
.exec_d_program("spawn_metrics_agent", execd)
.build()
}

Expand Down
1 change: 0 additions & 1 deletion buildpacks/ruby/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ impl Buildpack for RubyBuildpack {
};

// ## Install executable ruby version

(logger, env) = {
let section = logger.section(&format!(
"Ruby version {} from {}",
Expand Down
1 change: 1 addition & 0 deletions commons/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ thiserror = "1"
walkdir = "2"
which_problem = "0.1"
ascii_table = { version = "4.0.2", features = ["color_codes"] }
const_format = "0.2.31"

[dev-dependencies]
indoc = "2.0.1"
Expand Down
20 changes: 3 additions & 17 deletions commons/src/output/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::output::util::LinesWithEndings;
use const_format::formatcp;

/// Helpers for formatting and colorizing your output
/// Decorated str for prefixing "Help:"
pub const HELP: &str = "\x1B[0;36m! Help:\x1B[0m"; // "{IMPORTANT_COLOR}! HELP{RESET}"
pub const HELP: &str = formatcp!("{IMPORTANT_COLOR}! HELP{RESET}");

/// Decorated str for prefixing "Debug info:"
pub const DEBUG_INFO: &str = "\x1B[0;36mDebug info:\x1B[0m"; // "{IMPORTANT_COLOR}Debug info:{RESET}"
pub const DEBUG_INFO: &str = formatcp!("{IMPORTANT_COLOR}Debug info{RESET}");

/// Decorate a URL for the build output
#[must_use]
Expand Down Expand Up @@ -175,21 +176,6 @@ pub(crate) fn prepend_each_line(
})
.collect::<String>();
lines

// if body.trim().is_empty() {
// format!("{prepend}\n")
// } else {
// body.split('\n')
// .map(|section| {
// if section.trim().is_empty() {
// prepend.to_string()
// } else {
// format!("{prepend}{separator}{section}")
// }
// })
// .collect::<Vec<String>>()
// .join("\n")
// }
}

/// Colorizes a body while preserving existing color/reset combinations and clearing before newlines
Expand Down
7 changes: 7 additions & 0 deletions commons/src/output/interface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use std::fmt::Debug;
use std::io::Write;

/// Consuming stateful logger interface
///
/// The log pattern used by `BuildLog` is a consuming state machine that is designed to minimize
/// the amount of mistakes that can result in malformed build output.
///
/// The interface isn't stable and may need to change.
pub trait Logger: Debug {
fn buildpack_name(self, s: &str) -> Box<dyn StartedLogger>;
fn without_buildpack_name(self) -> Box<dyn StartedLogger>;
Expand Down
52 changes: 26 additions & 26 deletions commons/src/output/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ where
arc: Arc<Mutex<W>>,
}

impl<W> Clone for ReadYourWrite<W>
where
W: Write + AsRef<[u8]> + Debug,
{
fn clone(&self) -> Self {
Self {
arc: self.arc.clone(),
}
}
}

impl<W> Write for ReadYourWrite<W>
where
W: Write + AsRef<[u8]> + Debug,
{
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let mut writer = self.arc.lock().expect("Internal error");
writer.write(buf)
}

fn flush(&mut self) -> std::io::Result<()> {
let mut writer = self.arc.lock().expect("Internal error");
writer.flush()
}
}

impl<W> ReadYourWrite<W>
where
W: Write + AsRef<[u8]>,
Expand Down Expand Up @@ -75,32 +101,6 @@ where
}
}

impl<W> Clone for ReadYourWrite<W>
where
W: Write + AsRef<[u8]> + Debug,
{
fn clone(&self) -> Self {
Self {
arc: self.arc.clone(),
}
}
}

impl<W> Write for ReadYourWrite<W>
where
W: Write + AsRef<[u8]> + Debug,
{
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let mut writer = self.arc.lock().expect("Internal error");
writer.write(buf)
}

fn flush(&mut self) -> std::io::Result<()> {
let mut writer = self.arc.lock().expect("Internal error");
writer.flush()
}
}

/// Iterator yielding every line in a string. The line includes newline character(s).
///
/// <https://stackoverflow.com/a/40457615>
Expand Down
4 changes: 2 additions & 2 deletions commons/src/output/warn_later.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ thread_local!(static WARN_LATER: RefCell<Option<Vec<String>>> = RefCell::new(Non
/// let warn_later = WarnGuard::new(std::io::stdout());
/// // ...
///
/// // Warnings will be emitted if the warn guard is dropped
/// // Warnings will be emitted when the warn guard is dropped
/// drop(warn_later);
/// // }
/// ```
Expand Down Expand Up @@ -105,7 +105,7 @@ pub(crate) fn try_push(s: impl AsRef<str>) -> Result<(), WarnLaterError> {
///
/// Should only ever be used within a `WarnGuard`.
///
/// The state where the warnings are taken but a warn guard is still present
/// The state where the warnings are taken, but a warn guard is still present
/// can happen when more than one warn guard is created in the same thread
fn force_push(s: impl AsRef<str>) {
WARN_LATER.with(|cell| {
Expand Down

0 comments on commit 751a363

Please sign in to comment.