yesod-mirror/homebrew/formula.bzl
Copybara 8157b39ea4
Some checks failed
CI / build (push) Failing after 12s
Project import generated by Copybara.
GitOrigin-RevId: 6370f6ea785709295b6abcf9c60717cacf3ac432
2026-01-20 21:26:21 +00:00

31 lines
No EOL
986 B
Python

def homebrew_formula(name, src, binary, out, visibility = None):
"""
Generates a Homebrew formula with the SHA256 of the binary injected.
Args:
name: The name of the rule.
src: The template file (.rb.tpl).
binary: The binary target to hash.
out: The output filename (.rb).
visibility: Visibility of the rule.
"""
native.genrule(
name = name,
srcs = [src, binary],
outs = [out],
cmd = """
TEMPLATE=$(location %s)
BINARY=$(location %s)
# Calculate SHA256
if command -v sha256sum >/dev/null 2>&1; then
HASH=$$(sha256sum $$BINARY | cut -d' ' -f1)
else
HASH=$$(shasum -a 256 $$BINARY | cut -d' ' -f1)
fi
# Substitute into template
sed "s/{SHA256}/$$HASH/g" $$TEMPLATE > $@
""" % (src, binary),
visibility = visibility,
)