From 6f53567aa8ffbb1e54ad24e3d90def1acd08ae6d Mon Sep 17 00:00:00 2001 From: Bob van der Linden Date: Fri, 10 Feb 2023 09:24:41 +0100 Subject: [PATCH] rubyfmt: init at 0.8.1 --- .../0001-cargo-lock-update-version.patch | 25 ++++++++ .../0002-remove-dependency-on-git.patch | 62 +++++++++++++++++++ pkgs/development/tools/rubyfmt/default.nix | 57 +++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 4 files changed, 146 insertions(+) create mode 100644 pkgs/development/tools/rubyfmt/0001-cargo-lock-update-version.patch create mode 100644 pkgs/development/tools/rubyfmt/0002-remove-dependency-on-git.patch create mode 100644 pkgs/development/tools/rubyfmt/default.nix diff --git a/pkgs/development/tools/rubyfmt/0001-cargo-lock-update-version.patch b/pkgs/development/tools/rubyfmt/0001-cargo-lock-update-version.patch new file mode 100644 index 000000000000..d2bf9f9431ca --- /dev/null +++ b/pkgs/development/tools/rubyfmt/0001-cargo-lock-update-version.patch @@ -0,0 +1,25 @@ +From d9df7aaaaf9c758499f569376a041045d99e4015 Mon Sep 17 00:00:00 2001 +From: Bob van der Linden +Date: Thu, 9 Feb 2023 16:17:46 +0100 +Subject: [PATCH 1/2] cargo: lock: update version + +--- + Cargo.lock | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Cargo.lock b/Cargo.lock +index 79a81d1..374c10a 100644 +--- a/Cargo.lock ++++ b/Cargo.lock +@@ -642,7 +642,7 @@ dependencies = [ + + [[package]] + name = "rubyfmt-main" +-version = "0.8.0-pre" ++version = "0.8.1" + dependencies = [ + "atty", + "clap", +-- +2.39.1 + diff --git a/pkgs/development/tools/rubyfmt/0002-remove-dependency-on-git.patch b/pkgs/development/tools/rubyfmt/0002-remove-dependency-on-git.patch new file mode 100644 index 000000000000..d7e3b90ab79f --- /dev/null +++ b/pkgs/development/tools/rubyfmt/0002-remove-dependency-on-git.patch @@ -0,0 +1,62 @@ +From 3bbc396c4ddc8a5e26f7776155bb366c8d47c440 Mon Sep 17 00:00:00 2001 +From: Bob van der Linden +Date: Thu, 9 Feb 2023 16:55:00 +0100 +Subject: [PATCH 2/2] remove dependency on git + +--- + librubyfmt/build.rs | 35 +++-------------------------------- + 1 file changed, 3 insertions(+), 32 deletions(-) + +diff --git a/librubyfmt/build.rs b/librubyfmt/build.rs +index ef94c09..4668785 100644 +--- a/librubyfmt/build.rs ++++ b/librubyfmt/build.rs +@@ -26,27 +26,9 @@ fn main() -> Output { + let path = std::env::current_dir()?; + let ruby_checkout_path = path.join("ruby_checkout"); + +- let old_checkout_sha = if ruby_checkout_path.join(ripper).exists() { +- Some(get_ruby_checkout_sha()) +- } else { +- None +- }; +- +- let _ = Command::new("git") +- .args(&["submodule", "update", "--init"]) +- .status(); +- +- let new_checkout_sha = get_ruby_checkout_sha(); +- +- // Only rerun this build if the ruby_checkout has changed +- match old_checkout_sha { +- Some(old_sha) if old_sha == new_checkout_sha => {} +- _ => { +- make_configure(&ruby_checkout_path)?; +- run_configure(&ruby_checkout_path)?; +- build_ruby(&ruby_checkout_path)?; +- } +- } ++ make_configure(&ruby_checkout_path)?; ++ run_configure(&ruby_checkout_path)?; ++ build_ruby(&ruby_checkout_path)?; + + cc::Build::new() + .file("src/rubyfmt.c") +@@ -152,14 +134,3 @@ fn check_process_success(command: &str, code: ExitStatus) -> Output { + } + } + +-fn get_ruby_checkout_sha() -> String { +- String::from_utf8( +- Command::new("git") +- .args(&["rev-parse", "HEAD"]) +- .current_dir("./ruby_checkout") +- .output() +- .expect("git rev-parse shouldn't fail") +- .stdout, +- ) +- .expect("output should be valid utf8") +-} +-- +2.39.1 + diff --git a/pkgs/development/tools/rubyfmt/default.nix b/pkgs/development/tools/rubyfmt/default.nix new file mode 100644 index 000000000000..177444370ad8 --- /dev/null +++ b/pkgs/development/tools/rubyfmt/default.nix @@ -0,0 +1,57 @@ +{ lib +, rustPlatform +, fetchFromGitHub +, autoconf +, automake +, bison +, ruby +, zlib +, libxcrypt +}: + +rustPlatform.buildRustPackage rec { + pname = "rubyfmt"; + version = "0.8.1"; + + src = fetchFromGitHub { + owner = "fables-tales"; + repo = "rubyfmt"; + rev = "v${version}"; + hash = "sha256-lHq9lcLMp6HUHMonEe3T2YGwMYW1W131H1jo1cy6kyc="; + fetchSubmodules = true; + }; + + nativeBuildInputs = [ + autoconf + automake + bison + ruby + ]; + + buildInputs = [ + zlib + libxcrypt + ]; + + cargoPatches = [ + # The 0.8.1 release did not have an up-to-date lock file. The rubyfmt + # version in Cargo.toml was bumped, but it wasn't updated in the lock file. + ./0001-cargo-lock-update-version.patch + + # Avoid checking whether ruby gitsubmodule is up-to-date. + ./0002-remove-dependency-on-git.patch + ]; + + cargoHash = "sha256-keeIonGNgE0U0IVi8DeXAy6ygTXVXH+WDjob36epUDI="; + + preFixup = '' + mv $out/bin/rubyfmt{-main,} + ''; + + meta = with lib; { + description = "A Ruby autoformatter"; + homepage = "https://github.com/fables-tales/rubyfmt"; + license = licenses.mit; + maintainers = with maintainers; [ bobvanderlinden ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ff1cb1d7361b..5a691e3d895e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17863,6 +17863,8 @@ with pkgs; rbenv = callPackage ../development/ruby-modules/rbenv { }; + rubyfmt = callPackage ../development/tools/rubyfmt { }; + inherit (callPackage ../development/interpreters/ruby { inherit (darwin) libobjc libunwind; inherit (darwin.apple_sdk.frameworks) Foundation;