|
| 1 | +class GoLibrespot < Formula |
| 2 | + desc "Spotify client" |
| 3 | + homepage "https://github.com/devgianlu/go-librespot" |
| 4 | + url "https://github.com/devgianlu/go-librespot/archive/refs/tags/v0.3.3.tar.gz" |
| 5 | + sha256 "15678b4d6954b381fb9c5a84aca2b0d7706e4d0b2c3644bafcb79cea6d31064c" |
| 6 | + license "GPL-3.0-only" |
| 7 | + head "https://github.com/devgianlu/go-librespot.git", branch: "master" |
| 8 | + |
| 9 | + bottle do |
| 10 | + sha256 cellar: :any, arm64_sequoia: "83579e3caa527e18316188069045476c5976008ac15ae9ea16c4c8a70b47906c" |
| 11 | + sha256 cellar: :any, arm64_sonoma: "6e9b1274855e8d421367fdb84a918ac7235c107f5b107fcc529e538e2dbc60f7" |
| 12 | + sha256 cellar: :any, arm64_ventura: "48360bf34f1fa7396224cd8301991d8dd95067c95d29ab1d2e4d4683103e7140" |
| 13 | + sha256 cellar: :any, sonoma: "cc0e07fd00c3638e397ff8988f2aa287a1a688ef48648119d6d73a36945df4a9" |
| 14 | + sha256 cellar: :any, ventura: "c69cdd6d48c67941d4ef22225b7c755e53c772dc81bcab61ce4593b5211475a7" |
| 15 | + sha256 cellar: :any_skip_relocation, x86_64_linux: "41a8f04961a86a633373480afe82f53debbe61d891a8171af57fd587dff441c7" |
| 16 | + end |
| 17 | + |
| 18 | + depends_on "go" => :build |
| 19 | + depends_on "pkgconf" => :build |
| 20 | + depends_on "libogg" |
| 21 | + depends_on "libvorbis" |
| 22 | + |
| 23 | + on_linux do |
| 24 | + depends_on "alsa-lib" |
| 25 | + end |
| 26 | + |
| 27 | + def install |
| 28 | + ldflags = %W[ |
| 29 | + -s -w |
| 30 | + -X github.com/devgianlu/go-librespot.version=#{version} |
| 31 | + ] |
| 32 | + ldflags << "-X github.com/devgianlu/go-librespot.commit=#{Utils.git_short_head(length: 8)}" if build.head? |
| 33 | + |
| 34 | + system "go", "build", *std_go_args(output: bin/"go-librespot", ldflags: ldflags), "./cmd/daemon" |
| 35 | + |
| 36 | + # On macOS, create a minimal config that selects the correct backend. |
| 37 | + return unless OS.mac? |
| 38 | + |
| 39 | + (buildpath/"config.yml").write <<~YAML |
| 40 | + # Auto-generated by Homebrew. You can edit this file. |
| 41 | + # Use CoreAudio via AudioToolbox on macOS. |
| 42 | + audio_backend: audio-toolbox |
| 43 | + YAML |
| 44 | + pkgetc.install "config.yml" |
| 45 | + end |
| 46 | + |
| 47 | + def post_install |
| 48 | + (var/"log").mkpath |
| 49 | + end |
| 50 | + |
| 51 | + service do |
| 52 | + run [opt_bin/"go-librespot", "--config_dir", etc/"go-librespot"] |
| 53 | + keep_alive true |
| 54 | + log_path var/"log/go-librespot.log" |
| 55 | + error_log_path var/"log/go-librespot.log" |
| 56 | + end |
| 57 | + |
| 58 | + test do |
| 59 | + cfg = testpath/"config.yml" |
| 60 | + cfg.write <<~YAML |
| 61 | + volume_steps: not_a_number |
| 62 | + YAML |
| 63 | + |
| 64 | + output = shell_output("#{bin}/go-librespot --config_dir #{testpath} 2>&1", 1) |
| 65 | + assert_match "failed loading config", output |
| 66 | + assert_match "failed to unmarshal configuration", output |
| 67 | + end |
| 68 | +end |
0 commit comments