Add Kotlin 2.1.10 as the primary Kotlin compiler for testing

* Replace Kotlin compiler 2.1.0-Beta1 with 2.1.10
* Move Koltin 2.0.20 to run on the kotlin-old bot
* Add downloading of Kotlin stable to Kotlin compiler download
  script

Change-Id: I80359f0d1511d2c31ee7a1ba88627e30f5073fe6
diff --git a/.gitignore b/.gitignore
index 71a8778..20e754d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -168,8 +168,8 @@
 third_party/kotlin/kotlin-compiler-1.9.21
 third_party/kotlin/kotlin-compiler-2.0.20.tar.gz
 third_party/kotlin/kotlin-compiler-2.0.20
-third_party/kotlin/kotlin-compiler-2.1.0-Beta1
-third_party/kotlin/kotlin-compiler-2.1.0-Beta1.tar.gz
+third_party/kotlin/kotlin-compiler-2.1.10
+third_party/kotlin/kotlin-compiler-2.1.10.tar.gz
 third_party/kotlin/kotlin-compiler-dev.tar.gz
 third_party/kotlin/kotlin-compiler-dev
 third_party/kotlinx-coroutines-1.3.6.tar.gz
diff --git a/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt b/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt
index 6a55c49..eab8ce4 100644
--- a/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt
+++ b/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt
@@ -1101,7 +1101,7 @@
       "kotlin-compiler-1.8.0",
       "kotlin-compiler-1.9.21",
       "kotlin-compiler-2.0.20",
