Yohann Roussel | 50d8b23 | 2017-09-07 16:28:44 +0200 | [diff] [blame] | 1 | // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | package com.android.tools.r8; |
| 6 | |
Yohann Roussel | 73f58e1 | 2017-10-13 17:33:14 +0200 | [diff] [blame] | 7 | import com.android.tools.r8.utils.VersionProperties; |
Yohann Roussel | 73f58e1 | 2017-10-13 17:33:14 +0200 | [diff] [blame] | 8 | |
Ian Zerny | 850f13d | 2018-01-04 11:25:38 +0100 | [diff] [blame] | 9 | /** Version of the D8/R8 library. */ |
Yohann Roussel | 50d8b23 | 2017-09-07 16:28:44 +0200 | [diff] [blame] | 10 | public final class Version { |
| 11 | |
Søren Gjesse | 5de6d7d | 2023-02-10 12:37:19 +0100 | [diff] [blame] | 12 | private static final String MAIN_LABEL = "main"; |
| 13 | |
Mads Ager | a4911eb | 2017-11-22 13:19:36 +0100 | [diff] [blame] | 14 | // This field is accessed from release scripts using simple pattern matching. |
| 15 | // Therefore, changing this field could break our release scripts. |
Christoffer Adamsen | d4ff5ea | 2024-05-30 17:19:42 +0200 | [diff] [blame^] | 16 | public static final String LABEL = "8.3.47"; |
Yohann Roussel | 50d8b23 | 2017-09-07 16:28:44 +0200 | [diff] [blame] | 17 | |
| 18 | private Version() { |
| 19 | } |
Yohann Roussel | 73f58e1 | 2017-10-13 17:33:14 +0200 | [diff] [blame] | 20 | |
Ian Zerny | a7d828b | 2019-11-26 15:37:37 +0100 | [diff] [blame] | 21 | /** Returns current R8 version (with additional info) as a string. */ |
| 22 | public static String getVersionString() { |
| 23 | return LABEL + " (" + VersionProperties.INSTANCE.getDescription() + ")"; |
Yohann Roussel | d5e7a5e | 2017-11-10 17:01:35 +0100 | [diff] [blame] | 24 | } |
Yohann Roussel | 73f58e1 | 2017-10-13 17:33:14 +0200 | [diff] [blame] | 25 | |
Ian Zerny | a7d828b | 2019-11-26 15:37:37 +0100 | [diff] [blame] | 26 | /** |
| 27 | * Returns the major version number of the compiler. |
| 28 | * |
| 29 | * @return Major version or -1 for an unreleased build. |
| 30 | */ |
| 31 | public static int getMajorVersion() { |
Søren Gjesse | 9a4ecac | 2019-11-27 17:55:26 +0100 | [diff] [blame] | 32 | return getMajorVersion(LABEL); |
| 33 | } |
| 34 | |
| 35 | static int getMajorVersion(String label) { |
Søren Gjesse | 5de6d7d | 2023-02-10 12:37:19 +0100 | [diff] [blame] | 36 | if (label.equals(MAIN_LABEL)) { |
Ian Zerny | a7d828b | 2019-11-26 15:37:37 +0100 | [diff] [blame] | 37 | return -1; |
| 38 | } |
| 39 | int start = 0; |
Søren Gjesse | 9a4ecac | 2019-11-27 17:55:26 +0100 | [diff] [blame] | 40 | int end = label.indexOf('.'); |
| 41 | return Integer.parseInt(label.substring(start, end)); |
Ian Zerny | a7d828b | 2019-11-26 15:37:37 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns the minor version number of the compiler. |
| 46 | * |
| 47 | * @return Minor version or -1 for an unreleased build. |
| 48 | */ |
| 49 | public static int getMinorVersion() { |
Søren Gjesse | 9a4ecac | 2019-11-27 17:55:26 +0100 | [diff] [blame] | 50 | return getMinorVersion(LABEL); |
| 51 | } |
| 52 | |
| 53 | static int getMinorVersion(String label) { |
Søren Gjesse | 5de6d7d | 2023-02-10 12:37:19 +0100 | [diff] [blame] | 54 | if (label.equals(MAIN_LABEL)) { |
Ian Zerny | a7d828b | 2019-11-26 15:37:37 +0100 | [diff] [blame] | 55 | return -1; |
| 56 | } |
Søren Gjesse | 9a4ecac | 2019-11-27 17:55:26 +0100 | [diff] [blame] | 57 | int start = label.indexOf('.') + 1; |
| 58 | int end = label.indexOf('.', start); |
| 59 | return Integer.parseInt(label.substring(start, end)); |
Ian Zerny | a7d828b | 2019-11-26 15:37:37 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns the patch version number of the compiler. |
| 64 | * |
| 65 | * @return Patch version or -1 for an unreleased build. |
| 66 | */ |
| 67 | public static int getPatchVersion() { |
Søren Gjesse | 9a4ecac | 2019-11-27 17:55:26 +0100 | [diff] [blame] | 68 | return getPatchVersion(LABEL); |
| 69 | } |
| 70 | |
| 71 | static int getPatchVersion(String label) { |
Søren Gjesse | 5de6d7d | 2023-02-10 12:37:19 +0100 | [diff] [blame] | 72 | if (label.equals(MAIN_LABEL)) { |
Ian Zerny | a7d828b | 2019-11-26 15:37:37 +0100 | [diff] [blame] | 73 | return -1; |
| 74 | } |
Søren Gjesse | 9a4ecac | 2019-11-27 17:55:26 +0100 | [diff] [blame] | 75 | int skip = label.indexOf('.') + 1; |
| 76 | int start = label.indexOf('.', skip) + 1; |
| 77 | int end = label.indexOf('-', start); |
| 78 | return Integer.parseInt(label.substring(start, end != -1 ? end : label.length())); |
Ian Zerny | a7d828b | 2019-11-26 15:37:37 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns the pre-release version information of the compiler. |
| 83 | * |
| 84 | * @return Pre-release information if present, the empty string if absent, and null for an |
| 85 | * unreleased build. |
| 86 | */ |
| 87 | public static String getPreReleaseString() { |
Søren Gjesse | 9a4ecac | 2019-11-27 17:55:26 +0100 | [diff] [blame] | 88 | return getPreReleaseString(LABEL); |
| 89 | } |
| 90 | |
| 91 | static String getPreReleaseString(String label) { |
Søren Gjesse | 5de6d7d | 2023-02-10 12:37:19 +0100 | [diff] [blame] | 92 | if (label.equals(MAIN_LABEL)) { |
Ian Zerny | a7d828b | 2019-11-26 15:37:37 +0100 | [diff] [blame] | 93 | return null; |
| 94 | } |
Søren Gjesse | 9a4ecac | 2019-11-27 17:55:26 +0100 | [diff] [blame] | 95 | int start = label.indexOf('-') + 1; |
Ian Zerny | a7d828b | 2019-11-26 15:37:37 +0100 | [diff] [blame] | 96 | if (start > 0) { |
Søren Gjesse | 9a4ecac | 2019-11-27 17:55:26 +0100 | [diff] [blame] | 97 | return label.substring(start); |
Ian Zerny | a7d828b | 2019-11-26 15:37:37 +0100 | [diff] [blame] | 98 | } |
| 99 | return ""; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Is this a development version of the D8/R8 library. |
| 104 | * |
| 105 | * @return True if the build is not a release or if it is a development release. |
| 106 | */ |
| 107 | public static boolean isDevelopmentVersion() { |
Søren Gjesse | 9a4ecac | 2019-11-27 17:55:26 +0100 | [diff] [blame] | 108 | return isDevelopmentVersion(LABEL, VersionProperties.INSTANCE.isEngineering()); |
| 109 | } |
| 110 | |
| 111 | static boolean isDevelopmentVersion(String label, boolean isEngineering) { |
Søren Gjesse | 5de6d7d | 2023-02-10 12:37:19 +0100 | [diff] [blame] | 112 | return label.equals(MAIN_LABEL) || label.endsWith("-dev") || isEngineering; |
| 113 | } |
| 114 | |
| 115 | public static boolean isMainVersion() { |
| 116 | return LABEL.equals(MAIN_LABEL); |
Yohann Roussel | 73f58e1 | 2017-10-13 17:33:14 +0200 | [diff] [blame] | 117 | } |
Yohann Roussel | 50d8b23 | 2017-09-07 16:28:44 +0200 | [diff] [blame] | 118 | } |