Make the run_on_app.py script dertimine additional output files

The output path of the Proguard map and Proguard seeds flies are
specified in the proguard configuration file. Change the script
tools/run_on_app.py to generate a temporary Proguard configuration
to direct the these two files to the same output location as the
dex files no matter what is in the input Proguard configuration.

R=ager@google.com, ricow@google.com

Change-Id: I27f27842e9a3a370dcb1f4deff91154b8d044e07
diff --git a/tools/run_on_app.py b/tools/run_on_app.py
index 966f786..4ad013a 100755
--- a/tools/run_on_app.py
+++ b/tools/run_on_app.py
@@ -8,6 +8,7 @@
 import r8
 import d8
 import sys
+import utils
 
 import gmscore_data
 import youtube_data
@@ -65,6 +66,17 @@
                     'the run.')
   return result.parse_args()
 
+# Most apps have the -printmapping and -printseeds in the Proguard
+# configuration. However we don't want to write these files in these
+# locations. Instead generate an auxiliary Proguard configuration
+# placing these two output files together with the dex output.
+def GenerateAdditionalProguardConfiguration(temp, outdir):
+  name = "output.config"
+  with open(os.path.join(temp, name), 'w') as file:
+    file.write('-printmapping ' + os.path.join(outdir, 'proguard.map') + "\n")
+    file.write('-printseeds ' + os.path.join(outdir, 'proguard.seeds') + "\n")
+    return os.path.abspath(file.name)
+
 def main():
   (options, args) = ParseOptions()
   outdir = options.out
@@ -133,8 +145,16 @@
       d8.run(args, not options.no_build, not options.no_debug, options.profile,
              options.track_memory_to_file)
     else:
-      r8.run(args, not options.no_build, not options.no_debug, options.profile,
-             options.track_memory_to_file)
+      with utils.TempDir() as temp:
+        if outdir.endswith('.zip') or outdir.endswith('.jar'):
+          pg_outdir = os.path.dirname(outdir)
+        else:
+          pg_outdir = outdir
+        additional_pg_conf = GenerateAdditionalProguardConfiguration(
+            temp, os.path.abspath(pg_outdir))
+        args.extend(['--pg-conf', additional_pg_conf])
+        r8.run(args, not options.no_build, not options.no_debug, options.profile,
+               options.track_memory_to_file)
 
 if __name__ == '__main__':
   sys.exit(main())