homebrew-core/Formula/nanopb-generator.rb

50 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
sha256 cellar: :any_skip_relocation, all: "07bb3eaaff21602786aba8175fa1b4e76ef6c736114f53eee63045affc5535bc"
end
depends_on "protobuf"
depends_on "python@3.10"
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