blob: 6b2648721f63fbdc41f90947e0eee1ad430835a6 [file] [log] [blame]
Sergiusz Bazanskif2a812b2019-01-13 17:51:34 +01001def _copy_go_binary_impl(ctx):
2 output = ctx.actions.declare_file(ctx.label.name)
Serge Bazanski38aea812019-07-14 14:07:15 +02003 for f in ctx.attr.src.files.to_list():
Sergiusz Bazanskif2a812b2019-01-13 17:51:34 +01004 # go_binary rules have two outputs, a library and the binary itself.
5 # The following is a horrible hack to avoid copying the library.
6 if f.path.endswith(".a"):
7 continue
Serge Bazanski38aea812019-07-14 14:07:15 +02008 ctx.actions.run_shell(
Sergiusz Bazanskif2a812b2019-01-13 17:51:34 +01009 inputs=[f],
10 outputs=[output],
11 mnemonic="CopyGoBinary",
12 command="mkdir -p %s && cp %s %s" % (output.dirname, f.path, output.path))
13 return [DefaultInfo(executable=output)]
14
15copy_go_binary = rule(
16 implementation=_copy_go_binary_impl,
17 attrs={
18 "src": attr.label(mandatory=True, allow_files=True),
19 },
20 executable=True,
21)