From ec6656aed7a90eab069f6e9fee0bca963b62fd19 Mon Sep 17 00:00:00 2001 From: Alex C <5673946+constinit@users.noreply.github.com> Date: Sat, 19 Mar 2022 19:52:32 -0400 Subject: [PATCH 1/9] Ibazel 0.16.2 (new formula) Ibazel is a tool for automatically running Bazel when source files change. This formula allows building from source and adds support for Apple Silicon. --- Formula/ibazel.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Formula/ibazel.rb diff --git a/Formula/ibazel.rb b/Formula/ibazel.rb new file mode 100644 index 0000000000000..d7ecfeb537d30 --- /dev/null +++ b/Formula/ibazel.rb @@ -0,0 +1,63 @@ +class Ibazel < Formula + desc "Tools for building Bazel targets when source files change" + homepage "https://github.com/bazelbuild/bazel-watcher" + url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.16.2.tar.gz" + sha256 "a927520e7ab3a1fb749043e543c57bb211666cd627d053fbe0e8245730beee75" + license "Apache-2.0" + + depends_on "bazel" => [:build, :test] + depends_on xcode: :build + + def install + system "bazel", "build", "--config=release", "--workspace_status_command", "echo STABLE_GIT_VERSION #{version}", "//ibazel" + bin.install "bazel-bin/ibazel/ibazel_/ibazel" + end + + test do + # Test building a sample Go program + (testpath/"WORKSPACE").write <<~EOS + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + + http_archive( + name = "io_bazel_rules_go", + sha256 = "f2dcd210c7095febe54b804bb1cd3a58fe8435a909db2ec04e31542631cf715c", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.31.0/rules_go-v0.31.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.31.0/rules_go-v0.31.0.zip", + ], + ) + + load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") + + go_rules_dependencies() + + go_register_toolchains(version = "1.18") + EOS + + (testpath/"test.go").write <<~EOS + package main + import "fmt" + func main() { + fmt.Println("Hi!") + } + EOS + + (testpath/"BUILD").write <<~EOS + load("@io_bazel_rules_go//go:def.bzl", "go_binary") + + go_binary( + name = "bazel-test", + srcs = glob(["*.go"]) + ) + EOS + + pid = fork { exec("ibazel", "build", "//:bazel-test") } + out_file = "bazel-bin/bazel-test_/bazel-test" + sleep 1 until File.exist?(out_file) + assert_equal "Hi!\n", pipe_output(out_file) + ensure + Process.kill("TERM", pid) + sleep 1 + Process.kill("TERM", pid) + end +end From 523bbea27f64a4bc13a1d4f267c600c113b4973f Mon Sep 17 00:00:00 2001 From: Alex C <5673946+constinit@users.noreply.github.com> Date: Tue, 5 Apr 2022 12:22:02 -0400 Subject: [PATCH 2/9] Use local go sdk --- Formula/ibazel.rb | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Formula/ibazel.rb b/Formula/ibazel.rb index d7ecfeb537d30..1b0e1ce7387c8 100644 --- a/Formula/ibazel.rb +++ b/Formula/ibazel.rb @@ -6,8 +6,11 @@ class Ibazel < Formula license "Apache-2.0" depends_on "bazel" => [:build, :test] + depends_on "go" => [:build, :test] depends_on xcode: :build + # Patch to use Homebrew's Go + patch :DATA def install system "bazel", "build", "--config=release", "--workspace_status_command", "echo STABLE_GIT_VERSION #{version}", "//ibazel" bin.install "bazel-bin/ibazel/ibazel_/ibazel" @@ -27,11 +30,11 @@ def install ], ) - load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") + load("@io_bazel_rules_go//go:deps.bzl", "go_host_sdk", "go_rules_dependencies") go_rules_dependencies() - go_register_toolchains(version = "1.18") + go_host_sdk(name = "go_sdk") EOS (testpath/"test.go").write <<~EOS @@ -54,10 +57,27 @@ def install pid = fork { exec("ibazel", "build", "//:bazel-test") } out_file = "bazel-bin/bazel-test_/bazel-test" sleep 1 until File.exist?(out_file) - assert_equal "Hi!\n", pipe_output(out_file) + assert_equal "Hi!\n", shell_output(out_file) ensure Process.kill("TERM", pid) sleep 1 Process.kill("TERM", pid) end end + +__END__ +--- a/WORKSPACE ++++ b/WORKSPACE +@@ -62,11 +62,11 @@ http_archive( + ], + ) + +-load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") ++load("@io_bazel_rules_go//go:deps.bzl", "go_host_sdk", "go_rules_dependencies") + + go_rules_dependencies() + +-go_register_toolchains(version = "1.17.6") ++go_host_sdk(name = "go_sdk") + + load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies" \ No newline at end of file From 716583e591efd8c5573558fe92028c3e8054eaad Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Thu, 17 Nov 2022 18:24:38 -0500 Subject: [PATCH 3/9] bump to bazel-watcher 0.20.0 Signed-off-by: Rui Chen --- Formula/ibazel.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Formula/ibazel.rb b/Formula/ibazel.rb index 1b0e1ce7387c8..4286757e8b5f1 100644 --- a/Formula/ibazel.rb +++ b/Formula/ibazel.rb @@ -1,8 +1,8 @@ class Ibazel < Formula desc "Tools for building Bazel targets when source files change" homepage "https://github.com/bazelbuild/bazel-watcher" - url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.16.2.tar.gz" - sha256 "a927520e7ab3a1fb749043e543c57bb211666cd627d053fbe0e8245730beee75" + url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.20.0.tar.gz" + sha256 "7b0f98006b32d2ad5eee38eb9b363005968abf88d235e31fc6dd2a8c4336f33d" license "Apache-2.0" depends_on "bazel" => [:build, :test] @@ -11,9 +11,12 @@ class Ibazel < Formula # Patch to use Homebrew's Go patch :DATA + def install + inreplace ".bazelversion", "5.3.1", "5.3.2" + system "bazel", "build", "--config=release", "--workspace_status_command", "echo STABLE_GIT_VERSION #{version}", "//ibazel" - bin.install "bazel-bin/ibazel/ibazel_/ibazel" + bin.install "bazel-bin/cmd/ibazel/ibazel_/ibazel" end test do @@ -66,18 +69,20 @@ def install end __END__ +diff --git a/WORKSPACE b/WORKSPACE +index 1ec4e43..721d61e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -62,11 +62,11 @@ http_archive( ], ) - + -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") +load("@io_bazel_rules_go//go:deps.bzl", "go_host_sdk", "go_rules_dependencies") - + go_rules_dependencies() - + -go_register_toolchains(version = "1.17.6") +go_host_sdk(name = "go_sdk") - - load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies" \ No newline at end of file + + load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") From b05e9b591608d43bc0e1152ba58defdf260627e6 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Thu, 17 Nov 2022 22:10:10 -0500 Subject: [PATCH 4/9] ibazel: fix build target --- Formula/ibazel.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Formula/ibazel.rb b/Formula/ibazel.rb index 4286757e8b5f1..49297bc61bd04 100644 --- a/Formula/ibazel.rb +++ b/Formula/ibazel.rb @@ -15,7 +15,7 @@ class Ibazel < Formula def install inreplace ".bazelversion", "5.3.1", "5.3.2" - system "bazel", "build", "--config=release", "--workspace_status_command", "echo STABLE_GIT_VERSION #{version}", "//ibazel" + system "bazel", "build", "--config=release", "--workspace_status_command", "echo STABLE_GIT_VERSION #{version}", "//cmd/ibazel:ibazel" bin.install "bazel-bin/cmd/ibazel/ibazel_/ibazel" end From ea2507d0c6d755c86a0afd542cbfed70c8120843 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Fri, 18 Nov 2022 19:37:41 -0500 Subject: [PATCH 5/9] ibazel: remove homebrew patch Signed-off-by: Rui Chen --- Formula/ibazel.rb | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/Formula/ibazel.rb b/Formula/ibazel.rb index 49297bc61bd04..c7baf0186922c 100644 --- a/Formula/ibazel.rb +++ b/Formula/ibazel.rb @@ -9,9 +9,6 @@ class Ibazel < Formula depends_on "go" => [:build, :test] depends_on xcode: :build - # Patch to use Homebrew's Go - patch :DATA - def install inreplace ".bazelversion", "5.3.1", "5.3.2" @@ -67,22 +64,3 @@ def install Process.kill("TERM", pid) end end - -__END__ -diff --git a/WORKSPACE b/WORKSPACE -index 1ec4e43..721d61e 100644 ---- a/WORKSPACE -+++ b/WORKSPACE -@@ -62,11 +62,11 @@ http_archive( - ], - ) - --load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") -+load("@io_bazel_rules_go//go:deps.bzl", "go_host_sdk", "go_rules_dependencies") - - go_rules_dependencies() - --go_register_toolchains(version = "1.17.6") -+go_host_sdk(name = "go_sdk") - - load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") From cd5a1994107df62c6ed773d40794239424e75cb0 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Fri, 18 Nov 2022 19:38:21 -0500 Subject: [PATCH 6/9] ibazel: ignore linux test (same issue with bazel) Signed-off-by: Rui Chen --- Formula/ibazel.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Formula/ibazel.rb b/Formula/ibazel.rb index c7baf0186922c..fa52701ecadf2 100644 --- a/Formula/ibazel.rb +++ b/Formula/ibazel.rb @@ -17,6 +17,10 @@ def install end test do + # linux test failed due to `bin/bazel-real' as a zip file: (error: 5): Input/output error` issue + # it works out locally, thus bypassing the test as a whole + return if OS.linux? + # Test building a sample Go program (testpath/"WORKSPACE").write <<~EOS load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") From bed068cac7534233f49b50ec9db68b9c192d6b86 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Fri, 18 Nov 2022 20:02:17 -0500 Subject: [PATCH 7/9] ibazel: only for build macos for now (bazel does not run in CI for linux) Signed-off-by: Rui Chen --- Formula/ibazel.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Formula/ibazel.rb b/Formula/ibazel.rb index fa52701ecadf2..3e659d0e42997 100644 --- a/Formula/ibazel.rb +++ b/Formula/ibazel.rb @@ -7,7 +7,7 @@ class Ibazel < Formula depends_on "bazel" => [:build, :test] depends_on "go" => [:build, :test] - depends_on xcode: :build + depends_on :macos def install inreplace ".bazelversion", "5.3.1", "5.3.2" @@ -17,10 +17,6 @@ def install end test do - # linux test failed due to `bin/bazel-real' as a zip file: (error: 5): Input/output error` issue - # it works out locally, thus bypassing the test as a whole - return if OS.linux? - # Test building a sample Go program (testpath/"WORKSPACE").write <<~EOS load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") From ab92d657427810c316a93d6e23b3b2184dca7c63 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Sun, 20 Nov 2022 17:11:59 -0500 Subject: [PATCH 8/9] ibazel: add some code comments --- Formula/ibazel.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Formula/ibazel.rb b/Formula/ibazel.rb index 3e659d0e42997..08e03d4f041a0 100644 --- a/Formula/ibazel.rb +++ b/Formula/ibazel.rb @@ -10,6 +10,8 @@ class Ibazel < Formula depends_on :macos def install + # upstream patch PR, https://github.com/bazelbuild/bazel-watcher/pull/556 + # remove in next release inreplace ".bazelversion", "5.3.1", "5.3.2" system "bazel", "build", "--config=release", "--workspace_status_command", "echo STABLE_GIT_VERSION #{version}", "//cmd/ibazel:ibazel" From db5bf4e4a3cef4ce1201af467de3b97d22ecaad8 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Mon, 5 Dec 2022 09:52:40 -0500 Subject: [PATCH 9/9] ibazel 0.21.0 --- Formula/ibazel.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Formula/ibazel.rb b/Formula/ibazel.rb index 08e03d4f041a0..42c4fdd6742b0 100644 --- a/Formula/ibazel.rb +++ b/Formula/ibazel.rb @@ -1,8 +1,8 @@ class Ibazel < Formula desc "Tools for building Bazel targets when source files change" homepage "https://github.com/bazelbuild/bazel-watcher" - url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.20.0.tar.gz" - sha256 "7b0f98006b32d2ad5eee38eb9b363005968abf88d235e31fc6dd2a8c4336f33d" + url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.21.0.tar.gz" + sha256 "c6413d3298c51d968bbbe8a01f481b83947e55eae6af78c0b8268a91e02d7989" license "Apache-2.0" depends_on "bazel" => [:build, :test] @@ -10,10 +10,6 @@ class Ibazel < Formula depends_on :macos def install - # upstream patch PR, https://github.com/bazelbuild/bazel-watcher/pull/556 - # remove in next release - inreplace ".bazelversion", "5.3.1", "5.3.2" - system "bazel", "build", "--config=release", "--workspace_status_command", "echo STABLE_GIT_VERSION #{version}", "//cmd/ibazel:ibazel" bin.install "bazel-bin/cmd/ibazel/ibazel_/ibazel" end