Creating a Homebrew formula for standalone application

佐手、 提交于 2019-12-11 09:05:48

问题


I'm trying to create a homebrew formula for an application that doesn't need to be compiled. I've tried looking through the formula cookbook, but I'm missing something to make things properly work. Below is my use-case with more generic filenames.

Inside the container is two files: one is the script for the application, the other being a file for man pages. We'll use the following filenames to keep things generic:

  • myapp.py (executable script)
  • resource.txt (a resource file that the script needs)
  • myapp.1 (man page)

What are the best ways to get these into the correct locations? Presume I have the ability to modify the code in the script for choosing the location to load the resource.

Thanks.


回答1:


You can either modify your script at install time to use the correct location of the resource or just assume it’s in the same directory and let Homebrew do the magic for you. I wrote an example formula for the latter case in another answer.

Here’s how it looks like for your needs:

class Foo < Formula
  desc "Blah blah"
  url "https://github.com/foo/foo/archive/master.zip"
  version "1.2.3"

  def install
    man1.install "myapp.1"
    libexec.install Dir["*"]
    bin.write_exec_script (libexec/"myapp.py")
  end
end

It installs myapp.1 in the correct directory. You can also use man2, man3, etc for other man directories.

It then installs all the remaining files under libexec then create an exec script in bin/myapp.py. This will be a simple shell script that execs your script in libexec. That way, your script will executes from libexec and thus will be able to find resource.txt that’s located in the same directory.

If you’d like to call it myapp and not myapp.py it’d look like that:

  def install
    man1.install "myapp.1"
    libexec.install "resource.txt"
    libexec.install "myapp.py" => "myapp"
    bin.write_exec_script (libexec/"myapp")
  end


来源:https://stackoverflow.com/questions/45978097/creating-a-homebrew-formula-for-standalone-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!