gpg.bzl 855 B

1234567891011121314151617181920212223
  1. def _gpg_sign_impl(ctx):
  2. output_file = ctx.actions.declare_file(ctx.file.base.basename + ctx.attr.suffix, sibling = ctx.file.base)
  3. if not ctx.configuration.default_shell_env.get("GPG_PASS"):
  4. ctx.actions.write(output_file, "")
  5. else:
  6. command = "echo ${GPG_PASS} | gpg --pinentry-mode loopback --digest-algo SHA512 --passphrase-fd 0 --output %s --detach-sig %s" % (output_file.path, ctx.file.base.path)
  7. ctx.actions.run_shell(
  8. command = command,
  9. use_default_shell_env = True,
  10. inputs = [ctx.file.base],
  11. outputs = [output_file],
  12. progress_message = "Signing binary",
  13. mnemonic = "gpg",
  14. )
  15. return [DefaultInfo(files = depset([output_file]))]
  16. gpg_sign = rule(
  17. implementation = _gpg_sign_impl,
  18. attrs = {
  19. "base": attr.label(allow_single_file=True),
  20. "suffix": attr.string(default=".sig"),
  21. },
  22. )