Last active
April 2, 2019 13:53
-
-
Save nicolascouvrat/4a1df21bd55630371fbb749b62d2707a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.0.2.tar.gz" | |
sha256 "b700647e11556b643ccddffd1f41d8cb7704ed02090af54cc517d44d912d11c1" | |
head "https://github.com/google/protobuf.git" | |
bottle do | |
sha256 "12622b355f2f487ce7bad94d23fda69f1137a59f61a61d9b2839b64033f42334" => :sierra | |
sha256 "6e4be33dfd56f5a1434bd0922e5b488031cfc5d6ce599812034d3c1b855c4fe1" => :el_capitan | |
sha256 "a465fe01de58cb9c69d7643a446906fb055d21965e2f2aa3d44358ed38ce2c95" => :yosemite | |
sha256 "c3658cb510da1f506c400620877174e972ed2b99b99d47a63754c6ef4556094b" => :mavericks | |
end | |
# this will double the build time approximately if enabled | |
option "with-test", "Run build-time check" | |
option "without-python", "Build without python support" | |
option :universal | |
option :cxx11 | |
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 | |
fails_with :llvm do | |
build 2334 | |
end | |
resource "setuptools" do | |
url "https://pypi.python.org/packages/df/c3/4265eb901f9db8c0ea5bdfb344084d85bc96c1a9b883f70430254b5491f6/setuptools-26.1.0.tar.gz" | |
sha256 "64a2f7676cd026b64e46d179ed26b365e2f92f26c7fe04228ddd86d0436b797f" | |
end | |
resource "six" do | |
url "https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz" | |
sha256 "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a" | |
end | |
resource "python-dateutil" do | |
url "https://pypi.python.org/packages/3e/f5/aad82824b369332a676a90a8c0d1e608b17e740bbb6aeeebca726f17b902/python-dateutil-2.5.3.tar.gz" | |
sha256 "1408fdb07c6a1fa9997567ce3fcee6a337b39a503d80699e0f213de4aa4b32ed" | |
end | |
resource "pytz" do | |
url "https://pypi.python.org/packages/f7/c7/08e54702c74baf9d8f92d0bc331ecabf6d66a56f6d36370f0a672fc6a535/pytz-2016.6.1.tar.bz2" | |
sha256 "b5aff44126cf828537581e534cc94299b223b945a2bb3b5434d37bf8c7f3a10c" | |
end | |
resource "python-gflags" do | |
url "https://pypi.python.org/packages/91/97/84778286b3a1c0d52533a35a0b70a477050df2b83229f56e99c7a0f2d9d6/python-gflags-3.0.6.tar.gz" | |
sha256 "e904b251cb1d70ddd3a1fd152bd4b3674a95981dcac497450efd1311ff2b9b5a" | |
end | |
resource "google-apputils" do | |
url "https://pypi.python.org/packages/source/g/google-apputils/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 | |
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.universal_binary if build.universal? | |
ENV.cxx11 if build.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" | |
%w[setuptools six python-dateutil pytz python-gflags google-apputils].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 | |
Editor support and examples have been installed to: | |
#{doc} | |
EOS | |
end | |
test do | |
testdata = <<~EOS | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment