Added ahal

This is a formatted copy of WPILib's default user-visible C++ API, with
a bit of completely unnecessary functionality stripped out. Most of the
stripping so far is only related to weird threading decisions.

Change-Id: Icbfd949b48cd115561862cb909bcc572aba0e753
diff --git a/third_party/BUILD b/third_party/BUILD
index 20bb7e0..934486e 100644
--- a/third_party/BUILD
+++ b/third_party/BUILD
@@ -1,7 +1,14 @@
 cc_library(
-  name = 'wpilib',
-  deps = ['//third_party/allwpilib_2018:wpilib'],
-  visibility = ['//visibility:public'],
-  linkstatic = True,
-  restricted_to = ['//tools:roborio'],
+    name = "wpilib",
+    linkstatic = True,
+    restricted_to = ["//tools:roborio"],
+    visibility = ["//visibility:public"],
+    deps = ["//frc971/wpilib/ahal"],
+)
+
+cc_library(
+    name = "wpilib_hal",
+    restricted_to = ["//tools:roborio"],
+    visibility = ["//visibility:public"],
+    deps = ["//third_party/allwpilib_2018:hal"],
 )
diff --git a/third_party/Phoenix-frc-lib/BUILD b/third_party/Phoenix-frc-lib/BUILD
index 7a1934a..4686b68 100644
--- a/third_party/Phoenix-frc-lib/BUILD
+++ b/third_party/Phoenix-frc-lib/BUILD
@@ -1,6 +1,7 @@
 # It also restricts use to only with CTRE products and a roboRIO in FRC.
 licenses(["permissive"])
 
+# Excludes motor/sensor code because those have reliances on WPILib.
 cc_library(
     name = "phoenix",
     srcs = glob(
@@ -12,6 +13,8 @@
             "**/Tasking/**",
             "cpp/src/RCRadio3Ch.cpp",
             "cpp/src/CompileTest.cpp",
+            "**/MotorControl/**",
+            "**/Sensors/**",
         ],
     ) + [
         "libraries/driver/lib/libCTRE_PhoenixCCI.a",
@@ -23,6 +26,8 @@
         ],
         exclude = [
             "**/Tasking/**",
+            "**/MotorControl/**",
+            "**/Sensors/**",
             "cpp/include/ctre/phoenix/RCRadio3Ch.h",
         ],
     ),
