Merge "Add script for archiving gradle test logs"
diff --git a/tools/archive_logs.py b/tools/archive_logs.py
new file mode 100755
index 0000000..bdae32e
--- /dev/null
+++ b/tools/archive_logs.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+# Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+
+# Script for achiving gradle test logs.
+
+import utils
+
+if __name__ == '__main__':
+  utils.archive_failures()
diff --git a/tools/test.py b/tools/test.py
index 31b2134..9e287fb 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -13,13 +13,9 @@
 import subprocess
 import sys
 import utils
-import uuid
 import notify
-import upload_to_x20
-
 
 ALL_ART_VMS = ["default", "8.1.0", "7.0.0", "6.0.1", "5.1.1", "4.4.4", "4.0.4"]
-BUCKET = 'r8-test-results'
 
 def ParseOptions():
   result = optparse.OptionParser()
@@ -89,15 +85,6 @@
 
   return result.parse_args()
 
-def archive_failures():
-  upload_dir = os.path.join(utils.REPO_ROOT, 'build', 'reports', 'tests')
-  u_dir = uuid.uuid4()
-  destination = 'gs://%s/%s' % (BUCKET, u_dir)
-  utils.upload_dir_to_cloud_storage(upload_dir, destination, is_html=True)
-  url = 'http://storage.googleapis.com/%s/%s/test/index.html' % (BUCKET, u_dir)
-  print 'Test results available at: %s' % url
-  print '@@@STEP_LINK@Test failures@%s@@@' % url
-
 def Main():
   (options, args) = ParseOptions()
   if 'BUILDBOT_BUILDERNAME' in os.environ:
@@ -193,7 +180,7 @@
 
     if return_code != 0:
       if options.archive_failures and os.name != 'nt':
-        archive_failures()
+        utils.archive_failures()
       return return_code
 
   return 0
diff --git a/tools/utils.py b/tools/utils.py
index d28643d..282ddfa 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -12,6 +12,7 @@
 import sys
 import tarfile
 import tempfile
+import uuid
 
 ANDROID_JAR = 'third_party/android_jar/lib-v{api}/android.jar'
 TOOLS_DIR = os.path.abspath(os.path.normpath(os.path.join(__file__, '..')))
@@ -44,6 +45,8 @@
 RT_JAR = os.path.join(REPO_ROOT, 'third_party/openjdk/openjdk-rt-1.8/rt.jar')
 R8LIB_KEEP_RULES = os.path.join(REPO_ROOT, 'src/main/keep.txt')
 
+TEST_RESULT_BUCKET = 'r8-test-results'
+
 def PrintCmd(s):
   if type(s) is list:
     s = ' '.join(s)
@@ -180,6 +183,15 @@
  def __exit__(self, *_):
    shutil.rmtree(self._temp_dir, ignore_errors=True)
 
+def archive_failures():
+  upload_dir = os.path.join(REPO_ROOT, 'build', 'reports', 'tests')
+  u_dir = uuid.uuid4()
+  destination = 'gs://%s/%s' % (TEST_RESULT_BUCKET, u_dir)
+  upload_dir_to_cloud_storage(upload_dir, destination, is_html=True)
+  url = 'http://storage.googleapis.com/%s/%s/test/index.html' % (TEST_RESULT_BUCKET, u_dir)
+  print 'Test results available at: %s' % url
+  print '@@@STEP_LINK@Test failures@%s@@@' % url
+
 class ChangedWorkingDirectory(object):
  def __init__(self, working_directory):
    self._working_directory = working_directory