为独立应用程序创建Homebrew公式 [英] Creating a Homebrew formula for standalone application

查看:95
本文介绍了为独立应用程序创建Homebrew公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为不需要编译的应用程序创建自制程序公式.我尝试浏览配方食谱,但是我缺少一些东西可以使它们正常工作.以下是我的使用案例,其中包含更多通用文件名.

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(可执行脚本)
  • resource.txt(脚本需要的资源文件)
  • myapp.1(手册页)

将它们放入正确位置的最佳方法是什么?假设我有能力修改脚本中的代码,以选择加载资源的位置.

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.

谢谢.

推荐答案

您可以在安装时修改脚本以使用正确的资源位置,也可以假设它位于同一目录中,然后让Homebrew为您做魔术.我在另一个答案中写了后一种情况的示例公式.

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.

这是您需要的外观:

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

它将myapp.1安装在正确的目录中.您还可以将man2man3等用于其他man目录.

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

然后将所有剩余文件安装在libexec下,然后在bin/myapp.py中创建一个exec脚本.这将是一个简单的Shell脚本,它将libexec中的脚本exec替换为exec.这样,您的脚本将从libexec执行,因此能够找到位于同一目录中的resource.txt.

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.

如果您想将其命名为myapp而不是myapp.py,它将看起来像这样:

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

这篇关于为独立应用程序创建Homebrew公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