diff --git a/third_party/allwpilib_2018/BUILD b/third_party/allwpilib_2018/BUILD
index 38d9559..54e63da 100644
--- a/third_party/allwpilib_2018/BUILD
+++ b/third_party/allwpilib_2018/BUILD
@@ -1,143 +1,65 @@
-licenses(['notice'])
-
-genrule(
-  name = 'wpilib_version',
-  outs = ['shared/src/WPILibVersion.cpp'],
-  cmd = '\n'.join([
-    "cat > \"$@\" << EOF",
-    "// Autogenerated file! Do not manually edit this file.",
-    "#include \"WPILibVersion.h\"",
-    "const char* GetWPILibVersion() {",
-    "  return \"2018-frc971\";",
-    "}",
-    "EOF",
-  ]),
-)
-
-_header_dirs = [
-  'wpilibc/src/main/native/include',
-  #'wpilibc/shared/include',
-  #'wpilibc/athena/include',
-  'hal/src/main/native/include',
-  'hal/src/main/native/athena',
-  'hal/src/main/native/include/HAL/cpp',
-  #'hal/include',
-  #'hal/lib/athena',
-]
+licenses(["notice"])
 
 # Names of WPILib "devices" I don't want to deal with making trivial updates to
 # chop out various ugliness or have to vet for sanity.
 _excluded_devices = [
-  'ADXL345_I2C',
-  'ADXL345_SPI',
-  'ADXL362',
-  'ADXRS450_Gyro',
-  'AnalogAccelerometer',
-  #'AnalogGyro',
-  'AnalogPotentiometer',
-  'CANJaguar',
-  'CANSpeedController',
-  'CANTalon',
-  'CameraServer',
-  'DoubleSolenoid',
-  'GamepadBase',
-  'GearTooth',
-  'GenericHID',
-  #'GyroBase',
-  'IterativeRobot',
-  'Jaguar',
-  'Joystick',
-  'JoystickBase',
-  #'Log',
-  #'MotorSafety',
-  #'MotorSafetyHelper',
-  'OSSerialPort',
-  #'PIDController',
-  #'PIDSource',
-  #'PWMSpeedController',
-  'Potentiometer',
-  'RobotDrive',
-  'SD540',
-  #'SafePWM',
-  #'SerialHelper',
-  #'SerialPort',
-  #'Spark',
-  #'SpeedController',
-  'TalonSRX',
-  'Ultrasonic',
-  'Victor',
-  'XboxController',
-  #'visa',
-]
-
-# Whole subdirectories of WPILib we don't want around.
-_excluded_directories = [
-  #'SmartDashboard',
-  #'LiveWindow',
-  #'Commands',
-  #'Buttons',
-  #'Filters',
-  'LabView',
-  'vision',
+    "AnalogGyro",
+    "SerialPort",
+    "SerialHelper",
+    "OSSerialPort",
+    "visa",
 ]
 
 # Header files we don't want to have.
 _bad_hdrs = ([
-  'wpilibc/src/main/native/include/WPILib.h',
-  'hal/src/main/native/include/HAL/LabVIEW/HAL.h',
-  #'wpilibc/**/Accelerometer.*',
-] + ['**/%s/**' % d for d in _excluded_directories] +
- ['**/%s.*' % d for d in _excluded_devices])
-_h_hdrs = glob([d + '/**/*.h' for d in _header_dirs], exclude=_bad_hdrs)
-_hpp_hdrs = glob([d + '/**/*.hpp' for d in _header_dirs], exclude=_bad_hdrs)
+    "hal/include/HAL/LabVIEW/HAL.h",
+] + ["**/%s.*" % d for d in _excluded_devices])
+
+_hal_header_dirs = [
+    "hal/src/main/native/athena",
+    "hal/src/main/native/include",
+]
+
+_hal_h_hdrs = glob(
+    [d + "/**/*.h" for d in _hal_header_dirs],
+    exclude = _bad_hdrs,
+)
+
+_hal_hpp_hdrs = glob(
+    [d + "/**/*.hpp" for d in _hal_header_dirs],
+    exclude = _bad_hdrs,
+)
 
 cc_library(
-  name = 'wpilib',
-  visibility = ['//third_party:__pkg__'],
-  srcs = glob([
-    'wpilibc/src/main/native/cpp/*.cpp',
-    'wpilibc/src/main/native/cpp/interfaces/*.cpp',
-    'wpilibc/src/main/native/cpp/LiveWindow/*.cpp',
-    'wpilibc/src/main/native/cpp/Commands/*.cpp',
-    'wpilibc/src/main/native/cpp/SmartDashboard/*.cpp',
-
-    'hal/src/main/native/athena/*.cpp',
-    'hal/src/main/native/athena/cpp/*.cpp',
-    'hal/src/main/native/athena/ctre/*.cpp',
-    'hal/src/main/native/shared/handles/*.cpp',
-    'wpilibc/src/main/native/cpp/Internal/*.cpp',
-  ], exclude = (
-    ['**/%s/**' % d for d in _excluded_directories] +
-    ['**/%s.*' % d for d in _excluded_devices] + [
-    #'wpilibc/**/Accelerometer.*',
-  ])) + [
-    ':wpilib_version',
-  ],
-  copts = [
-    '-Wno-unused-parameter',
-    '-Wno-switch-enum',
-    '-Wno-attributes',
-    '-Wno-cast-align',
-    '-Wno-cast-qual',
-    '-Wno-deprecated-declarations',
-    '-Wno-error',
-    #'-Wno-unused-const-variable',
-  ],
-  deps = [
-    '//third_party/ntcore_2018:ntcore',
-    '@allwpilib_ni_libraries_repo_2018//:ni-libraries',
-    '//aos/logging',
-  ],
-  hdrs = _h_hdrs + _hpp_hdrs + [
-    'wpilibc/src/main/native/include/circular_buffer.inc',
-    'wpilibc/src/main/native/include/SpeedControllerGroup.inc',
-  ],
-  includes = _header_dirs,
-  linkopts = [
-    '-lpthread',
-  ],
-  defines = [
-    'WPILIB2018=1',
-  ],
-  restricted_to = ['//tools:roborio'],
+    name = "hal",
+    srcs = glob(
+        [
+            "hal/src/main/native/athena/*.cpp",
+            "hal/src/main/native/athena/cpp/*.cpp",
+            "hal/src/main/native/athena/ctre/*.cpp",
+            "hal/src/main/native/shared/handles/*.cpp",
+        ],
+        exclude = ["**/%s.*" % d for d in _excluded_devices],
+    ),
+    hdrs = _hal_h_hdrs + _hal_hpp_hdrs,
+    copts = [
+        "-Wno-unused-parameter",
+        "-Wno-switch-enum",
+        "-Wno-attributes",
+        "-Wno-cast-align",
+        "-Wno-cast-qual",
+        "-Wno-deprecated-declarations",
+        "-Wno-error",
+        "-Wno-unused-const-variable",
+    ],
+    defines = ["WPILIB2018=1"],
+    includes = _hal_header_dirs,
+    linkopts = ["-lpthread"],
+    restricted_to = ["//tools:roborio"],
+    visibility = ["//third_party:__pkg__"],
+    deps = [
+        "//aos/logging",
+        "//third_party/wpiutil_2018:wpiutil",
+        "@allwpilib_ni_libraries_repo_2018//:ni-libraries",
+    ],
 )
