blob: 6a9b575eaedd2f553e791425f3e4f3dcdb7d4a71 [file] [log] [blame]
Yohann Roussel50d8b232017-09-07 16:28:44 +02001// 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
5package com.android.tools.r8;
6
Yohann Roussel73f58e12017-10-13 17:33:14 +02007import com.android.tools.r8.utils.VersionProperties;
Yohann Roussel73f58e12017-10-13 17:33:14 +02008
Ian Zerny850f13d2018-01-04 11:25:38 +01009/** Version of the D8/R8 library. */
Yohann Roussel50d8b232017-09-07 16:28:44 +020010public final class Version {
11
Søren Gjesse5de6d7d2023-02-10 12:37:19 +010012 private static final String MAIN_LABEL = "main";
13
Mads Agera4911eb2017-11-22 13:19:36 +010014 // This field is accessed from release scripts using simple pattern matching.
15 // Therefore, changing this field could break our release scripts.
Christoffer Adamsend4ff5ea2024-05-30 17:19:42 +020016 public static final String LABEL = "8.3.47";
Yohann Roussel50d8b232017-09-07 16:28:44 +020017
18 private Version() {
19 }
Yohann Roussel73f58e12017-10-13 17:33:14 +020020
Ian Zernya7d828b2019-11-26 15:37:37 +010021 /** Returns current R8 version (with additional info) as a string. */
22 public static String getVersionString() {
23 return LABEL + " (" + VersionProperties.INSTANCE.getDescription() + ")";
Yohann Rousseld5e7a5e2017-11-10 17:01:35 +010024 }
Yohann Roussel73f58e12017-10-13 17:33:14 +020025
Ian Zernya7d828b2019-11-26 15:37:37 +010026 /**
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 Gjesse9a4ecac2019-11-27 17:55:26 +010032 return getMajorVersion(LABEL);
33 }
34
35 static int getMajorVersion(String label) {
Søren Gjesse5de6d7d2023-02-10 12:37:19 +010036 if (label.equals(MAIN_LABEL)) {
Ian Zernya7d828b2019-11-26 15:37:37 +010037 return -1;
38 }
39 int start = 0;
Søren Gjesse9a4ecac2019-11-27 17:55:26 +010040 int end = label.indexOf('.');
41 return Integer.parseInt(label.substring(start, end));
Ian Zernya7d828b2019-11-26 15:37:37 +010042 }
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 Gjesse9a4ecac2019-11-27 17:55:26 +010050 return getMinorVersion(LABEL);
51 }
52
53 static int getMinorVersion(String label) {
Søren Gjesse5de6d7d2023-02-10 12:37:19 +010054 if (label.equals(MAIN_LABEL)) {
Ian Zernya7d828b2019-11-26 15:37:37 +010055 return -1;
56 }
Søren Gjesse9a4ecac2019-11-27 17:55:26 +010057 int start = label.indexOf('.') + 1;
58 int end = label.indexOf('.', start);
59 return Integer.parseInt(label.substring(start, end));
Ian Zernya7d828b2019-11-26 15:37:37 +010060 }
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 Gjesse9a4ecac2019-11-27 17:55:26 +010068 return getPatchVersion(LABEL);
69 }
70
71 static int getPatchVersion(String label) {
Søren Gjesse5de6d7d2023-02-10 12:37:19 +010072 if (label.equals(MAIN_LABEL)) {
Ian Zernya7d828b2019-11-26 15:37:37 +010073 return -1;
74 }
Søren Gjesse9a4ecac2019-11-27 17:55:26 +010075 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 Zernya7d828b2019-11-26 15:37:37 +010079 }
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 Gjesse9a4ecac2019-11-27 17:55:26 +010088 return getPreReleaseString(LABEL);
89 }
90
91 static String getPreReleaseString(String label) {
Søren Gjesse5de6d7d2023-02-10 12:37:19 +010092 if (label.equals(MAIN_LABEL)) {
Ian Zernya7d828b2019-11-26 15:37:37 +010093 return null;
94 }
Søren Gjesse9a4ecac2019-11-27 17:55:26 +010095 int start = label.indexOf('-') + 1;
Ian Zernya7d828b2019-11-26 15:37:37 +010096 if (start > 0) {
Søren Gjesse9a4ecac2019-11-27 17:55:26 +010097 return label.substring(start);
Ian Zernya7d828b2019-11-26 15:37:37 +010098 }
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 Gjesse9a4ecac2019-11-27 17:55:26 +0100108 return isDevelopmentVersion(LABEL, VersionProperties.INSTANCE.isEngineering());
109 }
110
111 static boolean isDevelopmentVersion(String label, boolean isEngineering) {
Søren Gjesse5de6d7d2023-02-10 12:37:19 +0100112 return label.equals(MAIN_LABEL) || label.endsWith("-dev") || isEngineering;
113 }
114
115 public static boolean isMainVersion() {
116 return LABEL.equals(MAIN_LABEL);
Yohann Roussel73f58e12017-10-13 17:33:14 +0200117 }
Yohann Roussel50d8b232017-09-07 16:28:44 +0200118}