Parker Schuh | 5dbce22 | 2017-03-22 20:52:16 -0700 | [diff] [blame] | 1 | def _aos_vision_downloader_impl(ctx): |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 2 | all_files = ctx.files.srcs |
Philipp Schrader | 5dd9eda | 2020-11-08 10:16:35 -0800 | [diff] [blame] | 3 | ctx.actions.write( |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 4 | output = ctx.outputs.executable, |
Philipp Schrader | 5dd9eda | 2020-11-08 10:16:35 -0800 | [diff] [blame] | 5 | is_executable = True, |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 6 | content = "\n".join([ |
| 7 | "#!/bin/bash", |
| 8 | "set -e", |
| 9 | 'cd "${BASH_SOURCE[0]}.runfiles/%s"' % ctx.workspace_name, |
| 10 | ] + [ |
| 11 | 'exec %s %s -- %s "$@"' % ( |
| 12 | ctx.executable._downloader.short_path, |
| 13 | " ".join([src.short_path for src in all_files]), |
| 14 | ctx.attr.default_target, |
| 15 | ), |
| 16 | ]), |
| 17 | ) |
Parker Schuh | 5dbce22 | 2017-03-22 20:52:16 -0700 | [diff] [blame] | 18 | |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 19 | to_download = all_files |
Parker Schuh | 5dbce22 | 2017-03-22 20:52:16 -0700 | [diff] [blame] | 20 | |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 21 | return struct( |
| 22 | runfiles = ctx.runfiles( |
| 23 | files = to_download + ctx.files._downloader, |
| 24 | collect_data = True, |
| 25 | collect_default = True, |
| 26 | ), |
| 27 | files = set([ctx.outputs.executable]), |
| 28 | ) |
Parker Schuh | 5dbce22 | 2017-03-22 20:52:16 -0700 | [diff] [blame] | 29 | |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 30 | """Creates a binary which downloads code to a robot camera processing unit. |
Parker Schuh | 5dbce22 | 2017-03-22 20:52:16 -0700 | [diff] [blame] | 31 | |
| 32 | Running this with `bazel run` will actually download everything. |
| 33 | |
| 34 | Attrs: |
| 35 | srcs: The files to download. They currently all get shoved into one folder. |
| 36 | default_target: The default host to download to. If not specified, defaults to |
| 37 | root@10.9.71.179. |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 38 | """ |
Parker Schuh | 5dbce22 | 2017-03-22 20:52:16 -0700 | [diff] [blame] | 39 | aos_vision_downloader = rule( |
Austin Schuh | 8e17be9 | 2019-12-24 09:32:11 -0800 | [diff] [blame] | 40 | implementation = _aos_vision_downloader_impl, |
| 41 | attrs = { |
| 42 | "_downloader": attr.label( |
| 43 | executable = True, |
| 44 | cfg = "host", |
| 45 | default = Label("//aos/vision/download:downloader"), |
| 46 | ), |
| 47 | "srcs": attr.label_list( |
| 48 | mandatory = True, |
| 49 | allow_files = True, |
| 50 | ), |
| 51 | "default_target": attr.string( |
| 52 | default = "root@10.9.71.179", |
| 53 | ), |
| 54 | }, |
| 55 | executable = True, |
Parker Schuh | 5dbce22 | 2017-03-22 20:52:16 -0700 | [diff] [blame] | 56 | ) |