diff --git a/third_party/allwpilib_2018/hal/src/main/native/athena/HAL.cpp b/third_party/allwpilib_2018/hal/src/main/native/athena/HAL.cpp
index faa88b5..5a2fc1c 100644
--- a/third_party/allwpilib_2018/hal/src/main/native/athena/HAL.cpp
+++ b/third_party/allwpilib_2018/hal/src/main/native/athena/HAL.cpp
@@ -29,7 +29,6 @@
 #include "HAL/handles/HandlesInternal.h"
 #include "HALInitializer.h"
 #include "ctre/ctre.h"
-#include "visa/visa.h"
 
 using namespace hal;
 
@@ -44,7 +43,6 @@
   InitializeHandlesInternal();
   InitializeAccelerometer();
   InitializeAnalogAccumulator();
-  InitializeAnalogGyro();
   InitializeAnalogInput();
   InitializeAnalogInternal();
   InitializeAnalogOutput();
@@ -61,14 +59,12 @@
   InitializeI2C();
   InitialzeInterrupts();
   InitializeNotifier();
-  //InitializeOSSerialPort();
   InitializePCMInternal();
   InitializePDP();
   InitializePorts();
   InitializePower();
   InitializePWM();
   InitializeRelay();
-  InitializeSerialPort();
   InitializeSolenoid();
   InitializeSPI();
   InitializeThreads();
@@ -172,30 +168,6 @@
       return ERR_CANSessionMux_NotAllowed_MESSAGE;
     case HAL_ERR_CANSessionMux_NotInitialized:
       return ERR_CANSessionMux_NotInitialized_MESSAGE;
-    case VI_ERROR_SYSTEM_ERROR:
-      return VI_ERROR_SYSTEM_ERROR_MESSAGE;
-    case VI_ERROR_INV_OBJECT:
-      return VI_ERROR_INV_OBJECT_MESSAGE;
-    case VI_ERROR_RSRC_LOCKED:
-      return VI_ERROR_RSRC_LOCKED_MESSAGE;
-    case VI_ERROR_RSRC_NFOUND:
-      return VI_ERROR_RSRC_NFOUND_MESSAGE;
-    case VI_ERROR_INV_RSRC_NAME:
-      return VI_ERROR_INV_RSRC_NAME_MESSAGE;
-    case VI_ERROR_QUEUE_OVERFLOW:
-      return VI_ERROR_QUEUE_OVERFLOW_MESSAGE;
-    case VI_ERROR_IO:
-      return VI_ERROR_IO_MESSAGE;
-    case VI_ERROR_ASRL_PARITY:
-      return VI_ERROR_ASRL_PARITY_MESSAGE;
-    case VI_ERROR_ASRL_FRAMING:
-      return VI_ERROR_ASRL_FRAMING_MESSAGE;
-    case VI_ERROR_ASRL_OVERRUN:
-      return VI_ERROR_ASRL_OVERRUN_MESSAGE;
-    case VI_ERROR_RSRC_BUSY:
-      return VI_ERROR_RSRC_BUSY_MESSAGE;
-    case VI_ERROR_INV_PARAMETER:
-      return VI_ERROR_INV_PARAMETER_MESSAGE;
     case HAL_PWM_SCALE_ERROR:
       return HAL_PWM_SCALE_ERROR_MESSAGE;
     case HAL_SERIAL_PORT_NOT_FOUND:
