Add support for sharding tests

This allows you to specify the number of shards and the current shard to run when invoking test.py

Change-Id: I3981623c7cfc88d96178b615d9c4334c2a07a2ed
diff --git a/build.gradle b/build.gradle
index a247b4d..ac31d46 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1611,6 +1611,23 @@
     if (project.hasProperty('only_jctf')) {
         include "com/android/tools/r8/jctf/**"
     }
+    if (project.hasProperty('shard_count') ) {
+      assert project.hasProperty('shard_number')
+      int shard_count = project.getProperty('shard_count') as Integer
+      int shard_number = project.getProperty('shard_number') as Integer
+      assert shard_count < 65536
+      assert shard_number < shard_count
+      exclude {
+        entry ->
+          // Don't leave out directories. Leaving out a directory means all entries below.
+          if (entry.file.isDirectory()) {
+           return false
+          }
+          def first4 = entry.getRelativePath().toString().md5().substring(0, 4)
+          int hash = Integer.parseInt(first4, 16)
+          return hash % shard_count != shard_number
+      }
+    }
     if (project.hasProperty('jctf_compile_only')) {
         println "JCTF: compiling only"
         systemProperty 'jctf_compile_only', '1'