Merge commit 'e83c378efcc0fda820bed2540854ae3a6bfa8af7' into dev-release
diff --git a/tools/test.py b/tools/test.py
index 0e3bf0f..55dbac0 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -198,17 +198,40 @@
                     default=False, action='store_true')
   return result.parse_args()
 
+def has_failures(classes_file):
+  with open(classes_file) as f:
+    contents = f.read()
+    # The report has a div tag with the percentage of tests that succeeded.
+    assert '<div class="percent">' in contents
+    return '<div class="percent">100%</div>' not in contents
+
+def should_upload(filename, absolute_filename):
+  # filename is relative to REPO_ROOT/build/reports/tests
+  if filename.startswith('test/packages'):
+    # We don't upload the package overview
+    return False
+  if filename.startswith('test/classes'):
+    return has_failures(absolute_filename)
+  # Always upload index, css and js
+  return True
+
 def archive_failures(options):
   upload_dir = os.path.join(utils.REPO_ROOT, 'build', 'reports', 'tests')
   file_name = options.archive_failures_file_name
-  destination = 'gs://%s/%s' % (BUCKET, file_name)
-  utils.upload_dir_to_cloud_storage(upload_dir, destination, is_html=True)
+  destination_dir = 'gs://%s/%s/' % (BUCKET, file_name)
+  for (dir_path, dir_names, file_names) in os.walk(upload_dir):
+    for f in file_names:
+      absolute_file = os.path.join(dir_path, f)
+      relative_file = absolute_file[len(upload_dir)+1:]
+      if (should_upload(relative_file, absolute_file)):
+        utils.upload_file_to_cloud_storage(absolute_file,
+                                           destination_dir + relative_file,
+                                           public_read=False)
   url = 'https://storage.googleapis.com/%s/%s/test/index.html' % (BUCKET, file_name)
   print('Test results available at: %s' % url)
 
 def Main():
   (options, args) = ParseOptions()
-
   if utils.is_bot():
     gradle.RunGradle(['--no-daemon', 'clean'])
     print('Running with python ' + str(sys.version_info))
diff --git a/tools/utils.py b/tools/utils.py
index 9e837c3..6bab90b 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -343,18 +343,12 @@
   cmd = [get_gsutil(), '-m', 'cp']
   if is_html:
     cmd += ['-z', 'html']
-  if public_read:
-    # TODO(b/177799191) Temporarily disable public-read to test uniform access control
-    if 'r8-test-results' not in destination:
-      cmd += ['-a', 'public-read']
   cmd += ['-R', directory, destination]
   PrintCmd(cmd)
   subprocess.check_call(cmd)
 
 def upload_file_to_cloud_storage(source, destination, public_read=True):
   cmd = [get_gsutil(), 'cp']
-  if public_read:
-    cmd += ['-a', 'public-read']
   cmd += [source, destination]
   PrintCmd(cmd)
   subprocess.check_call(cmd)