diff --git a/third_party/allwpilib_2018/hal/src/main/native/include/HAL/HAL.h b/third_party/allwpilib_2018/hal/src/main/native/include/HAL/HAL.h
index ea396ca..c0d2572 100644
--- a/third_party/allwpilib_2018/hal/src/main/native/include/HAL/HAL.h
+++ b/third_party/allwpilib_2018/hal/src/main/native/include/HAL/HAL.h
@@ -13,7 +13,6 @@
 
 #include "HAL/Accelerometer.h"
 #include "HAL/AnalogAccumulator.h"
-#include "HAL/AnalogGyro.h"
 #include "HAL/AnalogInput.h"
 #include "HAL/AnalogOutput.h"
 #include "HAL/AnalogTrigger.h"
@@ -33,7 +32,6 @@
 #include "HAL/Power.h"
 #include "HAL/Relay.h"
 #include "HAL/SPI.h"
-#include "HAL/SerialPort.h"
 #include "HAL/Solenoid.h"
 
 #endif  // HAL_USE_LABVIEW
diff --git a/third_party/ntcore_2018/BUILD b/third_party/ntcore_2018/BUILD
index 4a6341c..8380dd2 100644
--- a/third_party/ntcore_2018/BUILD
+++ b/third_party/ntcore_2018/BUILD
@@ -1,31 +1,28 @@
-licenses(['notice'])
+licenses(["notice"])
 
 cc_library(
-  name = 'ntcore',
-  visibility = ['//visibility:public'],
-  srcs = glob([
-    'src/main/**/*.cpp',
-    'src/main/**/*.h',
-  ], exclude = [
-    #'src/main/native/cpp/networktables/**',
-    'src/main/native/cpp/jni/**',
-  ]),
-  copts = [
-    '-Wno-switch-enum',
-    '-Wno-cast-align',
-  ],
-  hdrs = glob([
-    'src/main/native/include/**/*.h',
-    'src/main/native/include/**/*.inl',
-  ]),
-  includes = [
-    'src/main/native/include',
-  ],
-  linkopts = [
-    '-lpthread',
-  ],
-  deps = [
-    '//third_party/wpiutil_2018:wpiutil',
-  ],
-  restricted_to = ['//tools:roborio'],
+    name = "ntcore",
+    srcs = glob(
+        [
+            "src/**/*.cpp",
+            "src/**/*.h",
+            "wpiutil/src/**/*.cpp",
+        ],
+        exclude = [
+            "src/main/native/cpp/networktables/**",
+            "src/test/**",
+            "src/main/native/cpp/jni/**",
+        ],
+    ),
+    copts = [
+        "-Wno-unused-parameter",
+    ],
+    includes = [
+        "src/main/native/include",
+    ],
+    restricted_to = ["//tools:roborio"],
+    visibility = ["//visibility:public"],
+    deps = [
+        "//third_party/wpiutil_2018:wpiutil",
+    ],
 )
diff --git a/third_party/wpiutil_2018/BUILD b/third_party/wpiutil_2018/BUILD
index 41822f6..aceed4a 100644
--- a/third_party/wpiutil_2018/BUILD
+++ b/third_party/wpiutil_2018/BUILD
@@ -1,27 +1,21 @@
-licenses(['notice'])
+licenses(["notice"])
 
 cc_library(
-  name = 'wpiutil',
-  visibility = ['//visibility:public'],
-  srcs = glob([
-    'src/main/native/cpp/**/*.cpp',
-    'src/main/native/cpp/**/*.h',
-    'src/main/native/cpp/**/*.inc',
-  ]),
-  copts = [
-    #'-Wno-switch-enum',
-    '-Wno-cast-align',
-    #'-Ithird_party/wpiutil_2018/
-    '-Wno-unused-parameter',
-  ],
-  hdrs = glob([
-    'src/main/native/include/**/*',
-  ]),
-  includes = [
-    'src/main/native/include',
-  ],
-  linkopts = [
-    '-lpthread',
-  ],
-  restricted_to = ['//tools:roborio'],
+    name = "wpiutil",
+    srcs = glob([
+        "src/main/native/cpp/llvm/*.cpp",
+        "src/main/native/cpp/llvm/Unix/Path.inc",
+        "src/main/native/cpp/support/timestamp.cpp",
+    ]),
+    hdrs = glob([
+        "src/main/native/include/**",
+    ]),
+    copts = [
+        "-Wno-unused-parameter",
+    ],
+    includes = [
+        "src/main/native/include",
+    ],
+    restricted_to = ["//tools:roborio"],
+    visibility = ["//visibility:public"],
 )