Get rid of //aos/prime
It's not a useful distinction to make any more.
Change-Id: Ieacfe8af4502108b8a5949234a1a3b6a6dd7b7e9
diff --git a/aos/downloader/BUILD b/aos/downloader/BUILD
new file mode 100644
index 0000000..536a7ad
--- /dev/null
+++ b/aos/downloader/BUILD
@@ -0,0 +1,7 @@
+py_binary(
+ name = 'downloader',
+ visibility = ['//visibility:public'],
+ srcs = [
+ 'downloader.py',
+ ],
+)
diff --git a/aos/downloader/downloader.bzl b/aos/downloader/downloader.bzl
new file mode 100644
index 0000000..dff198a
--- /dev/null
+++ b/aos/downloader/downloader.bzl
@@ -0,0 +1,62 @@
+def _aos_downloader_impl(ctx):
+ all_files = ctx.files.srcs + ctx.files.start_srcs + [ctx.outputs._startlist]
+ ctx.file_action(
+ output = ctx.outputs.executable,
+ executable = True,
+ content = '\n'.join([
+ '#!/bin/bash',
+ 'cd "${BASH_SOURCE[@]}.runfiles"',
+ 'exec %s %s -- %s "$@"' % (ctx.executable._downloader.short_path,
+ ' '.join([src.short_path for src in all_files]),
+ ctx.attr.default_target),
+ ]),
+ )
+
+ ctx.file_action(
+ output = ctx.outputs._startlist,
+ content = '\n'.join([f.basename for f in ctx.files.start_srcs]) + '\n',
+ )
+
+ return struct(
+ runfiles = ctx.runfiles(
+ files = all_files + ctx.files._downloader + [ctx.outputs._startlist],
+ collect_data = True,
+ collect_default = True,
+ ),
+ files = set([ctx.outputs.executable]),
+ )
+
+'''Creates a binary which downloads code to a robot.
+
+Running this with `bazel run` will actually download everything.
+
+Attrs:
+ srcs: The files to download. They currently all get shoved into one folder.
+ default_target: The default host to download to. If not specified, defaults to
+ roboRIO-971.local.
+'''
+aos_downloader = rule(
+ implementation = _aos_downloader_impl,
+ attrs = {
+ '_downloader': attr.label(
+ executable = True,
+ cfg = HOST_CFG,
+ default = Label('//aos/downloader'),
+ ),
+ 'start_srcs': attr.label_list(
+ mandatory = True,
+ allow_files = True,
+ ),
+ 'srcs': attr.label_list(
+ mandatory = True,
+ allow_files = True,
+ ),
+ 'default_target': attr.string(
+ default = 'roboRIO-971.local',
+ ),
+ },
+ executable = True,
+ outputs = {
+ '_startlist': '%{name}.start_list.dir/start_list.txt',
+ },
+)
diff --git a/aos/downloader/downloader.py b/aos/downloader/downloader.py
new file mode 100644
index 0000000..26ef19a
--- /dev/null
+++ b/aos/downloader/downloader.py
@@ -0,0 +1,47 @@
+# This file is run by shell scripts generated by the aos_downloader Skylark
+# macro. Everything before the first -- is a hard-coded list of files to
+# download.
+
+from __future__ import print_function
+
+import sys
+import subprocess
+import re
+import os
+
+def main(argv):
+ srcs = argv[1:argv.index('--')]
+ args = argv[argv.index('--') + 1:]
+
+ ROBORIO_TARGET_DIR = '/home/admin/robot_code'
+ ROBORIO_USER = 'admin'
+
+ target_dir = ROBORIO_TARGET_DIR
+ user = ROBORIO_USER
+ destination = args[-1]
+
+ result = re.match('(?:([^:@]+)@)?([^:@]+)(?::([^:@]+))?', destination)
+ if not result:
+ print('Not sure how to parse destination "%s"!' % destination,
+ file=sys.stderr)
+ return 1
+ if result.group(1):
+ user = result.group(1)
+ hostname = result.group(2)
+ if result.group(3):
+ target_dir = result.group(3)
+
+ ssh_target = '%s@%s' % (user, hostname)
+
+ subprocess.check_call(
+ ['rsync', '-c', '-v', '-z', '--copy-links'] + srcs +
+ ['%s:%s' % (ssh_target, target_dir)])
+ subprocess.check_call(
+ ('ssh', ssh_target, '&&'.join([
+ 'chmod u+s %s/starter_exe' % target_dir,
+ 'echo \'Done moving new executables into place\'',
+ 'bash -c \'sync && sync && sync\'',
+ ])))
+
+if __name__ == '__main__':
+ main(sys.argv)