homebrew-core/Formula/protobuf.rb

132 lines
5.1 KiB
Ruby

class Protobuf < Formula
desc "Protocol buffers (Google's data interchange format)"
homepage "https://github.com/google/protobuf/"
url "https://github.com/google/protobuf/archive/v3.2.0.tar.gz"
sha256 "2a25c2b71c707c5552ec9afdfb22532a93a339e1ca5d38f163fe4107af08c54c"
head "https://github.com/google/protobuf.git"
bottle do
sha256 "2438950b0e87c1a30d37c4a06e2413b22be22ed2313cb87373b224907adc1028" => :sierra
sha256 "18da3f765d76de871726d19a27dc856a26d467b9cf0b6c15c4693665113cda5a" => :el_capitan
sha256 "7e1207b8dfaf97916fc5b9534807a0bb1fe90bbbd5335f9a137d38cd4e84897a" => :yosemite
end
# this will double the build time approximately if enabled
option "with-test", "Run build-time check"
option "without-python", "Build without python support"
deprecated_option "with-check" => "with-test"
depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "libtool" => :build
depends_on :python => :recommended if MacOS.version <= :snow_leopard
resource "appdirs" do
url "https://files.pythonhosted.org/packages/bd/66/0a7f48a0f3fb1d3a4072bceb5bbd78b1a6de4d801fb7135578e7c7b1f563/appdirs-1.4.0.tar.gz"
sha256 "8fc245efb4387a4e3e0ac8ebcc704582df7d72ff6a42a53f5600bbb18fdaadc5"
end
resource "packaging" do
url "https://files.pythonhosted.org/packages/c6/70/bb32913de251017e266c5114d0a645f262fb10ebc9bf6de894966d124e35/packaging-16.8.tar.gz"
sha256 "5d50835fdf0a7edf0b55e311b7c887786504efea1177abd7e69329a8e5ea619e"
end
resource "pyparsing" do
url "https://files.pythonhosted.org/packages/38/bb/bf325351dd8ab6eb3c3b7c07c3978f38b2103e2ab48d59726916907cd6fb/pyparsing-2.1.10.tar.gz"
sha256 "811c3e7b0031021137fc83e051795025fcb98674d07eb8fe922ba4de53d39188"
end
resource "six" do
url "https://files.pythonhosted.org/packages/b3/b2/238e2590826bfdd113244a40d9d3eb26918bd798fc187e2360a8367068db/six-1.10.0.tar.gz"
sha256 "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a"
end
resource "setuptools" do
url "https://files.pythonhosted.org/packages/e3/6b/bb793ca610f364d1888b9bd7b83dccd0c27d779e4fd91a953ce8bae74996/setuptools-34.0.2.zip"
sha256 "a5bdc45a3c123a88c84e089a789ba70bbc61ee888c1306fd9dac04e037e81c37"
end
resource "google-apputils" do
url "https://files.pythonhosted.org/packages/69/66/a511c428fef8591c5adfa432a257a333e0d14184b6c5d03f1450827f7fe7/google-apputils-0.4.2.tar.gz"
sha256 "47959d0651c32102c10ad919b8a0ffe0ae85f44b8457ddcf2bdc0358fb03dc29"
end
# Upstream's autogen script fetches this if not present
# but does no integrity verification & mandates being online to install.
resource "gmock" do
url "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/googlemock/gmock-1.7.0.zip"
mirror "https://dl.bintray.com/homebrew/mirror/gmock-1.7.0.zip"
sha256 "26fcbb5925b74ad5fc8c26b0495dfc96353f4d553492eb97e85a8a6d2f43095b"
end
needs :cxx11
def install
# Don't build in debug mode. See:
# https://github.com/Homebrew/homebrew/issues/9279
# https://github.com/google/protobuf/blob/5c24564811c08772d090305be36fae82d8f12bbe/configure.ac#L61
ENV.prepend "CXXFLAGS", "-DNDEBUG"
ENV.cxx11
(buildpath/"gmock").install resource("gmock")
system "./autogen.sh"
system "./configure", "--disable-debug", "--disable-dependency-tracking",
"--prefix=#{prefix}", "--with-zlib"
system "make"
system "make", "check" if build.with?("test") || build.bottle?
system "make", "install"
# Install editor support and examples
doc.install "editors", "examples"
if build.with? "python"
# google-apputils is a build-time dependency
ENV.prepend_create_path "PYTHONPATH", buildpath/"homebrew/lib/python2.7/site-packages"
res = resources.map(&:name).to_set - ["gmock"]
res.each do |package|
resource(package).stage do
system "python", *Language::Python.setup_install_args(buildpath/"homebrew")
end
end
# google is a namespace package and .pth files aren't processed from
# PYTHONPATH
touch buildpath/"homebrew/lib/python2.7/site-packages/google/__init__.py"
chdir "python" do
ENV.append_to_cflags "-I#{include}"
ENV.append_to_cflags "-L#{lib}"
args = Language::Python.setup_install_args libexec
args << "--cpp_implementation"
system "python", *args
end
site_packages = "lib/python2.7/site-packages"
pth_contents = "import site; site.addsitedir('#{libexec/site_packages}')\n"
(prefix/site_packages/"homebrew-protobuf.pth").write pth_contents
end
end
def caveats; <<-EOS.undent
Editor support and examples have been installed to:
#{doc}
EOS
end
test do
testdata = <<-EOS.undent
syntax = "proto3";
package test;
message TestCase {
string name = 4;
}
message Test {
repeated TestCase case = 1;
}
EOS
(testpath/"test.proto").write testdata
system bin/"protoc", "test.proto", "--cpp_out=."
system "python", "-c", "import google.protobuf" if build.with? "python"
end
end