blob: dff198a9b51753d9e28123cba441692a0b7cfd69 [file] [log] [blame]
Brian Silvermanaf485d62015-10-12 00:37:14 -04001def _aos_downloader_impl(ctx):
Austin Schuhe7919972015-11-22 21:27:37 -08002 all_files = ctx.files.srcs + ctx.files.start_srcs + [ctx.outputs._startlist]
Brian Silvermanaf485d62015-10-12 00:37:14 -04003 ctx.file_action(
4 output = ctx.outputs.executable,
5 executable = True,
6 content = '\n'.join([
7 '#!/bin/bash',
Brian Silvermand54068e2015-10-14 17:56:05 -04008 'cd "${BASH_SOURCE[@]}.runfiles"',
Brian Silvermanaf485d62015-10-12 00:37:14 -04009 'exec %s %s -- %s "$@"' % (ctx.executable._downloader.short_path,
Austin Schuh1eceeb92015-11-08 21:16:06 -080010 ' '.join([src.short_path for src in all_files]),
Brian Silvermanaf485d62015-10-12 00:37:14 -040011 ctx.attr.default_target),
12 ]),
13 )
14
Austin Schuh1eceeb92015-11-08 21:16:06 -080015 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 Silvermanaf485d62015-10-12 00:37:14 -040020 return struct(
21 runfiles = ctx.runfiles(
Austin Schuh1eceeb92015-11-08 21:16:06 -080022 files = all_files + ctx.files._downloader + [ctx.outputs._startlist],
Brian Silvermanaf485d62015-10-12 00:37:14 -040023 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
31Running this with `bazel run` will actually download everything.
32
33Attrs:
34 srcs: The files to download. They currently all get shoved into one folder.
35 default_target: The default host to download to. If not specified, defaults to
36 roboRIO-971.local.
37'''
38aos_downloader = rule(
39 implementation = _aos_downloader_impl,
40 attrs = {
41 '_downloader': attr.label(
42 executable = True,
43 cfg = HOST_CFG,
Brian Silvermanc2065732015-11-28 22:55:30 +000044 default = Label('//aos/downloader'),
Brian Silvermanaf485d62015-10-12 00:37:14 -040045 ),
Austin Schuh1eceeb92015-11-08 21:16:06 -080046 'start_srcs': attr.label_list(
47 mandatory = True,
48 allow_files = True,
49 ),
Brian Silvermanaf485d62015-10-12 00:37:14 -040050 'srcs': attr.label_list(
51 mandatory = True,
52 allow_files = True,
53 ),
54 'default_target': attr.string(
55 default = 'roboRIO-971.local',
56 ),
57 },
58 executable = True,
Austin Schuh1eceeb92015-11-08 21:16:06 -080059 outputs = {
60 '_startlist': '%{name}.start_list.dir/start_list.txt',
61 },
Brian Silvermanaf485d62015-10-12 00:37:14 -040062)