homebrew-core/Formula/uutils-coreutils.rb

83 lines
3.0 KiB
Ruby

class UutilsCoreutils < Formula
desc "Cross-platform Rust rewrite of the GNU coreutils"
homepage "https://github.com/uutils/coreutils"
url "https://github.com/uutils/coreutils/archive/0.0.7.tar.gz"
sha256 "066359e9548940ee99c3d8911e951d5091aa1f2d7d409cb577c811f3993a1e7d"
license "MIT"
head "https://github.com/uutils/coreutils.git", branch: "master"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "d36cc1ff02e590820905007cb38dbf301b8876f9819e40e25a68b8174e3a8db4"
sha256 cellar: :any_skip_relocation, big_sur: "da3f830dd5b8e000a1034fc774fa5e94f7be860f17d00cedfb5b1c07bbd03dea"
sha256 cellar: :any_skip_relocation, catalina: "b6b0a749cf8c48a20ec5ada4d027052ba7ae8a8b008ce5f63a765224e03e32ec"
sha256 cellar: :any_skip_relocation, mojave: "e47dd3b756765216dc9200c0afdddbc05519b5263a4729a847d4fd2fb978a51f"
sha256 cellar: :any_skip_relocation, x86_64_linux: "d00eed1d93ef0748c7def130f03065e27e41e81d7a6a42ce24df633d6827b5f1"
end
depends_on "make" => :build
depends_on "rust" => :build
depends_on "sphinx-doc" => :build
conflicts_with "coreutils", because: "uutils-coreutils and coreutils install the same binaries"
conflicts_with "aardvark_shell_utils", because: "both install `realpath` binaries"
conflicts_with "truncate", because: "both install `truncate` binaries"
def install
man1.mkpath
ENV.prepend_path "PATH", Formula["make"].opt_libexec/"gnubin"
system "make", "install",
"PROG_PREFIX=u",
"PREFIX=#{prefix}",
"SPHINXBUILD=#{Formula["sphinx-doc"].opt_bin}/sphinx-build"
# Symlink all commands into libexec/uubin without the 'u' prefix
coreutils_filenames(bin).each do |cmd|
(libexec/"uubin").install_symlink bin/"u#{cmd}" => cmd
end
# Symlink all man(1) pages into libexec/uuman without the 'u' prefix
coreutils_filenames(man1).each do |cmd|
(libexec/"uuman"/"man1").install_symlink man1/"u#{cmd}" => cmd
end
libexec.install_symlink "uuman" => "man"
# Symlink non-conflicting binaries
%w[
base32 dircolors factor hashsum hostid nproc numfmt pinky ptx realpath
shred shuf stdbuf tac timeout truncate
].each do |cmd|
bin.install_symlink "u#{cmd}" => cmd
man1.install_symlink "u#{cmd}.1.gz" => "#{cmd}.1.gz"
end
end
def caveats
<<~EOS
Commands also provided by macOS have been installed with the prefix "u".
If you need to use these commands with their normal names, you
can add a "uubin" directory to your PATH from your bashrc like:
PATH="#{opt_libexec}/uubin:$PATH"
EOS
end
def coreutils_filenames(dir)
filenames = []
dir.find do |path|
next if path.directory? || path.basename.to_s == ".DS_Store"
filenames << path.basename.to_s.sub(/^u/, "")
end
filenames.sort
end
test do
(testpath/"test").write("test")
(testpath/"test.sha1").write("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 test")
system bin/"uhashsum", "--sha1", "-c", "test.sha1"
system bin/"uln", "-f", "test", "test.sha1"
end
end