Update release script to copy R8 SBOM.

Fixes: b/280466318
Change-Id: I2e1ba01d6c77bccf18bb0448be0243561c067a36
diff --git a/tools/update_prebuilds_in_android.py b/tools/update_prebuilds_in_android.py
index 31ee23e..623bacd 100755
--- a/tools/update_prebuilds_in_android.py
+++ b/tools/update_prebuilds_in_android.py
@@ -16,7 +16,8 @@
     'lib': [(utils.R8LIB, 'r8'),],
 }
 
-OTHER_TARGETS = ["LICENSE"]
+OTHER_TARGETS = ['LICENSE']
+SBOM_TARGETS = ['r8.spdx.json']
 KEEPANNO_JAR = 'keepanno-annotations.jar'
 
 
@@ -65,7 +66,7 @@
                 print('Copying: ' + src + '.map -> ' + dest + '.map')
                 copyfile(src + '.map', dest + '.map')
         else:
-            print('WARNING: Not copying ' + src + ' -> ' + dest + ', as' +
+            print('WARNING: Not copying ' + src + ' -> ' + dest + ', as ' +
                   dest + ' does not exist already')
 
 
@@ -75,8 +76,8 @@
     copy_targets(root, target_root, srcs, dests, maps=maps)
 
 
-def copy_other_targets(root, target_root):
-    copy_targets(root, target_root, OTHER_TARGETS, OTHER_TARGETS)
+def copy_other_targets(root, target_root, other_targets):
+    copy_targets(root, target_root, other_targets, other_targets)
 
 
 def download_hash(root, commit_hash, target, quiet=False):
@@ -96,9 +97,16 @@
 
 
 def main_download(hash, maps, targets, target_root, version, keepanno=False):
+    sbom_targets = []
+    if version:
+        semver = utils.check_basic_semver_version(version, allowPrerelease=True)
+        # Generation of SBOM started from version 8.3.13-dev.
+        if semver.larger_than(utils.SemanticVersion(8, 3, 12, 'dev')):
+            sbom_targets = SBOM_TARGETS
+
     jar_targets = JAR_TARGETS_MAP[targets]
     final_targets = list(map(
-        (lambda t: t[0] + '.jar'), jar_targets)) + OTHER_TARGETS
+        (lambda t: t[0] + '.jar'), jar_targets)) + OTHER_TARGETS + sbom_targets
     with utils.TempDir() as root:
         for target in final_targets:
             if hash:
@@ -110,12 +118,12 @@
             else:
                 assert version
                 download_version(root, version, target)
-                if maps and target not in OTHER_TARGETS:
+                if maps and target not in (OTHER_TARGETS + sbom_targets):
                     download_version(root, version, target + '.map')
                 if keepanno:
                     download_version(root, version, KEEPANNO_JAR)
         copy_jar_targets(root, target_root, jar_targets, maps)
-        copy_other_targets(root, target_root)
+        copy_other_targets(root, target_root, OTHER_TARGETS + sbom_targets)
         if keepanno:
             copy_targets(root, target_root, [KEEPANNO_JAR], [KEEPANNO_JAR])
 
@@ -129,7 +137,7 @@
         gradle_args.append('-Dorg.gradle.jvmargs=-Xmx' + max_memory_size)
     gradle.RunGradle(gradle_args)
     copy_jar_targets(utils.LIBS, target_root, jar_targets, maps)
-    copy_other_targets(utils.GENERATED_LICENSE_DIR, target_root)
+    copy_other_targets(utils.GENERATED_LICENSE_DIR, target_root, OTHER_TARGETS)
 
 
 def main(args):
diff --git a/tools/utils.py b/tools/utils.py
index db9844e..06fc3a7 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -720,8 +720,6 @@
         # Build metadata currently not suppported
 
     def larger_than(self, other):
-        if self.prerelease or other.prerelease:
-            raise Exception("Comparison with prerelease not implemented")
         if self.major > other.major:
             return True
         if self.major == other.major and self.minor > other.minor:
@@ -729,6 +727,12 @@
         if self.patch:
             return (self.major == other.major and self.minor == other.minor and
                     self.patch > other.patch)
+        if self.prerelease:
+            if other.prerelease:
+                return self.prerelease > other.prerelease
+            else:
+                return False
+
         else:
             return False