view lightsd.rb @ 16:d2063f0d66a9

New upstream release 1.2.0-rc.3
author Buildbot <buildbot@kalessin.fr>
date Sun, 03 Jul 2016 06:01:32 +0000
parents b3a1d8f53e72
children 7f884c8feb0c
line wrap: on
line source

require "formula"

class Lightsd < Formula
  desc "Daemon to control your LIFX wifi smart bulbs"
  homepage "https://github.com/lopter/lightsd/"
  url "https://downloads.lightsd.io/releases/lightsd-1.2.0-rc.3.tar.gz"
  sha256 "996e7d39a51aa9227d2ec3da186c7ebef5b604ecd50f06255a7e424b837979da"
  # This will have ~ instead of - for rc versions:
  version "1.2.0~rc.3
  revision 1

  depends_on "cmake" => :build
  depends_on "libevent" => :build
  depends_on "python3" => :optional

  def install
    # XXX, wtf? https://github.com/Homebrew/homebrew/issues/46061
    ENV["PATH"] = "/usr/bin:#{ENV["PATH"]}"

    args = std_cmake_args
    args << "-DLGTD_RUNTIME_DIRECTORY=#{var}/run/lightsd"

    # idk what std_cmake_args is supposed to do but it appears to be missing
    # proper release flags:
    cflags = %W[
      -fstack-protector-strong
      -D_FORTIFY_SOURCE=2
      -O3
      -DNDEBUG
    ]
    args << "-DCMAKE_BUILD_TYPE=RELEASE"
    args << "-DCMAKE_C_FLAGS_RELEASE='#{cflags * " "}'"

    system "cmake", *args
    system "make", "install"
  end

  def plist; <<-EOS.undent
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
      <dict>
        <key>KeepAlive</key>
        <dict>
          <key>SuccessfulExit</key>
          <false/>
        </dict>
        <key>Label</key>
        <string>#{plist_name}</string>
        <key>ProgramArguments</key>
        <array>
          <string>#{opt_bin}/lightsd</string>
          <string>-v</string>
          <string>warning</string>
          <string>-s</string>
          <string>#{var}/run/lightsd/socket</string>
          <string>-c</string>
          <string>#{var}/run/lightsd/pipe</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>WorkingDirectory</key>
        <string>#{var}</string>
        <key>StandardErrorPath</key>
        <string>#{var}/log/lightsd.log</string>
        <key>StandardOutPath</key>
        <string>#{var}/log/lightsd.log</string>
      </dict>
    </plist>
    EOS
  end

  def caveats; <<-EOS.undent
    Once you've started lightsd (see the brew services command below, if you're
    using tmux, remember that you will need to run it outside tmux), you can
    start poking around with lightsc.py:

      `lightsd --prefix`/share/lightsd/examples/lightsc.py
    EOS
  end

  head do
    url "https://github.com/lopter/lightsd.git"
  end

  test do
    Dir.mktmpdir("lightsd-test") do |dir|
      args = %W[
        -l ::1:0
        -l 127.0.0.1:0
        -c #{dir}/lightsd.cmd
        -h
      ]
      system "#{bin}/lightsd", *args
    end
  end
end