首页 > 解决方案 > 自制公式无法运行

问题描述

我正在尝试为我构建的 Go 服务构建 Homebrew 公式,并使其易于为我的同事安装。我是 Ruby 的新手。我编写的公式无法运行并出现以下错误

my-server.rb:1:in `<main>': uninitialized constant Formula (NameError)

公式代码如下

class My < Formula
  desc "My Server"
  homepage "https://my.io/"
  url "https://github.com/my-server/archive/v1.0.8.tar.gz"
  sha256 "f9c7b083f19ba1ff2ec3bebc69102ac053cb4f4e0002c6c8df7b3969d46a275b"
  head "https://github.com/my-server.git"
  version "1.0.8"

  depends_on "go" => :build

  def install
    ENV["GOPATH"] = buildpath

    bin_path = buildpath/"src/github.com/my-server"
    # Copy all files from their current location (GOPATH root)
    # to $GOPATH/src/github.com/my-server
    bin_path.install Dir["*"]


    Language::Go.stage_deps resources, buildpath/"src"
    cd bin_path do
      # Install the compiled binary into Homebrew's `bin` - a pre-existing
      # global variable
      system "go", "build", "./..."
      system "go", "build", "-o", bin/"my-server", "main.go"
    end
  end

  test do
    assert_match "[GIN-debug] Listening and serving HTTP on 0.0.0.0:3636", shell_output("#{bin}/my-server", 2)
  end
end

标签: rubygohomebrew

解决方案


推荐阅读