Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 1 | def _aos_downloader_impl(ctx): |
Austin Schuh | e791997 | 2015-11-22 21:27:37 -0800 | [diff] [blame] | 2 | all_files = ctx.files.srcs + ctx.files.start_srcs + [ctx.outputs._startlist] |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 3 | ctx.file_action( |
| 4 | output = ctx.outputs.executable, |
| 5 | executable = True, |
| 6 | content = '\n'.join([ |
| 7 | '#!/bin/bash', |
Brian Silverman | d54068e | 2015-10-14 17:56:05 -0400 | [diff] [blame] | 8 | 'cd "${BASH_SOURCE[@]}.runfiles"', |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 9 | 'exec %s %s -- %s "$@"' % (ctx.executable._downloader.short_path, |
Austin Schuh | 1eceeb9 | 2015-11-08 21:16:06 -0800 | [diff] [blame] | 10 | ' '.join([src.short_path for src in all_files]), |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 11 | ctx.attr.default_target), |
| 12 | ]), |
| 13 | ) |
| 14 | |
Austin Schuh | 1eceeb9 | 2015-11-08 21:16:06 -0800 | [diff] [blame] | 15 | ctx.file_action( |
| 16 | output = ctx.outputs._startlist, |
| 17 | content = '\n'.join([f.basename for f in ctx.files.start_srcs]) + '\n', |
| 18 | ) |
| 19 | |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 20 | return struct( |
| 21 | runfiles = ctx.runfiles( |
Austin Schuh | 1eceeb9 | 2015-11-08 21:16:06 -0800 | [diff] [blame] | 22 | files = all_files + ctx.files._downloader + [ctx.outputs._startlist], |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 23 | collect_data = True, |
| 24 | collect_default = True, |
| 25 | ), |
| 26 | files = set([ctx.outputs.executable]), |
| 27 | ) |
| 28 | |
| 29 | '''Creates a binary which downloads code to a robot. |
| 30 | |
| 31 | Running this with `bazel run` will actually download everything. |
| 32 | |
Brian Silverman | d254040 | 2015-11-28 18:35:00 -0500 | [diff] [blame^] | 33 | This also generates a start_list.txt file with the names of binaries to start. |
| 34 | |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 35 | Attrs: |
| 36 | srcs: The files to download. They currently all get shoved into one folder. |
Brian Silverman | d254040 | 2015-11-28 18:35:00 -0500 | [diff] [blame^] | 37 | start_srcs: Like srcs, except they also get put into start_list.txt. |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 38 | default_target: The default host to download to. If not specified, defaults to |
| 39 | roboRIO-971.local. |
| 40 | ''' |
| 41 | aos_downloader = rule( |
| 42 | implementation = _aos_downloader_impl, |
| 43 | attrs = { |
| 44 | '_downloader': attr.label( |
| 45 | executable = True, |
| 46 | cfg = HOST_CFG, |
Brian Silverman | c206573 | 2015-11-28 22:55:30 +0000 | [diff] [blame] | 47 | default = Label('//aos/downloader'), |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 48 | ), |
Austin Schuh | 1eceeb9 | 2015-11-08 21:16:06 -0800 | [diff] [blame] | 49 | 'start_srcs': attr.label_list( |
| 50 | mandatory = True, |
| 51 | allow_files = True, |
| 52 | ), |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 53 | 'srcs': attr.label_list( |
| 54 | mandatory = True, |
| 55 | allow_files = True, |
| 56 | ), |
| 57 | 'default_target': attr.string( |
| 58 | default = 'roboRIO-971.local', |
| 59 | ), |
| 60 | }, |
| 61 | executable = True, |
Austin Schuh | 1eceeb9 | 2015-11-08 21:16:06 -0800 | [diff] [blame] | 62 | outputs = { |
| 63 | '_startlist': '%{name}.start_list.dir/start_list.txt', |
| 64 | }, |
Brian Silverman | af485d6 | 2015-10-12 00:37:14 -0400 | [diff] [blame] | 65 | ) |