From 4e84735f7e3eb354d5d92c6a418d3077af37c0ae Mon Sep 17 00:00:00 2001 From: Tony Worm Date: Sun, 28 Aug 2022 03:09:22 -0400 Subject: [PATCH] completely rewrite --- Formula/hof.rb | 12 -------- Formula/mvs.rb | 11 -------- Makefile | 7 +++++ hof.cue | 53 ++++++++++++++++++++++++++++++++++++ hof.rb | 49 +++++++++++++++++++++++++++++++++ templates/from-gh-release.rb | 40 +++++++++++++++++++++++++++ templates/from-git-source.rb | 49 +++++++++++++++++++++++++++++++++ 7 files changed, 198 insertions(+), 23 deletions(-) delete mode 100644 Formula/hof.rb delete mode 100644 Formula/mvs.rb create mode 100644 Makefile create mode 100644 hof.cue create mode 100644 hof.rb create mode 100644 templates/from-gh-release.rb create mode 100644 templates/from-git-source.rb diff --git a/Formula/hof.rb b/Formula/hof.rb deleted file mode 100644 index 3087a82..0000000 --- a/Formula/hof.rb +++ /dev/null @@ -1,12 +0,0 @@ -# This file was generated by GoReleaser. DO NOT EDIT. -class Hof < Formula - desc "Hofstadter Studios CLI" - homepage "https://github.com/hofstadter-io/hof" - url "https://github.com/hofstadter-io/hof/releases/download/0.4.0/hof_0.4.0_MacOS-64bit.tar.gz" - version "0.0.0" - sha256 "4bc098e16284d45d523bd92ff9593254d19b51ed8118553f4cfd15f1b8009ddc" - - def install - bin.install "hof" - end -end diff --git a/Formula/mvs.rb b/Formula/mvs.rb deleted file mode 100644 index b37d57b..0000000 --- a/Formula/mvs.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Mvs < Formula - desc "MVS is a polyglot dependency management tool based on go mods" - homepage "https://github.com/hofstadter-io/mvs" - url "https://github.com/hofstadter-io/mvs/releases/download/0.0.1/mvs_0.0.1_MacOS-64bit.tar.gz" - version "0.0.1" - sha256 "21505047d417dac9d0ca811bd3f415e2f14b89c54ff16a83bd4bad59187415df" - - def install - bin.install "geb" - end -end diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6a9708d --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: gen gen-src gen-bin +gen: gen-src +gen-src: + hof gen hof.cue -T templates/from-git-source.rb=hof.rb --no-format +gen-bin: + hof gen hof.cue -T templates/from-gh-release.rb=hof.rb --no-format + diff --git a/hof.cue b/hof.cue new file mode 100644 index 0000000..e280994 --- /dev/null +++ b/hof.cue @@ -0,0 +1,53 @@ +package main + +import "strings" + +name: "hof" +version: "0.6.6" +tag: "v0.6.6" +commit: "0f49b4d71a66788b006daacf905a2b138768beca" +desc: "Flexible data modeling & code generation system" +homepage: "https://hofstadter.io/" +repo: "github.com/hofstadter-io/hof" +url: "https://\(repo).git" +license: "BSD-3-Clause" +branch: "_dev" +cmddir: "cmd/hof" +ldflags: strings.Replace(""" +-s -w +-X \(repo)/\(cmddir)/verinfo.Version=#{version} +-X \(repo)/\(cmddir)/verinfo.Commit=#{Utils.git_head} +-X \(repo)/\(cmddir)/verinfo.BuildDate=#{time.iso8601} +-X \(repo)/\(cmddir)/verinfo.GoVersion=#{Formula["go"].version} +-X \(repo)/\(cmddir)/verinfo.BuildOS=#{os} +-X \(repo)/\(cmddir)/verinfo.BuildArch=#{arch} +""", "\n", " ", -1) + +builds: { + [os=string]: [arch=string]: { + "name": name + + _url: "https://\(repo)/releases/download/\(tag)/\(name)_\(version)" + sha256: string + } + linux: { + intel: A={ + url: "\(A._url)_Linux_x86_64" + sha256: "581958cf7a69c2b9dc541ad0aac25396f7705d1533f89a90ab4a4b27a1128131" + } + arm: A={ + url: "\(A._url)_Linux_arm64" + sha256: "01c13dbd5d2dc3eaa573d5400c2a013d3fd0fe2b4de8f499c0bef3f10c90cc12" + } + } + macos: { + intel: A={ + url: "\(A._url)_Darwin_x86_64" + sha256: "e1cf5a28e07c34a4aa1dbd7f2c0149a4d76f3450e14e5c0ff1e28813e48bf33b" + } + arm: A={ + url: "\(A._url)_Darwin_arm64" + sha256: "124ad1d08c959690510a8983ac283b4c4ffafda2378768e89af2cd3af7226b54" + } + } +} diff --git a/hof.rb b/hof.rb new file mode 100644 index 0000000..0e2b348 --- /dev/null +++ b/hof.rb @@ -0,0 +1,49 @@ +class Hof < Formula + desc "Flexible data modeling & code generation system" + homepage "https://hofstadter.io/" + version "0.6.6" + url "https://github.com/hofstadter-io/hof.git", + tag: "v0.6.6", + revision: "0f49b4d71a66788b006daacf905a2b138768beca" + license "BSD-3-Clause" + head "https://github.com/hofstadter-io/hof.git", branch: "_dev" + + bottle do + sha256 cellar: :any_skip_relocation, arm64_monterey: "da7fa63d18da0c17f4bd2b4d1ddef8a1fa6bf9409ad32646db184e2da74a4472" + sha256 cellar: :any_skip_relocation, arm64_big_sur: "da7fa63d18da0c17f4bd2b4d1ddef8a1fa6bf9409ad32646db184e2da74a4472" + sha256 cellar: :any_skip_relocation, monterey: "0b9a77f9209c943caabd4cbb896a8cd31690d474735998df1a30ce777b7cee19" + sha256 cellar: :any_skip_relocation, big_sur: "0b9a77f9209c943caabd4cbb896a8cd31690d474735998df1a30ce777b7cee19" + sha256 cellar: :any_skip_relocation, catalina: "0b9a77f9209c943caabd4cbb896a8cd31690d474735998df1a30ce777b7cee19" + sha256 cellar: :any_skip_relocation, x86_64_linux: "7386d7a1f88d925e4621e1950e1edbca8361d813f68084eee7d53d185ad0da49" + end + + depends_on "go" => :build + depends_on "docker" => :test + + def install + arch = Hardware::CPU.intel? ? "amd64" : Hardware::CPU.arch.to_s + os = OS.kernel_name.downcase + + ldflags = %W[ -s -w -X github.com/hofstadter-io/hof/cmd/hof/verinfo.Version=#{version} -X github.com/hofstadter-io/hof/cmd/hof/verinfo.Commit=#{Utils.git_head} -X github.com/hofstadter-io/hof/cmd/hof/verinfo.BuildDate=#{time.iso8601} -X github.com/hofstadter-io/hof/cmd/hof/verinfo.GoVersion=#{Formula["go"].version} -X github.com/hofstadter-io/hof/cmd/hof/verinfo.BuildOS=#{os} -X github.com/hofstadter-io/hof/cmd/hof/verinfo.BuildArch=#{arch} ] + + ENV["CGO_ENABLED"] = "0" + system "go", "build", *std_go_args(ldflags: ldflags), "./cmd/hof" + + bash_output = Utils.safe_popen_read(bin/"hof", "completion", "bash") + (bash_completion/"hof").write bash_output + zsh_output = Utils.safe_popen_read(bin/"hof", "completion", "zsh") + (zsh_completion/"_hof").write zsh_output + fish_output = Utils.safe_popen_read(bin/"hof", "completion", "fish") + (fish_completion/"hof.fish").write fish_output + end + + test do + assert_match "v#{version}", shell_output("#{bin}/hof version") + + system bin/"hof", "mod", "init", "cue", "brew.sh/brewtest" + assert_predicate testpath/"cue.mods", :exist? + assert_equal "module: \"brew.sh/brewtest\"", (testpath/"cue.mod/module.cue").read.chomp + + assert_match version.to_s, shell_output(bin/"hof version") + end +end diff --git a/templates/from-gh-release.rb b/templates/from-gh-release.rb new file mode 100644 index 0000000..c57fb78 --- /dev/null +++ b/templates/from-gh-release.rb @@ -0,0 +1,40 @@ +# typed: false +# frozen_string_literal: true + +# This file was generated by GoReleaser. DO NOT EDIT. +class {{ title .name }} < Formula + desc "{{ .desc }}" + homepage "{{ .homepage }}" + version "{{ .version }}" + + on_macos do + if Hardware::CPU.intel? +{{ template "build-details" .builds.macos.intel }} + end + if Hardware::CPU.arm? +{{ template "build-details" .builds.macos.arm }} + end + end + + on_linux do + if Hardware::CPU.intel? +{{ template "build-details" .builds.linux.intel }} + end + if Hardware::CPU.arm? && Hardware::CPU.is_64_bit? +{{ template "build-details" .builds.linux.arm }} + end + end + + test do + system "#{bin}/{{ .name }} version" + end +end + +{{ define "build-details" }} + url "{{ .url }}" + sha256 "{{ .sha256 }}" + + def install + bin.install "{{ .name }}" + end +{{ end }} diff --git a/templates/from-git-source.rb b/templates/from-git-source.rb new file mode 100644 index 0000000..ad2ae21 --- /dev/null +++ b/templates/from-git-source.rb @@ -0,0 +1,49 @@ +class {{ title .name }} < Formula + desc "{{ .desc }}" + homepage "{{ .homepage }}" + version "{{ .version }}" + url "{{ .url }}", + tag: "{{ .tag }}", + revision: "{{ .commit }}" + license "{{ .license }}" + head "{{ .url }}", branch: "{{ .branch }}" + + bottle do + sha256 cellar: :any_skip_relocation, arm64_monterey: "da7fa63d18da0c17f4bd2b4d1ddef8a1fa6bf9409ad32646db184e2da74a4472" + sha256 cellar: :any_skip_relocation, arm64_big_sur: "da7fa63d18da0c17f4bd2b4d1ddef8a1fa6bf9409ad32646db184e2da74a4472" + sha256 cellar: :any_skip_relocation, monterey: "0b9a77f9209c943caabd4cbb896a8cd31690d474735998df1a30ce777b7cee19" + sha256 cellar: :any_skip_relocation, big_sur: "0b9a77f9209c943caabd4cbb896a8cd31690d474735998df1a30ce777b7cee19" + sha256 cellar: :any_skip_relocation, catalina: "0b9a77f9209c943caabd4cbb896a8cd31690d474735998df1a30ce777b7cee19" + sha256 cellar: :any_skip_relocation, x86_64_linux: "7386d7a1f88d925e4621e1950e1edbca8361d813f68084eee7d53d185ad0da49" + end + + depends_on "go" => :build + depends_on "docker" => :test + + def install + arch = Hardware::CPU.intel? ? "amd64" : Hardware::CPU.arch.to_s + os = OS.kernel_name.downcase + + ldflags = %W[ {{ .ldflags }} ] + + ENV["CGO_ENABLED"] = "0" + system "go", "build", *std_go_args(ldflags: ldflags), "./{{ .cmddir }}" + + bash_output = Utils.safe_popen_read(bin/"hof", "completion", "bash") + (bash_completion/"hof").write bash_output + zsh_output = Utils.safe_popen_read(bin/"hof", "completion", "zsh") + (zsh_completion/"_hof").write zsh_output + fish_output = Utils.safe_popen_read(bin/"hof", "completion", "fish") + (fish_completion/"hof.fish").write fish_output + end + + test do + assert_match "v#{version}", shell_output("#{bin}/hof version") + + system bin/"hof", "mod", "init", "cue", "brew.sh/brewtest" + assert_predicate testpath/"cue.mods", :exist? + assert_equal "module: \"brew.sh/brewtest\"", (testpath/"cue.mod/module.cue").read.chomp + + assert_match version.to_s, shell_output(bin/"hof version") + end +end