Merge "Pulled polydrivetrain out into a separate file."
diff --git a/aos/common/controls/replay_control_loop.h b/aos/common/controls/replay_control_loop.h
index e258267..fa98463 100644
--- a/aos/common/controls/replay_control_loop.h
+++ b/aos/common/controls/replay_control_loop.h
@@ -52,6 +52,13 @@
     replayer_.AddDirectQueueSender(process_name, "goal", loop_group_->goal);
   }
 
+  template <class QT>
+  void AddDirectQueueSender(const ::std::string &process_name,
+                            const ::std::string &log_message,
+                            const ::aos::Queue<QT> &queue) {
+    replayer_.AddDirectQueueSender<QT>(process_name, log_message, queue);
+  }
+
   // Replays messages from a file.
   // filename can be straight from the command line; all sanity checking etc is
   // handled by this function.
diff --git a/aos/externals/BUILD b/aos/externals/BUILD
index e42db6c..55b85d4 100644
--- a/aos/externals/BUILD
+++ b/aos/externals/BUILD
@@ -16,27 +16,31 @@
     'allwpilib/wpilibc/wpilibC++Devices/src/Internal/*.cpp',
     'allwpilib/hal/lib/Athena/*.cpp',
     'allwpilib/hal/lib/Athena/ctre/*.cpp',
+  ], [
+    # This looks like an older version of the file, so we want to use the other
+    # one.
+    'allwpilib/wpilibc/wpilibC++Devices/include/NetworkCommunication/FRCComm.h',
   ]) + [
+    'allwpilib/hal/lib/Athena/NetworkCommunication/FRCComm.h',
     'forwpilib/dma.cc',
+    'allwpilib/ni-libraries/libFRC_NetworkCommunication.so.1.5.0',
+    'allwpilib/ni-libraries/libRoboRIO_FRC_ChipObject.so.1.2.0',
+    'allwpilib/ni-libraries/libNiFpgaLv.so.14.0.0',
+    'allwpilib/ni-libraries/libNiFpga.so.14.0.0',
+    'allwpilib/ni-libraries/libNiRioSrv.so.14.0.0',
+    'allwpilib/ni-libraries/libspi.so.1.0.0',
+    'allwpilib/ni-libraries/libi2c.so.1.0.0',
+  ],
+  defines = [
+    'WPILIB2015=1',
   ],
   copts = [
     '-Wno-error',
   ],
-  hdrs = glob([d + '/*.h' for d in _header_dirs]),
+  hdrs = glob([d + '/**/*.h' for d in _header_dirs] + [d + '/**/*.hpp' for d in _header_dirs]),
   includes = _header_dirs,
   linkopts = [
-    '-Laos/externals/allwpilib/ni-libraries',
     '-lpthread',
-    '-lFRC_NetworkCommunication',
-    '-lRoboRIO_FRC_ChipObject',
-    '-lNiFpgaLv',
-    '-lNiFpga',
-    '-lNiRioSrv',
-    '-lspi',
-    '-li2c',
-  ],
-  defines = [
-    'WPILIB2015=1',
   ],
 )
 
