Move r8 assistant runtime files to seperate module.

Ensure that these files are exactly the javac generated versions in
r8lib by copying them in after r8 has compiled r8lib

Bug: b/393265921
Change-Id: If77bca03fea938a020200d5d87c511cf6584fec0
diff --git a/tools/create_r8lib.py b/tools/create_r8lib.py
index 2935a02..1c349e1 100755
--- a/tools/create_r8lib.py
+++ b/tools/create_r8lib.py
@@ -6,7 +6,9 @@
 import argparse
 import os
 import subprocess
+import shutil
 import sys
+import zipfile
 
 import jdk
 import utils
@@ -30,6 +32,9 @@
                         action='store_true',
                         default=False,
                         help='Create a socket for debugging')
+    parser.add_argument('--replace-from-jar',
+                        default=None,
+                        help='Replace output jar with classes from this jar.')
     parser.add_argument(
         '--excldeps-variant',
         action='store_true',
@@ -78,6 +83,26 @@
         else:
             return output
 
+def replace_in_jar(r8jar, replace_from):
+    with utils.TempDir() as temp:
+        result = os.path.join(temp, 'result.jar')
+        skip_from_r8jar = set()
+        with zipfile.ZipFile(result, 'w') as output_file:
+            with zipfile.ZipFile(replace_from, 'r') as input_file:
+                for zipinfo in input_file.infolist():
+                    if zipinfo.filename.endswith('.class'):
+                        data = input_file.read(zipinfo)
+                        zipinfo.date_time = (1980, 1, 1, 0, 0, 0)
+                        output_file.writestr(zipinfo, data)
+                        skip_from_r8jar.add(zipinfo.filename)
+                    else:
+                        assert (zipinfo.filename == 'META-INF/MANIFEST.MF' or
+                                zipinfo.is_dir())
+            with zipfile.ZipFile(r8jar, 'r') as input_file:
+                for zipinfo in input_file.infolist():
+                    if not zipinfo.filename in skip_from_r8jar:
+                        output_file.writestr(zipinfo, input_file.read(zipinfo))
+        shutil.copyfile(result, r8jar)
 
 def main():
     args = parse_options()
@@ -123,7 +148,8 @@
         cmd.extend(['--pg-map', args.pg_map])
     print(' '.join(cmd))
     subprocess.check_call(cmd)
-
+    if args.replace_from_jar:
+        replace_in_jar(args.output, args.replace_from_jar)
 
 if __name__ == '__main__':
     sys.exit(main())