homebrew-core/Formula/signal-cli.rb

87 lines
4.1 KiB
Ruby

class SignalCli < Formula
desc "CLI and dbus interface for WhisperSystems/libsignal-service-java"
homepage "https://github.com/AsamK/signal-cli"
url "https://github.com/AsamK/signal-cli/archive/refs/tags/v0.11.6.tar.gz"
sha256 "ed2fed353630891f7c6b723f13cb1e586e079eb45e31bdaf2132d9e9cd583a2c"
license "GPL-3.0-or-later"
bottle do
sha256 cellar: :any_skip_relocation, arm64_ventura: "600a098aadabe44498840cab0eadd54fc5a987cfb9cce97f153eedc1858e371f"
sha256 cellar: :any_skip_relocation, arm64_monterey: "2ac10c81223ad1dfcf3ee8f4fc0bcf76f43edac978e0b9712310cd31706b7542"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "b039febdf9edca4f1365355901c766fc4c4032818b1df4e89f833866f339a33d"
sha256 cellar: :any_skip_relocation, ventura: "828f5a88a9aaa0c1b12e621f3a65be103ff4fb6a1d110c813c063943c237c5a9"
sha256 cellar: :any_skip_relocation, monterey: "64a7c69e95cc3c7cefea33e489729b55962c1e472c11266287ac358a52aaf207"
sha256 cellar: :any_skip_relocation, big_sur: "f01382d3c8699a5495dc733b7a73d35ba438ddd70f8b2c8ddb21033c944b4f40"
sha256 cellar: :any_skip_relocation, x86_64_linux: "210f773da5337aad4bd7f80c6dc48f7f47a407aa68a1b297287c28d47c31d045"
end
depends_on "cmake" => :build # For `boring-sys` crate in `libsignal-client`
depends_on "gradle" => :build
depends_on "protobuf" => :build
# the libsignal-client build targets a specific rustc listed in the file
# https://github.com/signalapp/libsignal/blob/#{libsignal-client.version}/rust-toolchain
# which doesn't automatically happen if we use brew-installed rust. rustup-init
# allows us to use a toolchain that lives in HOMEBREW_CACHE
depends_on "rustup-init" => :build
depends_on "openjdk"
uses_from_macos "llvm" => :build # For `libclang`, used by `boring-sys` crate
uses_from_macos "zip" => :build
# per https://github.com/AsamK/signal-cli/wiki/Provide-native-lib-for-libsignal#libsignal-client
# we want the specific libsignal-client version from 'signal-cli-#{version}/lib/libsignal-client-X.X.X.jar'
resource "libsignal-client" do
url "https://github.com/signalapp/libsignal/archive/refs/tags/v0.21.1.tar.gz"
sha256 "1dd527ea0f5e7bb37c855b2e092d8b6d3ae496fd22f2c9684501c29c36c106cc"
end
def install
system "gradle", "build"
system "gradle", "installDist"
libexec.install (buildpath/"build/install/signal-cli").children
(libexec/"bin/signal-cli.bat").unlink
(bin/"signal-cli").write_env_script libexec/"bin/signal-cli", Language::Java.overridable_java_home_env
# this will install the necessary cargo/rustup toolchain bits in HOMEBREW_CACHE
system Formula["rustup-init"].bin/"rustup-init", "-qy", "--no-modify-path"
ENV.prepend_path "PATH", HOMEBREW_CACHE/"cargo_cache/bin"
resource("libsignal-client").stage do |r|
# https://github.com/AsamK/signal-cli/wiki/Provide-native-lib-for-libsignal#building-libsignal-client-yourself
libsignal_client_jar = libexec.glob("lib/libsignal-client-*.jar").first
embedded_jar_version = Version.new(libsignal_client_jar.to_s[/libsignal-client-(.*)\.jar$/, 1])
odie "#{r.name} needs to be updated to #{embedded_jar_version}!" unless embedded_jar_version == r.version
# rm originally-embedded libsignal_jni lib
system "zip", "-d", libsignal_client_jar, "libsignal_jni.so", "libsignal_jni.dylib", "signal_jni.dll"
# build & embed library for current platform
cd "java" do
inreplace "settings.gradle", "include ':android'", ""
system "./build_jni.sh", "desktop"
cd "shared/resources" do
system "zip", "-u", libsignal_client_jar, shared_library("libsignal_jni")
end
end
end
end
test do
# test 1: checks class loading is working and version is correct
output = shell_output("#{bin}/signal-cli --version")
assert_match "signal-cli #{version}", output
# test 2: ensure crypto is working
begin
io = IO.popen("#{bin}/signal-cli link", err: [:child, :out])
sleep 24
ensure
Process.kill("SIGINT", io.pid)
Process.wait(io.pid)
end
assert_match "sgnl://linkdevice?uuid=", io.read
end
end