The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

gradle: Use our own groovy code to compute a version from git

git worktree is not supported by androidgitversion

This makes it work with git worktrees and submodules, unlike the
plugin we used before. Unlike some other gradle plugins,
this allows us to set our own filter for tags that get included in
the version.

Thanks to Tao Pei for noticing the problem and proposing an initial fix.

Co-authored-by: tao.pei <tao.pei@xjmz.com>
Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2204>

+59 -10
+1
doc/changes/misc_features/mr.676.md
··· 16 16 - mr.1377 17 17 - mr.1385 18 18 - mr.2232 19 + - mr.2204 19 20 --- 20 21 21 22 More improvements to the Android port.
+58 -10
src/xrt/targets/openxr_android/build.gradle
··· 1 - // Copyright 2020-2022, Collabora, Ltd. 1 + // Copyright 2020-2024, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 import groovy.xml.XmlUtil 4 4 ··· 8 8 9 9 id 'com.mikepenz.aboutlibraries.plugin' 10 10 11 - id "com.gladed.androidgitversion" 12 11 id "de.undercouch.download" 13 12 14 13 // Hilt dependency injection ··· 33 32 // Use ktfmt(https://github.com/facebook/ktfmt) as the default Kotlin formatter. 34 33 ktfmt('0.43').kotlinlangStyle() 35 34 } 36 - } 37 - 38 - androidGitVersion { 39 - tagPattern(/^v[0-9]+.*/) 40 - codeFormat = 'MMNPBBBBB' 41 - format = '%tag%%-count%%-gcommit%%-dirty%' 42 35 } 43 36 44 37 def parseOpenXRVersion(def fn) { ··· 97 90 unpackEigen.enabled = false 98 91 } 99 92 93 + // *** 94 + // Git version handling 95 + // *** 96 + 97 + // Supplied with major, minor, patch, commit count 98 + def versionCodeFormatPattern = "%02d%01d%01d%05d" 99 + 100 + // parsed using this regex 101 + def gitDescribePattern = ~/v(?<tag>(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+))-(?<commits>\d+)-g(?<hash>[0-9a-f]+)/ 102 + 103 + // Get the version code from git describe output 104 + def getVersionCode = { -> 105 + try { 106 + def stdout = new ByteArrayOutputStream() 107 + exec { 108 + commandLine 'git', 'describe', '--always', '--long', '--match', 'v*' 109 + standardOutput = stdout 110 + workingDir rootDir 111 + } 112 + def longOutput = stdout.toString().trim() 113 + def matcher = longOutput =~ gitDescribePattern 114 + if (!matcher.matches()) { 115 + println "Could not find an annotated git tag matching the regex!" 116 + return null 117 + } 118 + def codeAsString = String.format(versionCodeFormatPattern, 119 + Integer.parseInt(matcher.group('major')), 120 + Integer.parseInt(matcher.group('minor')), 121 + Integer.parseInt(matcher.group('patch')), 122 + Integer.parseInt(matcher.group('commits'))) 123 + return Integer.parseInt(codeAsString) 124 + } 125 + catch (ignored) { 126 + return null; 127 + } 128 + } 129 + 130 + // Get the version string from git describe output 131 + def getVersionString = { -> 132 + try { 133 + def stdout = new ByteArrayOutputStream() 134 + exec { 135 + commandLine 'git', 'describe', '--always', '--dirty', '--match', 'v*' 136 + standardOutput = stdout 137 + workingDir rootDir 138 + } 139 + return stdout.toString().trim() 140 + } 141 + catch (ignored) { 142 + return null; 143 + } 144 + } 145 + 146 + 100 147 // Pass -PsharedStl=true on the gradle command line to build with the shared runtime library. 101 148 // This has potential compatibility issues and should only be used if you're consuming another 102 149 // library that exposes a C++ interface. ··· 117 164 minSdkVersion project.sharedMinSdk 118 165 targetSdkVersion project.sharedTargetSdk 119 166 120 - versionCode androidGitVersion.code() 121 - versionName androidGitVersion.name() 167 + versionCode = getVersionCode() 168 + versionName = getVersionString() 122 169 123 170 println versionName 171 + println versionCode 124 172 125 173 resValue "string", "monado_lib_version", "${versionName}" 126 174