Skip to content

package formulas #6

Description

@zbeekman

Hi all,
Just a suggestion about how to manage different packages, and a place to discuss.

I really like the way Homebrew keeps track of packages. It stores instructions for downloading, building and installing packages as relatively simple ruby scripts. I think this idea is much more powerful than trying to do something like duplicating package sources via cloning existing git repos. If FLATPack used a similar formula structure, the formula can indicate which compilers a certain package works with (and what versions and/or which language features or standards are required) and contain specialized build instructions for each compiler.

Here is a link to the Homebrew documentation for writing formulas and for submitting pull requests to add them to Homebrew.

Here is the json-fortran Homebrew formula for reference. It’s pretty concise and simple, and Homebrew has a create command which you pass a URL to and will extract version info, the sha256 hash and stub to expand. The bottle do stuff is just precompiled binaries built during the formula testing process and automatically added by the testbot:

class JsonFortran < Formula
  desc "A Fortran 2008 JSON API"
  homepage "https://github.com/jacobwilliams/json-fortran"
  url "https://github.com/jacobwilliams/json-fortran/archive/4.1.1.tar.gz"
  sha256 "97f258d28536035ef70e9ead5c7053e654106760a12db2cc652587ed61b76124"

  head "https://github.com/jacobwilliams/json-fortran.git"

  bottle do
    cellar :any
    sha256 "3b6410ef26c24d63f90e420aae0157f7d97b4d154b398305863e2be6c24eed8d" => :yosemite
    sha256 "5608f04857515ce6b38d6a7ade2cf50a15541cb307ff97cbde1d367af3b19801" => :mavericks
    sha256 "443ce5965a801c7e3dda0dfc5762b9f84ec97bf450d98eedfe0385d3681a725e" => :mountain_lion
  end

  option "with-unicode-support", "Build json-fortran to support unicode text in json objects and files"
  option "without-test", "Skip running build-time tests (not recommended)"
  option "without-robodoc", "Do not build and install ROBODoc generated documentation for json-fortran"

  depends_on "robodoc" => [:recommended, :build]
  depends_on "cmake" => :build
  depends_on :fortran

  def install
    mkdir "build" do
      args = std_cmake_args
      args << "-DUSE_GNU_INSTALL_CONVENTION:BOOL=TRUE" # Use more GNU/Homebrew-like install layout
      args << "-DENABLE_UNICODE:BOOL=TRUE" if build.with? "unicode-support"
      args << "-DSKIP_DOC_GEN:BOOL=TRUE" if build.without? "robodoc"
      system "cmake", "..", *args
      system "make", "check" if build.with? "test"
      system "make", "install"
    end
  end

  test do
    ENV.fortran
    (testpath/"json_test.f90").write <<-EOS.undent
      program json_test
        use json_module
        use ,intrinsic :: iso_fortran_env ,only: error_unit
        implicit none
        call json_initialize()
        if ( json_failed() ) then
          call json_print_error_message(error_unit)
          stop 2
        endif
      end program
    EOS
    system ENV.fc, "-ojson_test", "-ljsonfortran", "-I#{HOMEBREW_PREFIX}/include", testpath/"json_test.f90"
    system "./json_test"
  end
end

This encodes everything home-brew needs to know about json-fortran and this is what build options/info it provides to the user:

$ brew info json-fortran
json-fortran: stable 4.1.1 (bottled), HEAD
A Fortran 2008 JSON API
https://github.com/jacobwilliams/json-fortran
/usr/local/homebrew/Cellar/json-fortran/4.1.1 (34 files, 1.3M) *
  Built from source with: --with-unicode-support
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/json-fortran.rb
==> Dependencies
Build: robodoc ✔, cmake ✘
Recommended: robodoc ✔
==> Options
--with-unicode-support
    Build json-fortran to support unicode text in json objects and files
--without-robodoc
    Do not build and install ROBODoc generated documentation for json-fortran
--without-test
    Skip running build-time tests (not recommended)
--HEAD
    Install HEAD version

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions