Add --worktree flag to test.py to use a local gradle_user_home

Change-Id: Ibfe68bdaa5b84cea257e2603e78b5a75d1fe69f8
diff --git a/.gitignore b/.gitignore
index b74632a..bc99d6a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
 buildSrc/out/
 .idea/
 .gradle/
+.gradle_user_home
 android-data*/
 tests/2016-12-19/art.tar.gz
 tests/2016-12-19/art
diff --git a/tools/test.py b/tools/test.py
index 2d45d1c..5091f61 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -128,6 +128,9 @@
   result.add_option('--fail-fast', '--fail_fast',
       default=False, action='store_true',
       help='Stop on first failure. Passes --fail-fast to gradle test runner.')
+  result.add_option('--worktree',
+      default=False, action='store_true',
+      help='Tests are run in worktree and should not use gradle user home.')
   return result.parse_args()
 
 def archive_failures():
@@ -215,6 +218,8 @@
     gradle_args.append('R8LibNoDeps')
   if options.r8lib_no_deps:
     gradle_args.append('-Pr8lib_no_deps')
+  if options.worktree:
+    gradle_args.append('-g=' + os.path.join(utils.REPO_ROOT, ".gradle_user_home"))
 
   # Build an R8 with dependencies for bootstrapping tests before adding test sources.
   gradle_args.append('r8WithRelocatedDeps')