blob: c972639cf0ace184464cdd074f7164adff00103f [file] [log] [blame]
Parker Schuh5dbce222017-03-22 20:52:16 -07001def _aos_vision_downloader_impl(ctx):
Austin Schuh8e17be92019-12-24 09:32:11 -08002 all_files = ctx.files.srcs
Philipp Schrader5dd9eda2020-11-08 10:16:35 -08003 ctx.actions.write(
Austin Schuh8e17be92019-12-24 09:32:11 -08004 output = ctx.outputs.executable,
Philipp Schrader5dd9eda2020-11-08 10:16:35 -08005 is_executable = True,
Austin Schuh8e17be92019-12-24 09:32:11 -08006 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 Schuh5dbce222017-03-22 20:52:16 -070018
Austin Schuh8e17be92019-12-24 09:32:11 -080019 to_download = all_files
Parker Schuh5dbce222017-03-22 20:52:16 -070020
Austin Schuh8e17be92019-12-24 09:32:11 -080021 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 Schuh5dbce222017-03-22 20:52:16 -070029
Austin Schuh8e17be92019-12-24 09:32:11 -080030"""Creates a binary which downloads code to a robot camera processing unit.
Parker Schuh5dbce222017-03-22 20:52:16 -070031
32Running this with `bazel run` will actually download everything.
33
34Attrs:
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 Schuh8e17be92019-12-24 09:32:11 -080038"""
Parker Schuh5dbce222017-03-22 20:52:16 -070039aos_vision_downloader = rule(
Austin Schuh8e17be92019-12-24 09:32:11 -080040 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 Schuh5dbce222017-03-22 20:52:16 -070056)