Skip to content

Instantly share code, notes, and snippets.

@pmdarrow
Last active August 29, 2015 14:24
Show Gist options
  • Save pmdarrow/ce1b1aa50d2614dc1da4 to your computer and use it in GitHub Desktop.
Save pmdarrow/ce1b1aa50d2614dc1da4 to your computer and use it in GitHub Desktop.
protobuf-py3 Homebrew formula
# Place in /usr/local/Library/Formula/, then
# brew install protobuf-py3
class ProtobufPy3 < Formula
url "https://github.com/GreatFruitOmsk/protobuf-py3/archive/2.5.1.tar.gz"
version "2.5.1"
sha256 "496484244288b6e9b7d94baac71a3c0ea19c2a381a8a8685f0ff4235e81b1b38"
conflicts_with "protobuf", :because => "protobuf-py3 is incompatible with protobuf"
option :universal
option :cxx11
# this will double the build time approximately if enabled
option "with-check", "Run build-time check"
depends_on :python => :optional
depends_on :autoconf => :build
depends_on :automake => :build
depends_on :libtool => :build
fails_with :llvm do
build 2334
end
def install
# Don't build in debug mode. See:
# https://github.com/Homebrew/homebrew/issues/9279
ENV.prepend "CXXFLAGS", "-DNDEBUG"
ENV.universal_binary if build.universal?
ENV.cxx11 if build.cxx11?
system "./autogen.sh"
system "./configure", "--disable-debug",
"--disable-dependency-tracking",
"--prefix=#{prefix}",
"--with-zlib"
system "make"
system "make", "check" if build.with? "check" || build.bottle?
system "make", "install"
# Install editor support and examples
doc.install "editors", "examples"
if build.with? "python"
chdir "python" do
ENV["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "cpp"
ENV.append_to_cflags "-I#{include}"
ENV.append_to_cflags "-L#{lib}"
args = Language::Python.setup_install_args libexec
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
(testpath/"test.proto").write <<-EOS.undent
package test;
message TestCase {
required string name = 4;
}
message Test {
repeated TestCase case = 1;
}
EOS
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