blob: 7100ab7072efbd228ca4351ae357e12b7788a842 [file] [log] [blame]
Parker Schuh5dbce222017-03-22 20:52:16 -07001def _aos_vision_downloader_impl(ctx):
2 all_files = ctx.files.srcs
3 ctx.file_action(
4 output = ctx.outputs.executable,
5 executable = True,
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 "$@"' % (ctx.executable._downloader.short_path,
12 ' '.join([src.short_path for src in all_files]),
13 ctx.attr.default_target),
14 ]),
15 )
16
17 to_download = all_files
18
19 return struct(
20 runfiles = ctx.runfiles(
21 files = to_download + ctx.files._downloader,
22 collect_data = True,
23 collect_default = True,
24 ),
25 files = set([ctx.outputs.executable]),
26 )
27
28'''Creates a binary which downloads code to a robot camera processing unit.
29
30Running this with `bazel run` will actually download everything.
31
32Attrs:
33 srcs: The files to download. They currently all get shoved into one folder.
34 default_target: The default host to download to. If not specified, defaults to
35 root@10.9.71.179.
36'''
37aos_vision_downloader = rule(
38 implementation = _aos_vision_downloader_impl,
39 attrs = {
40 '_downloader': attr.label(
41 executable = True,
42 cfg = 'host',
43 default = Label('//aos/vision/download:downloader'),
44 ),
45 'srcs': attr.label_list(
46 mandatory = True,
47 allow_files = True,
48 ),
49 'default_target': attr.string(
50 default = 'root@10.9.71.179',
51 ),
52 },
53 executable = True,
54)