The open source OpenXR runtime
0
fork

Configure Feed

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

xrt: Add git tag/description

+377 -3
+4
CMakeLists.txt
··· 19 19 include(CMakeDependentOption) 20 20 include(SPIR-V) 21 21 include(GNUInstallDirs) 22 + include(GetGitRevisionDescription) 23 + git_describe(GIT_DESC "--always") 22 24 if(NOT ${CMAKE_VERSION} VERSION_LESS 3.9) 23 25 include(CheckIPOSupported) 24 26 check_ipo_supported(RESULT HAS_IPO) ··· 228 230 endif() 229 231 230 232 message(STATUS "#####----- Config -----#####") 233 + message(STATUS "# GIT_DESC: ${GIT_DESC}") 234 + message(STATUS "#") 231 235 message(STATUS "# WAYLAND: ${XRT_HAVE_WAYLAND}") 232 236 message(STATUS "# XLIB: ${XRT_HAVE_XLIB}") 233 237 message(STATUS "# XCB: ${XRT_HAVE_XCB}")
+279
cmake/GetGitRevisionDescription.cmake
··· 1 + # - Returns a version string from Git 2 + # 3 + # These functions force a re-configure on each git commit so that you can 4 + # trust the values of the variables in your build system. 5 + # 6 + # get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...]) 7 + # 8 + # Returns the refspec and sha hash of the current head revision 9 + # 10 + # git_describe(<var> [<additional arguments to git describe> ...]) 11 + # 12 + # Returns the results of git describe on the source tree, and adjusting 13 + # the output so that it tests false if an error occurs. 14 + # 15 + # git_describe_working_tree(<var> [<additional arguments to git describe> ...]) 16 + # 17 + # Returns the results of git describe on the working tree (--dirty option), 18 + # and adjusting the output so that it tests false if an error occurs. 19 + # 20 + # git_get_exact_tag(<var> [<additional arguments to git describe> ...]) 21 + # 22 + # Returns the results of git describe --exact-match on the source tree, 23 + # and adjusting the output so that it tests false if there was no exact 24 + # matching tag. 25 + # 26 + # git_local_changes(<var>) 27 + # 28 + # Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes. 29 + # Uses the return code of "git diff-index --quiet HEAD --". 30 + # Does not regard untracked files. 31 + # 32 + # Requires CMake 2.6 or newer (uses the 'function' command) 33 + # 34 + # Original Author: 35 + # 2009-2020 Ryan Pavlik <ryan.pavlik@gmail.com> <abiryan@ryand.net> 36 + # http://academic.cleardefinition.com 37 + # 38 + # Copyright 2009-2013, Iowa State University. 39 + # Copyright 2013-2020, Ryan Pavlik 40 + # Copyright 2013-2020, Contributors 41 + # SPDX-License-Identifier: BSL-1.0 42 + # Distributed under the Boost Software License, Version 1.0. 43 + # (See accompanying file LICENSE_1_0.txt or copy at 44 + # http://www.boost.org/LICENSE_1_0.txt) 45 + 46 + if(__get_git_revision_description) 47 + return() 48 + endif() 49 + set(__get_git_revision_description YES) 50 + 51 + # We must run the following at "include" time, not at function call time, 52 + # to find the path to this module rather than the path to a calling list file 53 + get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) 54 + 55 + # Function _git_find_closest_git_dir finds the next closest .git directory 56 + # that is part of any directory in the path defined by _start_dir. 57 + # The result is returned in the parent scope variable whose name is passed 58 + # as variable _git_dir_var. If no .git directory can be found, the 59 + # function returns an empty string via _git_dir_var. 60 + # 61 + # Example: Given a path C:/bla/foo/bar and assuming C:/bla/.git exists and 62 + # neither foo nor bar contain a file/directory .git. This wil return 63 + # C:/bla/.git 64 + # 65 + function(_git_find_closest_git_dir _start_dir _git_dir_var) 66 + set(cur_dir "${_start_dir}") 67 + set(git_dir "${_start_dir}/.git") 68 + while(NOT EXISTS "${git_dir}") 69 + # .git dir not found, search parent directories 70 + set(git_previous_parent "${cur_dir}") 71 + get_filename_component(cur_dir ${cur_dir} DIRECTORY) 72 + if(cur_dir STREQUAL git_previous_parent) 73 + # We have reached the root directory, we are not in git 74 + set(${_git_dir_var} 75 + "" 76 + PARENT_SCOPE) 77 + return() 78 + endif() 79 + set(git_dir "${cur_dir}/.git") 80 + endwhile() 81 + set(${_git_dir_var} 82 + "${git_dir}" 83 + PARENT_SCOPE) 84 + endfunction() 85 + 86 + function(get_git_head_revision _refspecvar _hashvar) 87 + _git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR) 88 + 89 + if(NOT "${GIT_DIR}" STREQUAL "") 90 + file(RELATIVE_PATH _relative_to_source_dir "${CMAKE_SOURCE_DIR}" 91 + "${GIT_DIR}") 92 + if("${_relative_to_source_dir}" MATCHES "[.][.]") 93 + # We've gone above the CMake root dir. 94 + set(GIT_DIR "") 95 + endif() 96 + endif() 97 + if("${GIT_DIR}" STREQUAL "") 98 + set(${_refspecvar} 99 + "GITDIR-NOTFOUND" 100 + PARENT_SCOPE) 101 + set(${_hashvar} 102 + "GITDIR-NOTFOUND" 103 + PARENT_SCOPE) 104 + return() 105 + endif() 106 + 107 + # Check if the current source dir is a git submodule or a worktree. 108 + # In both cases .git is a file instead of a directory. 109 + # 110 + if(NOT IS_DIRECTORY ${GIT_DIR}) 111 + # The following git command will return a non empty string that 112 + # points to the super project working tree if the current 113 + # source dir is inside a git submodule. 114 + # Otherwise the command will return an empty string. 115 + # 116 + execute_process( 117 + COMMAND "${GIT_EXECUTABLE}" rev-parse 118 + --show-superproject-working-tree 119 + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 120 + OUTPUT_VARIABLE out 121 + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) 122 + if(NOT "${out}" STREQUAL "") 123 + # If out is empty, GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a submodule 124 + file(READ ${GIT_DIR} submodule) 125 + string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE 126 + ${submodule}) 127 + string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE) 128 + get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) 129 + get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} 130 + ABSOLUTE) 131 + set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD") 132 + else() 133 + # GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a worktree 134 + file(READ ${GIT_DIR} worktree_ref) 135 + # The .git directory contains a path to the worktree information directory 136 + # inside the parent git repo of the worktree. 137 + # 138 + string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir 139 + ${worktree_ref}) 140 + string(STRIP ${git_worktree_dir} git_worktree_dir) 141 + _git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR) 142 + set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD") 143 + endif() 144 + else() 145 + set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD") 146 + endif() 147 + set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") 148 + if(NOT EXISTS "${GIT_DATA}") 149 + file(MAKE_DIRECTORY "${GIT_DATA}") 150 + endif() 151 + 152 + if(NOT EXISTS "${HEAD_SOURCE_FILE}") 153 + return() 154 + endif() 155 + set(HEAD_FILE "${GIT_DATA}/HEAD") 156 + configure_file("${HEAD_SOURCE_FILE}" "${HEAD_FILE}" COPYONLY) 157 + 158 + configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" 159 + "${GIT_DATA}/grabRef.cmake" @ONLY) 160 + include("${GIT_DATA}/grabRef.cmake") 161 + 162 + set(${_refspecvar} 163 + "${HEAD_REF}" 164 + PARENT_SCOPE) 165 + set(${_hashvar} 166 + "${HEAD_HASH}" 167 + PARENT_SCOPE) 168 + endfunction() 169 + 170 + function(git_describe _var) 171 + if(NOT GIT_FOUND) 172 + find_package(Git QUIET) 173 + endif() 174 + get_git_head_revision(refspec hash) 175 + if(NOT GIT_FOUND) 176 + set(${_var} 177 + "GIT-NOTFOUND" 178 + PARENT_SCOPE) 179 + return() 180 + endif() 181 + if(NOT hash) 182 + set(${_var} 183 + "HEAD-HASH-NOTFOUND" 184 + PARENT_SCOPE) 185 + return() 186 + endif() 187 + 188 + # TODO sanitize 189 + #if((${ARGN}" MATCHES "&&") OR 190 + # (ARGN MATCHES "||") OR 191 + # (ARGN MATCHES "\\;")) 192 + # message("Please report the following error to the project!") 193 + # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") 194 + #endif() 195 + 196 + #message(STATUS "Arguments to execute_process: ${ARGN}") 197 + 198 + execute_process( 199 + COMMAND "${GIT_EXECUTABLE}" describe --tags --always ${hash} ${ARGN} 200 + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 201 + RESULT_VARIABLE res 202 + OUTPUT_VARIABLE out 203 + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) 204 + if(NOT res EQUAL 0) 205 + set(out "${out}-${res}-NOTFOUND") 206 + endif() 207 + 208 + set(${_var} 209 + "${out}" 210 + PARENT_SCOPE) 211 + endfunction() 212 + 213 + function(git_describe_working_tree _var) 214 + if(NOT GIT_FOUND) 215 + find_package(Git QUIET) 216 + endif() 217 + if(NOT GIT_FOUND) 218 + set(${_var} 219 + "GIT-NOTFOUND" 220 + PARENT_SCOPE) 221 + return() 222 + endif() 223 + 224 + execute_process( 225 + COMMAND "${GIT_EXECUTABLE}" describe --dirty ${ARGN} 226 + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 227 + RESULT_VARIABLE res 228 + OUTPUT_VARIABLE out 229 + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) 230 + if(NOT res EQUAL 0) 231 + set(out "${out}-${res}-NOTFOUND") 232 + endif() 233 + 234 + set(${_var} 235 + "${out}" 236 + PARENT_SCOPE) 237 + endfunction() 238 + 239 + function(git_get_exact_tag _var) 240 + git_describe(out --exact-match ${ARGN}) 241 + set(${_var} 242 + "${out}" 243 + PARENT_SCOPE) 244 + endfunction() 245 + 246 + function(git_local_changes _var) 247 + if(NOT GIT_FOUND) 248 + find_package(Git QUIET) 249 + endif() 250 + get_git_head_revision(refspec hash) 251 + if(NOT GIT_FOUND) 252 + set(${_var} 253 + "GIT-NOTFOUND" 254 + PARENT_SCOPE) 255 + return() 256 + endif() 257 + if(NOT hash) 258 + set(${_var} 259 + "HEAD-HASH-NOTFOUND" 260 + PARENT_SCOPE) 261 + return() 262 + endif() 263 + 264 + execute_process( 265 + COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD -- 266 + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 267 + RESULT_VARIABLE res 268 + OUTPUT_VARIABLE out 269 + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) 270 + if(res EQUAL 0) 271 + set(${_var} 272 + "CLEAN" 273 + PARENT_SCOPE) 274 + else() 275 + set(${_var} 276 + "DIRTY" 277 + PARENT_SCOPE) 278 + endif() 279 + endfunction()
+41
cmake/GetGitRevisionDescription.cmake.in
··· 1 + # 2 + # Internal file for GetGitRevisionDescription.cmake 3 + # 4 + # Requires CMake 2.6 or newer (uses the 'function' command) 5 + # 6 + # Original Author: 7 + # 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> 8 + # http://academic.cleardefinition.com 9 + # Iowa State University HCI Graduate Program/VRAC 10 + # 11 + # Copyright Iowa State University 2009-2010. 12 + # Distributed under the Boost Software License, Version 1.0. 13 + # (See accompanying file LICENSE_1_0.txt or copy at 14 + # http://www.boost.org/LICENSE_1_0.txt) 15 + 16 + set(HEAD_HASH) 17 + 18 + file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) 19 + 20 + string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) 21 + if(HEAD_CONTENTS MATCHES "ref") 22 + # named branch 23 + string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") 24 + if(EXISTS "@GIT_DIR@/${HEAD_REF}") 25 + configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) 26 + else() 27 + configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY) 28 + file(READ "@GIT_DATA@/packed-refs" PACKED_REFS) 29 + if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}") 30 + set(HEAD_HASH "${CMAKE_MATCH_1}") 31 + endif() 32 + endif() 33 + else() 34 + # detached HEAD 35 + configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) 36 + endif() 37 + 38 + if(NOT HEAD_HASH) 39 + file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) 40 + string(STRIP "${HEAD_HASH}" HEAD_HASH) 41 + endif()
+4
src/xrt/auxiliary/CMakeLists.txt
··· 104 104 util/u_format.h 105 105 util/u_frame.c 106 106 util/u_frame.h 107 + util/u_git_tag.h 107 108 util/u_handles.c 108 109 util/u_handles.h 109 110 util/u_hashmap.cpp ··· 131 132 util/u_hand_tracking.c 132 133 util/u_hand_tracking.h 133 134 ) 135 + 136 + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/util/u_git_tag.c.in" "${CMAKE_CURRENT_BINARY_DIR}/u_git_tag.c" @ONLY) 137 + list(APPEND UTIL_SOURCE_FILES "${CMAKE_CURRENT_BINARY_DIR}/u_git_tag.c") 134 138 135 139 set(VK_SOURCE_FILES 136 140 vk/vk_documentation.h
+10 -1
src/xrt/auxiliary/meson.build
··· 3 3 4 4 aux_include = include_directories('.') 5 5 6 + u_git_tag_c = vcs_tag( 7 + input: 'util/u_git_tag.c.in', 8 + output: 'u_git_tag.c', 9 + replace_string: '@GIT_DESC@', 10 + ) 11 + 6 12 lib_aux_util = static_library( 7 13 'aux_util', 8 14 files( ··· 21 27 'util/u_format.h', 22 28 'util/u_frame.c', 23 29 'util/u_frame.h', 30 + 'util/u_git_tag.h', 24 31 'util/u_handles.c', 25 32 'util/u_handles.h', 26 33 'util/u_hashmap.cpp', ··· 47 54 'util/u_var.h', 48 55 'util/u_hand_tracking.c', 49 56 'util/u_hand_tracking.h', 50 - ), 57 + ) + [ 58 + u_git_tag_c 59 + ], 51 60 include_directories: [ 52 61 xrt_include, 53 62 cjson_include,
+13
src/xrt/auxiliary/util/u_git_tag.c.in
··· 1 + // Copyright 2020, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Holds the git hash of Monado. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup aux_util 8 + */ 9 + 10 + #include "util/u_git_tag.h" 11 + 12 + #define GIT_DESC "@GIT_DESC@" 13 + const char u_git_tag[] = GIT_DESC;
+23
src/xrt/auxiliary/util/u_git_tag.h
··· 1 + // Copyright 2020, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Holds the git hash of Monado. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup aux_util 8 + */ 9 + 10 + #pragma once 11 + 12 + 13 + #ifdef __cplusplus 14 + extern "C" { 15 + #endif 16 + 17 + 18 + extern const char u_git_tag[]; 19 + 20 + 21 + #ifdef __cplusplus 22 + } 23 + #endif
+3 -2
src/xrt/state_trackers/oxr/oxr_instance.c
··· 16 16 #include "util/u_time.h" 17 17 #include "util/u_misc.h" 18 18 #include "util/u_debug.h" 19 + #include "util/u_git_tag.h" 19 20 20 21 #ifdef XRT_OS_ANDROID 21 22 #include "android/android_globals.h" ··· 418 419 XrInstanceProperties *instanceProperties) 419 420 { 420 421 instanceProperties->runtimeVersion = XR_MAKE_VERSION(0, 1, 42); 421 - strncpy(instanceProperties->runtimeName, 422 - "Monado(XRT) by Collabora et al", XR_MAX_RUNTIME_NAME_SIZE - 1); 422 + snprintf(instanceProperties->runtimeName, XR_MAX_RUNTIME_NAME_SIZE - 1, 423 + "Monado(XRT) by Collabora et al '%s'", u_git_tag); 423 424 424 425 return XR_SUCCESS; 425 426 }