homebrew-core/Formula/nanopb-generator.rb

51 lines
1.5 KiB
Ruby

class NanopbGenerator < Formula
include Language::Python::Shebang
desc "C library for encoding and decoding Protocol Buffer messages"
homepage "https://jpa.kapsi.fi/nanopb/docs/index.html"
url "https://jpa.kapsi.fi/nanopb/download/nanopb-0.4.6.tar.gz"
sha256 "e379d9babd86b9cfd8f8900fd0da8705cbd9bea4491178fb2b8be5e217bf02ab"
license "Zlib"
livecheck do
url "https://jpa.kapsi.fi/nanopb/download/"
regex(/href=.*?nanopb[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
bottle do
rebuild 1
sha256 cellar: :any_skip_relocation, all: "ac1eb681935c128508d1d5f2159ec8fe2cb4c7d248b8f955ce53f35f7ca0a63e"
end
depends_on "protobuf"
depends_on "python@3.11"
conflicts_with "mesos",
because: "they depend on an incompatible version of protobuf"
def install
cd "generator" do
system "make", "-C", "proto"
rewrite_shebang detected_python_shebang, "nanopb_generator.py"
libexec.install "nanopb_generator.py", "protoc-gen-nanopb", "proto"
bin.install_symlink libexec/"protoc-gen-nanopb", libexec/"nanopb_generator.py"
end
end
test do
(testpath/"test.proto").write <<~EOS
syntax = "proto2";
message Test {
required string test_field = 1;
}
EOS
system Formula["protobuf"].bin/"protoc",
"--proto_path=#{testpath}", "--plugin=#{bin}/protoc-gen-nanopb",
"--nanopb_out=#{testpath}", testpath/"test.proto"
system "grep", "Test", testpath/"test.pb.c"
system "grep", "Test", testpath/"test.pb.h"
end
end