blob: 51d6916fe17ab39a284532d7389d2ef5dbf92062 [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
Brian Silvermand2540402015-11-28 18:35:00 -050033This also generates a start_list.txt file with the names of binaries to start.
34
Brian Silvermanaf485d62015-10-12 00:37:14 -040035Attrs:
36 srcs: The files to download. They currently all get shoved into one folder.
Brian Silvermand2540402015-11-28 18:35:00 -050037 start_srcs: Like srcs, except they also get put into start_list.txt.
Brian Silvermanaf485d62015-10-12 00:37:14 -040038 default_target: The default host to download to. If not specified, defaults to
39 roboRIO-971.local.
40'''
41aos_downloader = rule(
42 implementation = _aos_downloader_impl,
43 attrs = {
44 '_downloader': attr.label(
45 executable = True,
46 cfg = HOST_CFG,
Brian Silvermanc2065732015-11-28 22:55:30 +000047 default = Label('//aos/downloader'),
Brian Silvermanaf485d62015-10-12 00:37:14 -040048 ),
Austin Schuh1eceeb92015-11-08 21:16:06 -080049 'start_srcs': attr.label_list(
50 mandatory = True,
51 allow_files = True,
52 ),
Brian Silvermanaf485d62015-10-12 00:37:14 -040053 'srcs': attr.label_list(
54 mandatory = True,
55 allow_files = True,
56 ),
57 'default_target': attr.string(
58 default = 'roboRIO-971.local',
59 ),
60 },
61 executable = True,
Austin Schuh1eceeb92015-11-08 21:16:06 -080062 outputs = {
63 '_startlist': '%{name}.start_list.dir/start_list.txt',
64 },
Brian Silvermanaf485d62015-10-12 00:37:14 -040065)