Skip to content

Commit

Permalink
Move fun_run to its own crate
Browse files Browse the repository at this point in the history
The `fun_run` library is small but it can stand on its own. I ported it to a crate as an exercise in code cleanup and to remove unnecessary dependencies.
  • Loading branch information
schneems committed Nov 2, 2023
1 parent 4f514f6 commit 2fb195e
Showing 19 changed files with 43 additions and 653 deletions.
16 changes: 14 additions & 2 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
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- The `fun_run` commons library was moved to it's own crate ()

## [2.1.2] - 2023-10-31

### Fixed
1 change: 1 addition & 0 deletions buildpacks/ruby/Cargo.toml
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ thiserror = "1"
ureq = "2"
url = "2"
clap = { version = "4", features = ["derive"] }
fun_run = { version = "0.1", features = ["which_problem"] }

[dev-dependencies]
libcnb-test = "=0.15.0"
2 changes: 1 addition & 1 deletion buildpacks/ruby/src/bin/agentmon_loop.rs
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ where
let mut cmd = Command::new(path);
cmd.args(args);

eprintln!("Running: {}", commons::fun_run::display(&mut cmd));
eprintln!("Running: {}", fun_run::display(&mut cmd));

cmd.status()
}
2 changes: 1 addition & 1 deletion buildpacks/ruby/src/bin/launch_daemon.rs
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ fn main() {
command.status().unwrap_or_else(|error| {
eprintln!(
"Command failed {}. Details: {error}",
commons::fun_run::display(&mut command)
fun_run::display(&mut command)
);
exit(1)
});
2 changes: 1 addition & 1 deletion buildpacks/ruby/src/gem_list.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use commons::fun_run::{CmdError, CommandWithName};
use commons::gem_version::GemVersion;
use commons::output::{
fmt,
section_log::{log_step_timed, SectionLogger},
};
use core::str::FromStr;
use fun_run::{CmdError, CommandWithName};
use regex::Regex;
use std::collections::HashMap;
use std::ffi::OsStr;
2 changes: 1 addition & 1 deletion buildpacks/ruby/src/layers/bundle_download_layer.rs
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ use commons::output::{

use crate::RubyBuildpack;
use crate::RubyBuildpackError;
use commons::fun_run::{self, CommandWithName};
use commons::gemfile_lock::ResolvedBundlerVersion;
use fun_run::{self, CommandWithName};
use libcnb::build::BuildContext;
use libcnb::data::layer_content_metadata::LayerTypes;
use libcnb::layer::{ExistingLayerStrategy, Layer, LayerData, LayerResult, LayerResultBuilder};
8 changes: 3 additions & 5 deletions buildpacks/ruby/src/layers/bundle_install_layer.rs
Original file line number Diff line number Diff line change
@@ -4,13 +4,11 @@ use commons::output::{
};

use crate::{BundleWithout, RubyBuildpack, RubyBuildpackError};
use commons::fun_run::CommandWithName;
use commons::{
display::SentenceList,
fun_run::{self, CmdError},
gemfile_lock::ResolvedRubyVersion,
metadata_digest::MetadataDigest,
display::SentenceList, gemfile_lock::ResolvedRubyVersion, metadata_digest::MetadataDigest,
};
use fun_run::CommandWithName;
use fun_run::{self, CmdError};
use libcnb::{
build::BuildContext,
data::{buildpack::StackId, layer_content_metadata::LayerTypes},
2 changes: 1 addition & 1 deletion buildpacks/ruby/src/main.rs
Original file line number Diff line number Diff line change
@@ -2,13 +2,13 @@
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
use commons::cache::CacheError;
use commons::fun_run::CmdError;
use commons::gemfile_lock::GemfileLock;
use commons::metadata_digest::MetadataDigest;
use commons::output::warn_later::WarnGuard;
#[allow(clippy::wildcard_imports)]
use commons::output::{build_log::*, fmt};
use core::str::FromStr;
use fun_run::CmdError;
use layers::{
bundle_download_layer::{BundleDownloadLayer, BundleDownloadLayerMetadata},
bundle_install_layer::{BundleInstallLayer, BundleInstallLayerMetadata},
2 changes: 1 addition & 1 deletion buildpacks/ruby/src/rake_task_detect.rs
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ use commons::output::{
section_log::{log_step_timed, SectionLogger},
};

use commons::fun_run::{CmdError, CommandWithName};
use core::str::FromStr;
use fun_run::{CmdError, CommandWithName};
use std::{ffi::OsStr, process::Command};

/// Run `rake -P` and parse output to show what rake tasks an application has
2 changes: 1 addition & 1 deletion buildpacks/ruby/src/steps/rake_assets_install.rs
Original file line number Diff line number Diff line change
@@ -2,11 +2,11 @@ use crate::rake_task_detect::RakeDetect;
use crate::RubyBuildpack;
use crate::RubyBuildpackError;
use commons::cache::{mib, AppCacheCollection, CacheConfig, KeepPath};
use commons::fun_run::{self, CmdError, CommandWithName};
use commons::output::{
fmt::{self, HELP},
section_log::{log_step, log_step_stream, SectionLogger},
};
use fun_run::{self, CmdError, CommandWithName};
use libcnb::build::BuildContext;
use libcnb::Env;
use std::process::Command;
2 changes: 1 addition & 1 deletion buildpacks/ruby/src/user_errors.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use commons::output::{
};

use crate::RubyBuildpackError;
use commons::fun_run::{CmdError, CommandWithName};
use fun_run::{CmdError, CommandWithName};
use indoc::formatdoc;

pub(crate) fn on_error(err: libcnb::Error<RubyBuildpackError>) {
7 changes: 7 additions & 0 deletions commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog for commons features

## 1.0.0

### Changed

- Move `fun_run` commons library to it's own crate ()
4 changes: 2 additions & 2 deletions commons/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "commons"
version = "0.1.0"
version = "1.0.0"
edition = "2021"
publish = false

@@ -26,9 +26,9 @@ sha2 = "0.10"
tempfile = "3"
thiserror = "1"
walkdir = "2"
which_problem = "0.1"
ascii_table = { version = "4", features = ["color_codes"] }
const_format = "0.2"
fun_run = "0.1"

[dev-dependencies]
indoc = "2"
2 changes: 1 addition & 1 deletion commons/bin/print_style_guide.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use ascii_table::AsciiTable;
use commons::fun_run::CommandWithName;
use commons::output::fmt::{self, DEBUG_INFO, HELP};
use commons::output::{
build_log::*,
section_log::{log_step, log_step_stream, log_step_timed},
};
use fun_run::CommandWithName;
use indoc::formatdoc;
use std::io::stdout;
use std::process::Command;
57 changes: 0 additions & 57 deletions commons/src/err.rs

This file was deleted.

Loading

0 comments on commit 2fb195e

Please sign in to comment.