Skip to content

Commit

Permalink
update templates
Browse files Browse the repository at this point in the history
  • Loading branch information
verdverm committed Aug 28, 2022
1 parent 276a8e8 commit 662d507
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 23 deletions.
34 changes: 34 additions & 0 deletions .hof/shadow/AdhocGen/hof.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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"

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")
end
end
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +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
hof gen hof.cue -T templates/from-git-source.rb=hof.rb --no-format --diff3
gen-bin:
hof gen hof.cue -T templates/from-gh-release.rb=hof.rb --no-format

34 changes: 34 additions & 0 deletions templates/core.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class {{ title .name }} < Formula
desc "{{ .desc }}"
homepage "{{ .homepage }}"
url "{{ .url }}",
tag: "{{ .tag }}",
revision: "{{ .commit }}"
license "{{ .license }}"
head "{{ .url }}", branch: "{{ .branch }}"

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/"{{ .name }}", "completion", "bash")
(bash_completion/"{{ .name }}").write bash_output
zsh_output = Utils.safe_popen_read(bin/"{{ .name }}", "completion", "zsh")
(zsh_completion/"_{{ .name }}").write zsh_output
fish_output = Utils.safe_popen_read(bin/"{{ .name }}", "completion", "fish")
(fish_completion/"{{ .name }}.fish").write fish_output
end

test do
assert_match "v#{version}", shell_output("#{bin}/{{ .name }} version")
end
end

29 changes: 7 additions & 22 deletions templates/from-git-source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ class {{ title .name }} < Formula
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

Expand All @@ -29,21 +20,15 @@ def install
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
bash_output = Utils.safe_popen_read(bin/"{{ .name }}", "completion", "bash")
(bash_completion/"{{ .name }}").write bash_output
zsh_output = Utils.safe_popen_read(bin/"{{ .name }}", "completion", "zsh")
(zsh_completion/"_{{ .name }}").write zsh_output
fish_output = Utils.safe_popen_read(bin/"{{ .name }}", "completion", "fish")
(fish_completion/"{{ .name }}.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")
assert_match "v#{version}", shell_output("#{bin}/{{ .name }} version")
end
end

0 comments on commit 662d507

Please sign in to comment.