使用 Homebrew 发布软件

2024-08-29 16:08
文章标签 使用 软件 发布 homebrew

本文主要是介绍使用 Homebrew 发布软件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

    • 1 相关概念
    • 2 创建 Formula
    • 3 创建 Tap
    • 4 安装创建的软件
    • 5 参考资料

1 相关概念

  • Keg(酒桶):安装好的脚本、软件等;
  • Cellar(酒窖):所有用 Homebrew 安装在本地的脚本、软件组成的集合;
  • Formula(配方):定义如何下载、编译和安装脚本或软件的 Ruby 脚本;
  • Tap:一个包含若干 Formula 的 GitHub 专案。

2 创建 Formula

假如有一个软件的二进制包,需要先上传到网络上,并获取下载链接,如: https://github.com/Bytom/bytom/releases/download/v1.0.7/bytom-1.0.7-darwin_amd64.tgz

然后执行如下命令:

$ brew create https://github.com/Bytom/bytom/releases/download/v1.0.7/bytom-1.0.7-darwin_amd64.tgz

之后 brew 就在其目录 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/中自动创建一个 ruby 文件 bytom.rb:

# Documentation: https://docs.brew.sh/Formula-Cookbook
#                https://www.rubydoc.info/github/Homebrew/brew/master/Formula
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
class Bytom < Formuladesc "Official Go implementation of the Bytom protocol "homepage "https://bytom.io/"url "https://github.com/Bytom/bytom/releases/download/v1.0.7/bytom-1.0.7-darwin_amd64.tgz"sha256 "25dd62343157fe6eb7a983edb1455f457cfca07552f02e1f9142227bd961a4a5"# depends_on "cmake" => :builddef install# ENV.deparallelize  # if your formula fails when building in parallel# Remove unrecognized options if warned by configuresystem "./configure", "--disable-debug","--disable-dependency-tracking","--disable-silent-rules","--prefix=#{prefix}"# system "cmake", ".", *std_cmake_argssystem "make", "install" # if this fails, try separate make/make install stepsendtest do# `test do` will create, run in and delete a temporary directory.## This test will fail and we won't accept that! For Homebrew/homebrew-core# this will need to be a test that verifies the functionality of the# software. Run the test with `brew test bytom`. Options passed# to `brew install` such as `--HEAD` also need to be provided to `brew test`.## The installed folder is not in the path, so use the entire path to any# executables being tested: `system "#{bin}/program", "do", "something"`.system "false"end
end

之后按照软件的实际需求对该文件进行编辑,可以修改或者增加以下内容:

desc           # 说明,默认已填写
homepage       # 主页,默认已填写
url            # 文件下载地址,默认已填写
version        # 软件版本号,该字段可以自己添加,强烈建议添加
sha256         # 信息摘要,默认已填写

文件的 sha256 摘要可以使用 openssl 命令获取:

$ openssl sha256 bytom-1.0.7-darwin_amd64.tgz
SHA256(bytom-1.0.7-darwin_amd64.tgz)= 25dd62343157fe6eb7a983edb1455f457cfca07552f02e1f9142227bd961a4a5

之后是文件依赖部分:

# depends_on "cmake" => :build

该部分按照实际需求填写。之后是安装部分:

  def install# ENV.deparallelize  # if your formula fails when building in parallel# Remove unrecognized options if warned by configuresystem "./configure", "--disable-debug","--disable-dependency-tracking","--disable-silent-rules","--prefix=#{prefix}"# system "cmake", ".", *std_cmake_argssystem "make", "install" # if this fails, try separate make/make install stepsend

system 后面是需要执行的安装命令,这个根据实际软件编译过程进行修改。

因为 bytom 是已经编译好的二进制软件包,所以实际的文件进行修改如下:

class Bytom < Formuladesc "Official Go implementation of the Bytom protocol "homepage "https://bytom.io/"url "https://github.com/Bytom/bytom/releases/download/v1.0.7/bytom-1.0.7-darwin_amd64.tgz"version "1.0.7"sha256 "25dd62343157fe6eb7a983edb1455f457cfca07552f02e1f9142227bd961a4a5"def installsystem 'mv bytomd-darwin_amd64 bytomd'system 'mv bytomcli-darwin_amd64 bytomcli'bin.install "bytomd"bin.install "bytomcli"endtest do# `test do` will create, run in and delete a temporary directory.## This test will fail and we won't accept that! For Homebrew/homebrew-core# this will need to be a test that verifies the functionality of the# software. Run the test with `brew test bytom`. Options passed# to `brew install` such as `--HEAD` also need to be provided to `brew test`.## The installed folder is not in the path, so use the entire path to any# executables being tested: `system "#{bin}/program", "do", "something"`.system "false"endend

安装过程的 bin.install 是调用 Homebrew 安装二进制软件。保存后,执行安装过程:

$ brew install bytom

之后软件就自动安装在 /usr/local/bin 文件夹下。

3 创建 Tap

