Add rules for packaging up Ruby code.

These were originally written by Parker and then cleaned up by me.

Change-Id: I93b66c83f80ca86a267abb84cab5f160b837083b
diff --git a/build_tests/BUILD b/build_tests/BUILD
index e11937b..75198fd 100644
--- a/build_tests/BUILD
+++ b/build_tests/BUILD
@@ -1,3 +1,5 @@
+load('/tools/build_rules/ruby', 'ruby_binary')
+
 cc_test(
   name = 'gflags_build_test',
   srcs = [
@@ -8,3 +10,25 @@
   ],
   size = 'small',
 )
+
+ruby_binary(
+  name = 'ruby_binary',
+  srcs = [
+    'ruby.rb',
+    'ruby_to_require.rb',
+  ],
+  data = [
+    'ruby_to_require.rb',
+  ],
+)
+
+sh_test(
+  name = 'ruby_build_test',
+  srcs = [
+    'ruby_check.sh',
+  ],
+  data = [
+    ':ruby_binary',
+  ],
+  size = 'small',
+)
diff --git a/build_tests/ruby.rb b/build_tests/ruby.rb
new file mode 100644
index 0000000..12af7fe
--- /dev/null
+++ b/build_tests/ruby.rb
@@ -0,0 +1,18 @@
+# ruby_check.sh runs this and verifies the output matches.
+# The first argument is the absolute path to the runfiles directory to use for
+# testing require with an absolute path.
+
+$loaded = false
+raise unless require_relative 'ruby_to_require.rb'
+raise unless $loaded
+
+# We already loaded this above, so it won't happen again.
+raise if require 'build_tests/ruby_to_require'
+
+$loaded = false
+raise unless require ARGV[0] + '/build_tests/ruby_to_require'
+raise unless $loaded
+
+raise unless ''.encoding == Encoding::UTF_8
+
+puts 'Hi from ruby'
diff --git a/build_tests/ruby_check.sh b/build_tests/ruby_check.sh
new file mode 100755
index 0000000..70d3149
--- /dev/null
+++ b/build_tests/ruby_check.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# Checks the output from ruby.rb.
+
+set -e
+set -u
+
+OUTPUT="$("./build_tests/ruby_binary" "${PWD}")"
+
+if [[ "${OUTPUT}" != "Hi from ruby" ]]; then
+  echo "Output is actually:" >&2
+  echo "${OUTPUT}" >&2
+  exit 1
+fi
diff --git a/build_tests/ruby_to_require.rb b/build_tests/ruby_to_require.rb
new file mode 100644
index 0000000..b63cda2
--- /dev/null
+++ b/build_tests/ruby_to_require.rb
@@ -0,0 +1,4 @@
+# This file is loaded by ruby.rb through several mechanisms to make sure they
+# all work.
+
+$loaded = true