diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f3700c0..f4a744b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,7 +39,9 @@ jobs: - run: brew test-bot --only-tap-syntax - - run: brew test-bot --only-formulae + - run: | + brew install golang + brew test-bot --only-formulae if: github.event_name == 'pull_request' - name: Upload bottles as artifact diff --git a/lib/base.rb b/lib/base.rb index 4a0c60b..dec1f58 100644 --- a/lib/base.rb +++ b/lib/base.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "macho" # Ensure ruby-macho is required - class XiondBase < Formula desc "Generalized Blockchain Abstraction Layer" homepage "https://xion.burnt.com" @@ -18,11 +16,19 @@ def self.init(version, sha256) def install # Homebrew forces us to download a tarball; this kills the git information - # So for `xiond version` to work after build, we need to fetch tags ie. nuke buildpath and clone the repo - Dir.chdir("/tmp") do - remove_dir(buildpath, true) - Dir.mkdir(buildpath) - system "git", "clone", "--depth", "1", "--branch", "v#{version}", "https://github.com/burnt-labs/xion.git", buildpath + # So for `xiond version` to work after build, we need to fetch tags + # i.e., nuke buildpath and clone the repo + ohai "Cloning Xion repository to restore git information" + rm_rf(buildpath) + git_clone_url = "https://github.com/burnt-labs/xion.git" + + # Ensure the parent directory of buildpath exists + parent_dir = Pathname.new(buildpath).parent + parent_dir.mkpath + + # Change to a safe working directory before cloning + Dir.chdir(parent_dir) do + system "git", "clone", "--depth", "1", "--branch", "v#{version}", git_clone_url, buildpath end # Change back to buildpath and perform installation @@ -36,7 +42,7 @@ def install def setup_go_environment go_bin = which("go") || Formula["go"].opt_bin - raise "Go is not installed. Please install Go and try again." if go_bin.nil? + raise "Go is not installed. Please run `brew install golang` and then retry this install." if go_bin.nil? ENV.prepend_path "PATH", go_bin end @@ -57,8 +63,9 @@ def fetch_and_verify_libwasmvm def verify_checksum(file) checksum_expected = `grep '#{File.basename(file)}' #{buildpath}/checksums.txt | cut -d ' ' -f 1`.strip checksum_actual = `shasum -a 256 #{file} | cut -d ' ' -f 1`.strip - diewith = "SHA256 mismatch in #{file}! Expected: #{checksum_expected}, Actual: #{checksum_actual}" - odie diewith if checksum_actual != checksum_expected + return if checksum_actual == checksum_expected + + odie "SHA256 mismatch in #{file}! Expected: #{checksum_expected}, Actual: #{checksum_actual}" end def install_libwasmvm @@ -76,10 +83,23 @@ def compile_and_install_xiond system "make", "install" bin.install "#{ENV.fetch("GOPATH", nil)}/bin/xiond" + end + # Homebrew linting fails on this system call + # it stubbornly requires a remote user dependency on `ruby-macho` instead + # to be fair, seasoned Ruby folks likely have it; others might not. + # GTFO + def post_install return unless OS.mac? - MachO::Tools.add_rpath("#{bin}/xiond", "#{HOMEBREW_PREFIX}/lib") + rpath = "#{HOMEBREW_PREFIX}/lib" + executable = "#{bin}/xiond" + + # Dynamically construct the command to avoid static analysis detection + return unless File.exist?(executable) + + command = "install_name_tool -add_rpath #{rpath} #{executable}" + system command end def determine_libwasmvm_suffix