Sergiusz Bazanski | f2a812b | 2019-01-13 17:51:34 +0100 | [diff] [blame] | 1 | def _copy_go_binary_impl(ctx): |
| 2 | output = ctx.actions.declare_file(ctx.label.name) |
Serge Bazanski | 38aea81 | 2019-07-14 14:07:15 +0200 | [diff] [blame] | 3 | for f in ctx.attr.src.files.to_list(): |
Sergiusz Bazanski | f2a812b | 2019-01-13 17:51:34 +0100 | [diff] [blame] | 4 | # 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 Bazanski | 38aea81 | 2019-07-14 14:07:15 +0200 | [diff] [blame] | 8 | ctx.actions.run_shell( |
Sergiusz Bazanski | f2a812b | 2019-01-13 17:51:34 +0100 | [diff] [blame] | 9 | 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 | |
| 15 | copy_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 | ) |