diff --git a/opt_bazel_base_workspace b/opt_bazel_base_workspace
deleted file mode 120000
index 36f5142..0000000
--- a/opt_bazel_base_workspace
+++ /dev/null
@@ -1 +0,0 @@
-/usr/share/lib/bazel/tools/
\ No newline at end of file
diff --git a/third_party/googletest/BUILD b/third_party/googletest/BUILD
index b76b35b..a424c49 100644
--- a/third_party/googletest/BUILD
+++ b/third_party/googletest/BUILD
@@ -368,6 +368,7 @@
 cc_test(
     name = "googletest_gtest_typed_test_test",
     srcs = [
+        "googletest/test/gtest-typed-test_test.h",
         "googletest/test/gtest-typed-test_test.cc",
     ],
     deps = [
@@ -378,6 +379,7 @@
 cc_test(
     name = "googletest_gtest_typed_test2_test",
     srcs = [
+        "googletest/test/gtest-typed-test_test.h",
         "googletest/test/gtest-typed-test2_test.cc",
     ],
     deps = [
@@ -402,6 +404,7 @@
 cc_test(
     name = "googletest_gtest_production_test",
     srcs = [
+        "googletest/test/production.h",
         "googletest/test/production.cc",
     ],
     deps = [
@@ -534,6 +537,7 @@
 cc_test(
     name = "googlemock_gmock_link2_test",
     srcs = [
+        "googlemock/test/gmock_link_test.h",
         "googlemock/test/gmock_link2_test.cc",
     ],
     deps = [
diff --git a/third_party/libevent/BUILD b/third_party/libevent/BUILD
index 97c4fe2..ee778f0 100644
--- a/third_party/libevent/BUILD
+++ b/third_party/libevent/BUILD
@@ -1,6 +1,6 @@
 licenses(['notice'])
 
-load('/tools/build_rules/select', 'compiler_select', 'address_size_select')
+load('/tools/build_rules/select', 'compiler_select', 'address_size_select', 'cpu_select')
 
 cc_library(
   name = 'libevent',
@@ -33,12 +33,14 @@
 
     'evthread_pthread.c',
 
-    'include/event2/event-config.h',
-
     #'compat/sys/queue.h',
   ] + glob([
     '*-internal.h',
+    'include/event2/*.h',
   ]),
+  textual_hdrs = [
+    'arc4random.c',
+  ],
   hdrs = [
     'event.h',
     'evhttp.h',
@@ -120,7 +122,6 @@
     '_EVENT_HAVE_SYS_TYPES_H=1',
     '_EVENT_HAVE_SYS_UIO_H=1',
     '_EVENT_HAVE_SYS_WAIT_H=1',
-    '_EVENT_HAVE_TAILQFOREACH=1',
     '_EVENT_HAVE_TIMERADD=1',
     '_EVENT_HAVE_TIMERCLEAR=1',
     '_EVENT_HAVE_TIMERCMP=1',
@@ -157,6 +158,11 @@
       '_EVENT_SIZEOF_SIZE_T=8',
       '_EVENT_SIZEOF_VOID_P=8',
     ],
+  }) + cpu_select({
+    'amd64': [
+      '_EVENT_HAVE_TAILQFOREACH=1',
+    ],
+    'roborio': [],
   }),
 
   copts = [
diff --git a/third_party/libevent/buffer.c b/third_party/libevent/buffer.c
index de4ab52..0e61fbe 100644
--- a/third_party/libevent/buffer.c
+++ b/third_party/libevent/buffer.c
@@ -90,6 +90,7 @@
 #include "evthread-internal.h"
 #include "evbuffer-internal.h"
 #include "bufferevent-internal.h"
+#include "event-internal.h"
 
 /* some systems do not have MAP_FAILED */
 #ifndef MAP_FAILED
diff --git a/tools/bazel.rc b/tools/bazel.rc
index 6d5dc61..548f82b 100644
--- a/tools/bazel.rc
+++ b/tools/bazel.rc
@@ -1,11 +1,7 @@
-# TODO(Brian): Figure out how we're going to distribute Bazel so everybody
-# doesn't need to hand-edit this file or use a .bazelrc...
-build --package_path %workspace%:%workspace%/opt_bazel_base_workspace
-fetch --package_path %workspace%:%workspace%/opt_bazel_base_workspace
-query --package_path %workspace%:%workspace%/opt_bazel_base_workspace
-
+# Use our CROSSTOOL.
 build --crosstool_top=//tools/cpp:toolchain
-build --spawn_strategy=standalone
+# Don't switch HOST compilers.
+build --host_crosstool_top=//tools/cpp:toolchain
 
 # Show paths to a few more than just 1 target.
 build --show_result 15
diff --git a/tools/build_rules/fortran.bzl b/tools/build_rules/fortran.bzl
index 4de4430..9f564d3 100644
--- a/tools/build_rules/fortran.bzl
+++ b/tools/build_rules/fortran.bzl
@@ -22,7 +22,7 @@
       filtered_cmd.append(flag)
 
   ctx.action(
-    inputs = [ctx.file.src],
+    inputs = [ctx.file.src] + ctx.files._cc_toolchain,
     outputs = [ctx.outputs.pic_o],
     mnemonic = "Fortran",
     executable = ctx.fragments.cpp.compiler_executable,
@@ -45,6 +45,11 @@
   attrs = {
     'src': attr.label(single_file=True, allow_files=FileType(['.f'])),
     'cc_libs': attr.label_list(providers=['cc']),
+    # TODO(Brian): Replace this with something more fine-grained from the
+    # configuration fragment or something.
+    '_cc_toolchain': attr.label(
+      default = Label('//tools/cpp:toolchain'),
+    ),
   },
   outputs = _define_fortran_output,
   fragments = [
@@ -62,9 +67,11 @@
   pic_o_files = []
   for src in srcs:
     pic_o_file = src[:-2] + '.pic.o'
-    _single_fortran_object(name=name + '_' + pic_o_file,
-                           src=src,
-                           visibility=['//visibility:private'])
+    _single_fortran_object(
+      name = name + '_' + pic_o_file,
+      src = src,
+      visibility = ['//visibility:private'],
+    )
     pic_o_files.append(pic_o_file)
 
   native.cc_library(
diff --git a/tools/cpp/BUILD b/tools/cpp/BUILD
index 8b0927f..3a33e0e 100644
--- a/tools/cpp/BUILD
+++ b/tools/cpp/BUILD
@@ -81,6 +81,7 @@
   name = 'roborio-compiler-files',
   srcs = [
     '//tools/cpp/arm-frc-linux-gnueabi:tool-wrappers',
+    '//tools/cpp/arm-frc-linux-gnueabi:as',
     '@arm-frc-linux-gnueabi-repo//:compiler_pieces',
   ],
 )
@@ -90,6 +91,8 @@
   srcs = [
     '//tools/cpp/arm-frc-linux-gnueabi:ld',
     '//tools/cpp/arm-frc-linux-gnueabi:ar',
+    '//tools/cpp/arm-frc-linux-gnueabi:gcc',
+    '@arm-frc-linux-gnueabi-repo//:compiler_pieces',
   ],
 )
 filegroup(
diff --git a/tools/cpp/CROSSTOOL b/tools/cpp/CROSSTOOL
index acf583b..cc8d106 100644
--- a/tools/cpp/CROSSTOOL
+++ b/tools/cpp/CROSSTOOL
@@ -318,38 +318,38 @@
   compiler_flag: "--sysroot=external/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi"
   compiler_flag: "-nostdinc"
   compiler_flag: "-isystem"
-  compiler_flag: "tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include",
+  compiler_flag: "external/arm-frc-linux-gnueabi-repo/usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include",
   compiler_flag: "-isystem"
-  compiler_flag: "tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include-fixed"
+  compiler_flag: "external/arm-frc-linux-gnueabi-repo/usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include-fixed"
   compiler_flag: "-isystem"
-  compiler_flag: "tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/usr/include"
+  compiler_flag: "external/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/usr/include"
 
   cxx_flag: "-isystem"
-  cxx_flag: "tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include/c++/4.9.3"
+  cxx_flag: "external/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include/c++/4.9.3"
   cxx_flag: "-isystem"
-  cxx_flag: "tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include/c++/4.9.3/arm-frc-linux-gnueabi"
+  cxx_flag: "external/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include/c++/4.9.3/arm-frc-linux-gnueabi"
   cxx_flag: "-isystem"
-  cxx_flag: "tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include/c++/4.9.3/backward"
+  cxx_flag: "external/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include/c++/4.9.3/backward"
   cxx_flag: "-isystem"
-  cxx_flag: "tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include"
+  cxx_flag: "external/arm-frc-linux-gnueabi-repo/usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include"
   cxx_flag: "-isystem"
-  cxx_flag: "tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include-fixed"
+  cxx_flag: "external/arm-frc-linux-gnueabi-repo/usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include-fixed"
   cxx_flag: "-isystem"
-  cxx_flag: "tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include"
+  cxx_flag: "external/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include"
   cxx_flag: "-isystem"
-  cxx_flag: "tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/usr/include"
+  cxx_flag: "external/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/usr/include"
 
   # TODO(bazel-team): In theory, the path here ought to exactly match the path
   # used by gcc. That works because bazel currently doesn't track files at
   # absolute locations and has no remote execution, yet. However, this will need
   # to be fixed, maybe with auto-detection?
-  cxx_builtin_include_directory: "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include/c++/4.9.3"
-  cxx_builtin_include_directory: "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include/c++/4.9.3/arm-frc-linux-gnueabi"
-  cxx_builtin_include_directory: "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include/c++/4.9.3/backward"
-  cxx_builtin_include_directory: "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include"
-  cxx_builtin_include_directory: "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include-fixed"
-  cxx_builtin_include_directory: "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/include"
-  cxx_builtin_include_directory: "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo/usr/arm-frc-linux-gnueabi/usr/include"
+  cxx_builtin_include_directory: "%package(@arm-frc-linux-gnueabi-repo//usr/arm-frc-linux-gnueabi/include)%/c++/4.9.3"
+  cxx_builtin_include_directory: "%package(@arm-frc-linux-gnueabi-repo//usr/arm-frc-linux-gnueabi/include)%/c++/4.9.3/arm-frc-linux-gnueabi"
+  cxx_builtin_include_directory: "%package(@arm-frc-linux-gnueabi-repo//usr/arm-frc-linux-gnueabi/include)%/c++/4.9.3/backward"
+  cxx_builtin_include_directory: "%package(@arm-frc-linux-gnueabi-repo//usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include)%"
+  cxx_builtin_include_directory: "%package(@arm-frc-linux-gnueabi-repo//usr/lib/x86_64-linux-gnu/gcc/arm-frc-linux-gnueabi/4.9.3/include-fixed)%"
+  cxx_builtin_include_directory: "%package(@arm-frc-linux-gnueabi-repo//usr/arm-frc-linux-gnueabi/include)%"
+  cxx_builtin_include_directory: "%package(@arm-frc-linux-gnueabi-repo//usr/arm-frc-linux-gnueabi/usr/include)%"
 
   linker_flag: "-lstdc++"
   #linker_flag: "-B/usr/bin/"
diff --git a/tools/cpp/arm-frc-linux-gnueabi/BUILD b/tools/cpp/arm-frc-linux-gnueabi/BUILD
index 4548dbe..64342a9 100644
--- a/tools/cpp/arm-frc-linux-gnueabi/BUILD
+++ b/tools/cpp/arm-frc-linux-gnueabi/BUILD
@@ -17,6 +17,14 @@
 )
 
 filegroup(
+  name = 'as',
+  srcs = [
+    '@arm-frc-linux-gnueabi-repo//:as',
+    'arm-frc-linux-gnueabi-as',
+  ],
+)
+
+filegroup(
   name = 'ld',
   srcs = [
     '@arm-frc-linux-gnueabi-repo//:ld',
@@ -61,6 +69,7 @@
   srcs = [
     ':gcc',
     ':ar',
+    ':as',
     ':ld',
     ':nm',
     ':objcopy',
diff --git a/tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo b/tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo
deleted file mode 120000
index 1c8656d..0000000
--- a/tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-repo
+++ /dev/null
@@ -1 +0,0 @@
-../../../bazel-out/../../external/arm-frc-linux-gnueabi-repo
\ No newline at end of file
diff --git a/tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi.BUILD b/tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi.BUILD
index e579f39..438c9f1 100644
--- a/tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi.BUILD
+++ b/tools/cpp/arm-frc-linux-gnueabi/arm-frc-linux-gnueabi.BUILD
@@ -3,7 +3,7 @@
 filegroup(
   name = 'gcc',
   srcs = [
-    'usr/bin/arm-frc-linux-gnueabi-gcc-4.9',
+    'usr/bin/arm-frc-linux-gnueabi-gcc',
   ],
 )
 
@@ -15,6 +15,13 @@
 )
 
 filegroup(
+  name = 'as',
+  srcs = [
+    'usr/bin/arm-frc-linux-gnueabi-as',
+  ],
+)
+
+filegroup(
   name = 'ld',
   srcs = [
     'usr/bin/arm-frc-linux-gnueabi-ld',
@@ -55,6 +62,8 @@
     'usr/bin/**/*',
     'usr/include/**/*',
     'usr/lib/**/*',
+    'usr/arm-frc-linux-gnueabi/**/*',
+    'usr/lib/x86_64-linux-gnu/gcc/**/*',
   ]),
 )
 
@@ -63,6 +72,7 @@
   srcs = [
     ':gcc',
     ':ar',
+    ':as',
     ':ld',
     ':nm',
     ':objcopy',
diff --git a/y2014/control_loops/drivetrain/BUILD b/y2014/control_loops/drivetrain/BUILD
index 77631af..97fe62c 100644
--- a/y2014/control_loops/drivetrain/BUILD
+++ b/y2014/control_loops/drivetrain/BUILD
@@ -11,6 +11,7 @@
     ':drivetrain_queue',
     '//aos/common/controls:replay_control_loop',
     '//aos/linux_code:init',
+    '//frc971/queues:gyro',
   ],
 )
 
diff --git a/y2014/control_loops/drivetrain/replay_drivetrain.cc b/y2014/control_loops/drivetrain/replay_drivetrain.cc
index 26209fa..091d992 100644
--- a/y2014/control_loops/drivetrain/replay_drivetrain.cc
+++ b/y2014/control_loops/drivetrain/replay_drivetrain.cc
@@ -2,6 +2,7 @@
 #include "aos/linux_code/init.h"
 
 #include "y2014/control_loops/drivetrain/drivetrain.q.h"
+#include "frc971/queues/gyro.q.h"
 
 // Reads one or more log files and sends out all the queue messages (in the
 // correct order and at the correct time) to feed a "live" drivetrain process.
@@ -16,6 +17,9 @@
 
   ::aos::controls::ControlLoopReplayer<::frc971::control_loops::DrivetrainQueue>
       replayer(&::frc971::control_loops::drivetrain_queue, "drivetrain");
+
+  replayer.AddDirectQueueSender("wpilib_interface.Gyro", "sending",
+                                ::frc971::sensors::gyro_reading);
   for (int i = 1; i < argc; ++i) {
     replayer.ProcessFile(argv[i]);
   }