class Mesos < Formula desc "Apache cluster manager" homepage "https://mesos.apache.org" url "https://www.apache.org/dyn/closer.cgi?path=mesos/1.0.1/mesos-1.0.1.tar.gz" mirror "https://archive.apache.org/dist/mesos/1.0.1/mesos-1.0.1.tar.gz" sha256 "e053d97192ca1dd949e07e6e34cca0f28af9767cdff5ec984769b2102017b0c1" bottle do sha256 "71559d903c2c5677dbf6f4fd5d8e87136f35a094f194fa112d88043a99bf63cf" => :sierra sha256 "95464c86a67e1af673af595537e7af770854e59fa864f53f89ef8048d3cad54f" => :el_capitan sha256 "6a94003af55afa369e40b3996f1b4bfce9a2ca9b8ee1d874d34d61b52a3b88e7" => :yosemite end depends_on :java => "1.7+" depends_on :macos => :mountain_lion depends_on :apr => :build depends_on "maven" => :build depends_on "subversion" resource "protobuf" do url "https://pypi.python.org/packages/source/p/protobuf/protobuf-2.6.1.tar.gz" sha256 "8faca1fb462ee1be58d00f5efb4ca4f64bde92187fe61fde32615bbee7b3e745" end # build dependencies for protobuf resource "six" do url "https://files.pythonhosted.org/packages/b3/b2/238e2590826bfdd113244a40d9d3eb26918bd798fc187e2360a8367068db/six-1.10.0.tar.gz" sha256 "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a" end resource "python-dateutil" do url "https://files.pythonhosted.org/packages/3e/f5/aad82824b369332a676a90a8c0d1e608b17e740bbb6aeeebca726f17b902/python-dateutil-2.5.3.tar.gz" sha256 "1408fdb07c6a1fa9997567ce3fcee6a337b39a503d80699e0f213de4aa4b32ed" end resource "pytz" do url "https://files.pythonhosted.org/packages/f7/c7/08e54702c74baf9d8f92d0bc331ecabf6d66a56f6d36370f0a672fc6a535/pytz-2016.6.1.tar.bz2" sha256 "b5aff44126cf828537581e534cc94299b223b945a2bb3b5434d37bf8c7f3a10c" end resource "python-gflags" do url "https://files.pythonhosted.org/packages/6b/1c/47996c14dc91249376f218c0f943da3b85ff7e9af9c5de05cd2600c8afb4/python-gflags-3.0.7.tar.gz" sha256 "db889af55e39fa6a37125d6aa70dfdd788dbc180f9566d3053250e28877e68dc" end resource "google-apputils" do url "https://files.pythonhosted.org/packages/69/66/a511c428fef8591c5adfa432a257a333e0d14184b6c5d03f1450827f7fe7/google-apputils-0.4.2.tar.gz" sha256 "47959d0651c32102c10ad919b8a0ffe0ae85f44b8457ddcf2bdc0358fb03dc29" end needs :cxx11 def install ENV.java_cache # work around to avoid `_clock_gettime` symbol not found error. if MacOS.version == "10.11" && MacOS::Xcode.installed? && MacOS::Xcode.version >= "8.0" ENV["ac_have_clock_syscall"] = "no" end # work around distutils abusing CC instead of using CXX # https://issues.apache.org/jira/browse/MESOS-799 # https://github.com/Homebrew/homebrew/pull/37087 native_patch = <<-EOS.undent import os os.environ["CC"] = os.environ["CXX"] os.environ["LDFLAGS"] = "@LIBS@" \\0 EOS inreplace "src/python/executor/setup.py.in", "import ext_modules", native_patch inreplace "src/python/scheduler/setup.py.in", "import ext_modules", native_patch # skip build javadoc because Homebrew sandbox ENV.java_cache # would trigger maven-javadoc-plugin bug. # https://issues.apache.org/jira/browse/MESOS-3482 maven_javadoc_patch = <<-EOS.undent true \\0 EOS inreplace "src/java/mesos.pom.in", "http://mesos.apache.org", maven_javadoc_patch args = %W[ --prefix=#{prefix} --disable-debug --disable-dependency-tracking --disable-silent-rules --with-svn=#{Formula["subversion"].opt_prefix} ] unless MacOS::CLT.installed? args << "--with-apr=#{Formula["apr"].opt_libexec}" end ENV.cxx11 system "./configure", "--disable-python", *args system "make" system "make", "install" # The native Python modules `executor` and `scheduler` (see below) fail to # link to Subversion libraries if Homebrew isn't installed in `/usr/local`. ENV.append_to_cflags "-L#{Formula["subversion"].opt_lib}" system "./configure", "--enable-python", *args ["native", "interface", "executor", "scheduler", "cli", ""].each do |p| cd "src/python/#{p}" do system "python", *Language::Python.setup_install_args(prefix) end end # stage protobuf build dependencies ENV.prepend_create_path "PYTHONPATH", buildpath/"protobuf/lib/python2.7/site-packages" %w[six python-dateutil pytz python-gflags google-apputils].each do |r| resource(r).stage do system "python", *Language::Python.setup_install_args(buildpath/"protobuf") end end protobuf_path = libexec/"protobuf/lib/python2.7/site-packages" ENV.prepend_create_path "PYTHONPATH", protobuf_path resource("protobuf").stage do ln_s buildpath/"protobuf/lib/python2.7/site-packages/google/apputils", "google/apputils" system "python", *Language::Python.setup_install_args(libexec/"protobuf") end pth_contents = "import site; site.addsitedir('#{protobuf_path}')\n" (lib/"python2.7/site-packages/homebrew-mesos-protobuf.pth").write pth_contents end test do require "timeout" master = fork do exec "#{sbin}/mesos-master", "--ip=127.0.0.1", "--registry=in_memory" end agent = fork do exec "#{sbin}/mesos-agent", "--master=127.0.0.1:5050", "--work_dir=#{testpath}" end Timeout.timeout(15) do system "#{bin}/mesos", "execute", "--master=127.0.0.1:5050", "--name=execute-touch", "--command=touch\s#{testpath}/executed" end Process.kill("TERM", master) Process.kill("TERM", agent) assert File.exist?("#{testpath}/executed") system "python", "-c", "import mesos.native" end end