之后,为了使其他用户也能安装上面的配置文件进行安装软件,则需要将上一步制作的 bytom.rb 文件上传到 GitHub 上,以供其他用户下载。

创建的 GitHub 仓库名的前缀统一为 homebrew-。例如将 bytom.rb 文件放置在 Bytom 组织的 homebrew-bytom 仓库下。

4 安装创建的软件

初次安装需要指定 tap:

$ brew tap bytom/bytom

该命令将用户名为 bytom 的 homebrew-bytom 联系起来,之后安装 bytom 软件时候就不需要再次指定了。然后进行安装:

$ brew install bytom

验证 bytomd 和 bytomcli 是否正确安装:

$ bytomd version
1.0.7+96a0b65f
$ bytomcli version
Bytomcli v1.0.7+96a0b65f darwin/amd64

5 参考资料

  • 在 Homebrew 上发布自己的 App
  • Homebrew:Homebrew 官方指南。

这篇关于使用 Homebrew 发布软件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1118322

相关文章

Java中的Cursor使用详解

《Java中的Cursor使用详解》本文介绍了Java中的Cursor接口及其在大数据集处理中的优势,包括逐行读取、分页处理、流控制、动态改变查询、并发控制和减少网络流量等,感兴趣的朋友一起看看吧... 最近看代码,有一段代码涉及到Cursor,感觉写法挺有意思的。注意是Cursor,而不是Consumer

Node.js net模块的使用示例

《Node.jsnet模块的使用示例》本文主要介绍了Node.jsnet模块的使用示例,net模块支持TCP通信,处理TCP连接和数据传输,具有一定的参考价值,感兴趣的可以了解一下... 目录简介引入 net 模块核心概念TCP (传输控制协议)Socket服务器TCP 服务器创建基本服务器服务器配置选项服

如何使用CSS3实现波浪式图片墙

《如何使用CSS3实现波浪式图片墙》:本文主要介绍了如何使用CSS3的transform属性和动画技巧实现波浪式图片墙,通过设置图片的垂直偏移量,并使用动画使其周期性地改变位置,可以创建出动态且具有波浪效果的图片墙,同时,还强调了响应式设计的重要性,以确保图片墙在不同设备上都能良好显示,详细内容请阅读本文,希望能对你有所帮助...

Rust中的注释使用解读

《Rust中的注释使用解读》本文介绍了Rust中的行注释、块注释和文档注释的使用方法,通过示例展示了如何在实际代码中应用这些注释,以提高代码的可读性和可维护性... 目录Rust 中的注释使用指南1. 行注释示例:行注释2. 块注释示例:块注释3. 文档注释示例:文档注释4. 综合示例总结Rust 中的注释

Linux使用cut进行文本提取的操作方法

《Linux使用cut进行文本提取的操作方法》Linux中的cut命令是一个命令行实用程序,用于从文件或标准输入中提取文本行的部分,本文给大家介绍了Linux使用cut进行文本提取的操作方法,文中有详... 目录简介基础语法常用选项范围选择示例用法-f:字段选择-d:分隔符-c:字符选择-b:字节选择--c

使用Go语言开发一个命令行文件管理工具

《使用Go语言开发一个命令行文件管理工具》这篇文章主要为大家详细介绍了如何使用Go语言开发一款命令行文件管理工具,支持批量重命名,删除,创建,移动文件,需要的小伙伴可以了解下... 目录一、工具功能一览二、核心代码解析1. 主程序结构2. 批量重命名3. 批量删除4. 创建文件/目录5. 批量移动三、如何安

springboot的调度服务与异步服务使用详解

《springboot的调度服务与异步服务使用详解》本文主要介绍了Java的ScheduledExecutorService接口和SpringBoot中如何使用调度线程池,包括核心参数、创建方式、自定... 目录1.调度服务1.1.JDK之ScheduledExecutorService1.2.spring

Java使用Tesseract-OCR实战教程

《Java使用Tesseract-OCR实战教程》本文介绍了如何在Java中使用Tesseract-OCR进行文本提取,包括Tesseract-OCR的安装、中文训练库的配置、依赖库的引入以及具体的代... 目录Java使用Tesseract-OCRTesseract-OCR安装配置中文训练库引入依赖代码实

Python使用Pandas对比两列数据取最大值的五种方法

《Python使用Pandas对比两列数据取最大值的五种方法》本文主要介绍使用Pandas对比两列数据取最大值的五种方法,包括使用max方法、apply方法结合lambda函数、函数、clip方法、w... 目录引言一、使用max方法二、使用apply方法结合lambda函数三、使用np.maximum函数

Qt 中集成mqtt协议的使用方法

《Qt中集成mqtt协议的使用方法》文章介绍了如何在工程中引入qmqtt库,并通过声明一个单例类来暴露订阅到的主题数据,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一,引入qmqtt 库二,使用一,引入qmqtt 库我是将整个头文件/源文件都添加到了工程中进行编译,这样 跨平台