-      "kotlin-compiler-2.1.0-Beta1",
+      "kotlin-compiler-2.1.10",
       "kotlin-compiler-dev",
     )
     .map {
diff --git a/src/test/java/com/android/tools/r8/kotlin/KotlinClassInlinerTest.java b/src/test/java/com/android/tools/r8/kotlin/KotlinClassInlinerTest.java
index 10ce745..471e37f 100644
--- a/src/test/java/com/android/tools/r8/kotlin/KotlinClassInlinerTest.java
+++ b/src/test/java/com/android/tools/r8/kotlin/KotlinClassInlinerTest.java
@@ -9,7 +9,7 @@
 import static com.android.tools.r8.KotlinCompilerTool.KotlinCompilerVersion.KOTLINC_1_6_0;
 import static com.android.tools.r8.KotlinCompilerTool.KotlinCompilerVersion.KOTLINC_1_9_21;
 import static com.android.tools.r8.KotlinCompilerTool.KotlinCompilerVersion.KOTLINC_2_0_20;
-import static com.android.tools.r8.KotlinCompilerTool.KotlinCompilerVersion.KOTLINC_2_1_0_BETA1;
+import static com.android.tools.r8.KotlinCompilerTool.KotlinCompilerVersion.KOTLINC_2_1_10;
 import static com.android.tools.r8.utils.codeinspector.Matchers.isAbsent;
 import static com.android.tools.r8.utils.codeinspector.Matchers.isAbsentIf;
 import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
@@ -224,7 +224,7 @@
                                     kotlinParameters
                                         .getCompiler()
                                         .getCompilerVersion()
-                                        .isGreaterThanOrEqualTo(KOTLINC_2_1_0_BETA1),
+                                        .isGreaterThanOrEqualTo(KOTLINC_2_1_10),
                                     i -> {
                                       ClassReference sequencesKt =
                                           Reference.classFromTypeName(
diff --git a/src/test/testbase/java/com/android/tools/r8/KotlinCompilerTool.java b/src/test/testbase/java/com/android/tools/r8/KotlinCompilerTool.java
index 996d362..f1945ef 100644
--- a/src/test/testbase/java/com/android/tools/r8/KotlinCompilerTool.java
+++ b/src/test/testbase/java/com/android/tools/r8/KotlinCompilerTool.java
@@ -78,15 +78,13 @@
     KOTLINC_1_8_0("kotlin-compiler-1.8.0", KotlinLambdaGeneration.CLASS),
     KOTLINC_1_9_21("kotlin-compiler-1.9.21", KotlinLambdaGeneration.CLASS),
     KOTLINC_2_0_20("kotlin-compiler-2.0.20", KotlinLambdaGeneration.INVOKE_DYNAMIC),
-    KOTLINC_2_1_0_BETA1("kotlin-compiler-2.1.0-Beta1", KotlinLambdaGeneration.INVOKE_DYNAMIC),
+    KOTLINC_2_1_10("kotlin-compiler-2.1.10", KotlinLambdaGeneration.INVOKE_DYNAMIC),
     KOTLIN_DEV("kotlin-compiler-dev", KotlinLambdaGeneration.INVOKE_DYNAMIC);
 
-    public static final KotlinCompilerVersion MIN_SUPPORTED_VERSION = KOTLINC_2_0_20;
-    public static final KotlinCompilerVersion MAX_SUPPORTED_VERSION = KOTLINC_2_0_20;
+    public static final KotlinCompilerVersion MIN_SUPPORTED_VERSION = KOTLINC_2_1_10;
+    public static final KotlinCompilerVersion MAX_SUPPORTED_VERSION = KOTLINC_2_1_10;
     public static final KotlinCompilerVersion[] DEV_COMPILERS =
-        new KotlinCompilerVersion[] {
-          KotlinCompilerVersion.KOTLINC_2_1_0_BETA1, KotlinCompilerVersion.KOTLIN_DEV
-        };
+        new KotlinCompilerVersion[] {KotlinCompilerVersion.KOTLIN_DEV};
 
     private final String folder;
     private final KotlinLambdaGeneration defaultLambdaGeneration;
diff --git a/third_party/kotlin/kotlin-compiler-2.1.0-Beta1.tar.gz.sha1 b/third_party/kotlin/kotlin-compiler-2.1.0-Beta1.tar.gz.sha1
deleted file mode 100644
index 3f0f592..0000000
--- a/third_party/kotlin/kotlin-compiler-2.1.0-Beta1.tar.gz.sha1
+++ /dev/null
@@ -1 +0,0 @@
-491ee600cbb5b7febfd1ca4bda0d97e5d14aa370
\ No newline at end of file
diff --git a/third_party/kotlin/kotlin-compiler-2.1.10.tar.gz.sha1 b/third_party/kotlin/kotlin-compiler-2.1.10.tar.gz.sha1
new file mode 100644
index 0000000..0b4047b
--- /dev/null
+++ b/third_party/kotlin/kotlin-compiler-2.1.10.tar.gz.sha1
@@ -0,0 +1 @@
+5ebb0481921f7068daee3f7306ca6d3d17b40290
\ No newline at end of file
diff --git a/tools/download_kotlin_dev.py b/tools/download_kotlin.py
similarity index 72%
rename from tools/download_kotlin_dev.py
rename to tools/download_kotlin.py
index f51a2a1..91707895 100755
--- a/tools/download_kotlin_dev.py
+++ b/tools/download_kotlin.py
@@ -3,26 +3,60 @@
 # for details. All rights reserved. Use of this source code is governed by a
 # BSD-style license that can be found in the LICENSE file.
 
+import argparse
 import utils
-if utils.is_python3():
-    from html.parser import HTMLParser
-    import urllib.request
-    url_request = urllib.request
-else:
-    from HTMLParser import HTMLParser
-    import urllib
-    url_request = urllib
+from html.parser import HTMLParser
+import urllib.request
 import os
+import subprocess
 import sys
 import xml.etree.ElementTree
 
 
+JETBRAINS_KOTLIN_STABLE_URL = "https://github.com/JetBrains/kotlin/releases/download"
 JETBRAINS_KOTLIN_MAVEN_URL = "https://maven.pkg.jetbrains.space/kotlin/p/" \
                              "kotlin/bootstrap/org/jetbrains/kotlin/"
 KOTLIN_RELEASE_URL = JETBRAINS_KOTLIN_MAVEN_URL + "kotlin-compiler/"
 KOTLINC_LIB = os.path.join(utils.THIRD_PARTY, "kotlin",
                    "kotlin-compiler-dev", "kotlinc", "lib")
 
+def ParseOptions(args):
+    parser = argparse.ArgumentParser(description='Update third_party Kotlin')
+    parser.add_argument(
+        '--version',
+        required=True,
+        help="The Kotlin version, use 'dev' for the latest dev compiler")
+    return parser.parse_args()
+
+def download_stable(version):
+    with utils.TempDir() as temp:
+        unzip_dir = os.path.join(
+            utils.THIRD_PARTY,
+            'kotlin',
+            'kotlin-compiler-{version}'.format(version=version))
+        if os.path.exists(unzip_dir):
+            print('Destination dir {dir} exists. Please remove and retry.'.format(dir=unzip_dir))
+            sys.exit(-1)
+        url = (
+            '{download_url_base}/v{version}/kotlin-compiler-{version}.zip'
+                .format(download_url_base=JETBRAINS_KOTLIN_STABLE_URL, version=version))
+        kotlin_compiler_download_zip = os.path.join(temp, 'kotlin-compiler.zip')
+        download_and_save(url, kotlin_compiler_download_zip)
+        cmd = ['unzip', '-q', kotlin_compiler_download_zip, '-d', unzip_dir]
+        subprocess.check_call(cmd)
+        with open(os.path.join(unzip_dir, 'README.google'), 'w') as readme:
+            readme.write('Name: Kotlin\n')
+            readme.write('URL: {url}\n'.format(url=url))
+            readme.write('Version: {version}\n'.format(version=version))
+            readme.write('Revision: NA\n')
+            readme.write('License: Apache License Version 2.0\n')
+    print('If you want to upload this run:')
+    print('  (cd {dir}; upload_to_google_storage.py -a --bucket r8-deps {file})'
+        .format(dir=os.path.dirname(unzip_dir), file=os.path.basename(unzip_dir)))
+
+
+
+
 
 def download_newest():
     response = url_request.urlopen(KOTLIN_RELEASE_URL)
@@ -133,9 +167,22 @@
 
 
 def download_and_save(url, path, name):
-    print('Downloading: ' + url)
-    url_request.urlretrieve(url, os.path.join(path, name))
+    download_and_save(url, dest)
+
+
+def download_and_save(url, dest):
+    print('Downloading: ' + url + ' to: ' + dest)
+    urllib.request.urlretrieve(url, dest)
+
+
+def main(args):
+    options = ParseOptions(args)
+    print(options.version)
+    if options.version == 'dev':
+        download_newest()
+    else:
+        download_stable(options.version)
 
 
 if __name__ == '__main__':
-    sys.exit(download_newest())
+    sys.exit(main(sys.argv[1:]))
diff --git a/tools/test.py b/tools/test.py
index 666f627..8dc8b32 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -16,7 +16,7 @@
 import uuid
 
 import archive_desugar_jdk_libs
-import download_kotlin_dev
+import download_kotlin
 import gradle
 import notify
 import testing_state
@@ -447,7 +447,7 @@
         gradle_args.append('-Pkotlin_compiler_old')
     if options.kotlin_compiler_dev:
         gradle_args.append('-Pkotlin_compiler_dev')
-        download_kotlin_dev.download_newest()
+        download_kotlin.download_newest()
     if os.name == 'nt':
         gradle_args.append('-Pno_internal')
     if options.test_dir: