art script: generate app image for profile filters

We recently started requiring app images to load an OAT file that was
compiled using --compiler-filter=speed-profile or
--compiler-filter=everything-profile.  The CL that introduced this
behavior change is https://r.android.com/1290475

Unfortunately, this led to large regressions in Golem because we were
not generating app images there. This change adjusts the art script to
generate app images when the compiler filter is speed-profile or
everything-profile, which should fix the regressions.

Bug: 38313278
Test: Run CaffeineFloat, observe that performance improves
Change-Id: I020d451bc6f3ea4399bc39157398eb35929bfddd
diff --git a/tools/art b/tools/art
index 6175992..3b03552 100644
--- a/tools/art
+++ b/tools/art
@@ -195,6 +195,12 @@
     verbose_run mkdir -p $(dirname "$dex_file")/oat/$ISA
     local oat_file=$(basename "$dex_file")
     local oat_file=$(dirname "$dex_file")/oat/$ISA/${oat_file%.*}.odex
+    if [ "$GENERATE_APP_IMAGE" = "yes" ]; then
+      local art_file=$(basename "$dex_file")
+      local art_file=$(dirname "$dex_file")/oat/$ISA/${art_file%.*}.art
+      DEX2OAT_FLAGS+=("--app-image-file=$art_file")
+    fi
+
     # When running dex2oat use the exact same context as when running dalvikvm.
     # (see run_art function)
     verbose_run ANDROID_DATA=$ANDROID_DATA                    \
@@ -232,6 +238,17 @@
     case $1 in
       -Xcompiler-option)
         DEX2OAT_FLAGS+=("$2")
+
+        # Enable app images for profile filters
+        case $2 in
+          --compiler-filter=speed-profile)
+            GENERATE_APP_IMAGE="yes"
+            ;;
+          --compiler-filter=everything-profile)
+            GENERATE_APP_IMAGE="yes"
+            ;;
+        esac
+
         shift
         ;;
       -Ximage:*)
@@ -314,6 +331,7 @@
 EXTRA_OPTIONS=()
 DEX2OAT_FLAGS=()
 DEX2OAT_CLASSPATH=()
+GENERATE_APP_IMAGE="no"
 
 # Parse arguments
 while [[ "$1" = "-"* ]]; do