Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 1 | def _aos_downloader_impl(ctx): |
| 2 | ctx.file_action( |
| 3 | output = ctx.outputs.executable, |
| 4 | executable = True, |
| 5 | content = '\n'.join([ |
| 6 | '#!/bin/bash', |
Brian Silverman | d54068e | 2015-10-14 17:56:05 -0400 | [diff] [blame] | 7 | 'cd "${BASH_SOURCE[@]}.runfiles"', |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 8 | 'exec %s %s -- %s "$@"' % (ctx.executable._downloader.short_path, |
| 9 | ' '.join([src.short_path for src in ctx.files.srcs]), |
| 10 | ctx.attr.default_target), |
| 11 | ]), |
| 12 | ) |
| 13 | |
| 14 | return struct( |
| 15 | runfiles = ctx.runfiles( |
| 16 | files = ctx.files.srcs + ctx.files._downloader, |
| 17 | collect_data = True, |
| 18 | collect_default = True, |
| 19 | ), |
| 20 | files = set([ctx.outputs.executable]), |
| 21 | ) |
| 22 | |
| 23 | '''Creates a binary which downloads code to a robot. |
| 24 | |
| 25 | Running this with `bazel run` will actually download everything. |
| 26 | |
| 27 | Attrs: |
| 28 | srcs: The files to download. They currently all get shoved into one folder. |
| 29 | default_target: The default host to download to. If not specified, defaults to |
| 30 | roboRIO-971.local. |
| 31 | ''' |
| 32 | aos_downloader = rule( |
| 33 | implementation = _aos_downloader_impl, |
| 34 | attrs = { |
| 35 | '_downloader': attr.label( |
| 36 | executable = True, |
| 37 | cfg = HOST_CFG, |
| 38 | default = Label('//aos/prime/downloader'), |
| 39 | ), |
| 40 | 'srcs': attr.label_list( |
| 41 | mandatory = True, |
| 42 | allow_files = True, |
| 43 | ), |
| 44 | 'default_target': attr.string( |
| 45 | default = 'roboRIO-971.local', |
| 46 | ), |
| 47 | }, |
| 48 | executable = True, |
| 49 | ) |