Add an option to the art script to not cleanup.

Use it for jdwp tests, where the debuggee shouldn't clean up
the oat files generated by the debugger.

Test: run-jdwp-tests
Change-Id: I2f4c2066fac18c2cedb2b72d13186db4a8807e05
diff --git a/tools/art b/tools/art
index dea7ebd..15993dd 100644
--- a/tools/art
+++ b/tools/art
@@ -23,6 +23,7 @@
 LIBART=libart.so
 JIT_PROFILE="no"
 VERBOSE="no"
+CLEAN_OAT_FILES="yes"
 EXTRA_OPTIONS=()
 
 # Follow all sym links to get the program name.
@@ -87,6 +88,7 @@
                            report upon completion.
   --profile                Run with profiling, then run using profile data.
   --verbose                Run script verbosely.
+  --no-clean               Don't cleanup oat directories.
 
 The ART_OPTIONS are passed directly to the Android Runtime.
 
@@ -176,12 +178,14 @@
 # Input: Command line arguments to the art script.
 # e.g. -cp foo/classes.dex:bar/classes.dex would delete (foo/oat bar/oat) directories.
 cleanup_oat_directory_for_classpath() {
-  # First try: Use $CLASSPATH environment variable.
-  parse_classpath "$CLASSPATH"
-  # Second try: Look for latest -cp or -classpath arg which will take precedence.
-  find_cp_in_args "$@"
+  if [ "$CLEAN_OAT_FILES" = "yes" ]; then
+    # First try: Use $CLASSPATH environment variable.
+    parse_classpath "$CLASSPATH"
+    # Second try: Look for latest -cp or -classpath arg which will take precedence.
+    find_cp_in_args "$@"
 
-  cleanup_oat_directory "${PARSE_CLASSPATH_RESULT[@]}"
+    cleanup_oat_directory "${PARSE_CLASSPATH_RESULT[@]}"
+  fi
 }
 
 # Attempt to find $ANDROID_ROOT/framework/<isa>/core.art' without knowing what <isa> is.
@@ -291,6 +295,9 @@
   --verbose)
     VERBOSE="yes"
     ;;
+  --no-clean)
+    CLEAN_OAT_FILES="no"
+    ;;
   --*)
     echo "unknown option: $1" 1>&2
     usage
diff --git a/tools/run-jdwp-tests.sh b/tools/run-jdwp-tests.sh
index d2322bb..355646b 100755
--- a/tools/run-jdwp-tests.sh
+++ b/tools/run-jdwp-tests.sh
@@ -122,6 +122,9 @@
   fi
 done
 
+# Make sure the debuggee doesn't clean up what the debugger has generated.
+art_debugee="$art_debugee --no-clean"
+
 # For the host:
 #
 # If, on the other hand, there is a variant set, use it to modify the art_debugee parameter to