blob: e960f2774373473356d6a520ef0ea90734c48a7b [file] [log] [blame]
Brian Silvermanaf485d62015-10-12 00:37:14 -04001def _aos_downloader_impl(ctx):
2 ctx.file_action(
3 output = ctx.outputs.executable,
4 executable = True,
5 content = '\n'.join([
6 '#!/bin/bash',
Brian Silvermand54068e2015-10-14 17:56:05 -04007 'cd "${BASH_SOURCE[@]}.runfiles"',
Brian Silvermanaf485d62015-10-12 00:37:14 -04008 '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
25Running this with `bazel run` will actually download everything.
26
27Attrs:
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'''
32aos_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)