Geant4 Cross Reference |
1 #.rst: 1 #.rst: 2 # G4GitUtilities 2 # G4GitUtilities 3 # -------------- 3 # -------------- 4 # 4 # 5 # .. code-block::cmake 5 # .. code-block::cmake 6 # 6 # 7 # include(G4GitUtilities) 7 # include(G4GitUtilities) 8 # 8 # 9 # CMake functions and macros for working with 9 # CMake functions and macros for working with Git where needed in 10 # Geant4's build/packaging systems. 10 # Geant4's build/packaging systems. 11 # 11 # 12 12 13 #--------------------------------------------- 13 #----------------------------------------------------------------- 14 # License and Disclaimer 14 # License and Disclaimer 15 # 15 # 16 # The Geant4 software is copyright of the C 16 # The Geant4 software is copyright of the Copyright Holders of 17 # the Geant4 Collaboration. It is provided u 17 # the Geant4 Collaboration. It is provided under the terms and 18 # conditions of the Geant4 Software License, 18 # conditions of the Geant4 Software License, included in the file 19 # LICENSE and available at http://cern.ch/gea 19 # LICENSE and available at http://cern.ch/geant4/license . These 20 # include a list of copyright holders. 20 # include a list of copyright holders. 21 # 21 # 22 # Neither the authors of this software system, 22 # Neither the authors of this software system, nor their employing 23 # institutes,nor the agencies providing financ 23 # institutes,nor the agencies providing financial support for this 24 # work make any representation or warranty, 24 # work make any representation or warranty, express or implied, 25 # regarding this software system or assume a 25 # regarding this software system or assume any liability for its 26 # use. Please see the license in the file LI 26 # use. Please see the license in the file LICENSE and URL above 27 # for the full disclaimer and the limitation o 27 # for the full disclaimer and the limitation of liability. 28 # 28 # 29 # This code implementation is the result of 29 # This code implementation is the result of the scientific and 30 # technical work of the GEANT4 collaboration. 30 # technical work of the GEANT4 collaboration. 31 # By using, copying, modifying or distribut 31 # By using, copying, modifying or distributing the software (or 32 # any work based on the software) you agree 32 # any work based on the software) you agree to acknowledge its 33 # use in resulting scientific publications 33 # use in resulting scientific publications, and indicate your 34 # acceptance of all terms of the Geant4 Softwa 34 # acceptance of all terms of the Geant4 Software license. 35 # 35 # 36 #--------------------------------------------- 36 #----------------------------------------------------------------- 37 37 38 include_guard(GLOBAL) 38 include_guard(GLOBAL) 39 39 40 #--------------------------------------------- 40 #----------------------------------------------------------------------- 41 #.rst: 41 #.rst: 42 # .. cmake:command:: geant4_git_find_dirty 42 # .. cmake:command:: geant4_git_find_dirty 43 # 43 # 44 # .. code-block:: cmake 44 # .. code-block:: cmake 45 # 45 # 46 # geant4_git_find_dirty(<basedir> <modifie 46 # geant4_git_find_dirty(<basedir> <modified> <untracked>) 47 # 47 # 48 # Runs ``git status`` in the ``<basedir>``, 48 # Runs ``git status`` in the ``<basedir>``, writing lists of modified 49 # and untracked/ignored files to ``<modified 49 # and untracked/ignored files to ``<modified>`` and ``<untracked>`` 50 # respectively. 50 # respectively. 51 # 51 # 52 # ``<basedir>`` must be the root of the repo 52 # ``<basedir>`` must be the root of the repository queried, i.e. containing 53 # the ``.git/`` directory. 53 # the ``.git/`` directory. 54 # 54 # 55 # Nothing is returned in the output variable 55 # Nothing is returned in the output variables if ``<basedir>`` is not a 56 # git repository or if a ``git`` executable 56 # git repository or if a ``git`` executable cannot be located. 57 # 57 # 58 function(geant4_git_find_dirty _basedir _outpu 58 function(geant4_git_find_dirty _basedir _output_modified _output_untracked) 59 if(NOT EXISTS "${_basedir}/.git") 59 if(NOT EXISTS "${_basedir}/.git") 60 return() 60 return() 61 endif() 61 endif() 62 62 63 find_package(Git QUIET) 63 find_package(Git QUIET) 64 if(NOT Git_FOUND) 64 if(NOT Git_FOUND) 65 return() 65 return() 66 endif() 66 endif() 67 67 68 execute_process(COMMAND ${GIT_EXECUTABLE} st 68 execute_process(COMMAND ${GIT_EXECUTABLE} status -s --ignored 69 WORKING_DIRECTORY "${_basedir}" 69 WORKING_DIRECTORY "${_basedir}" 70 OUTPUT_VARIABLE GEANT4_GIT_UNTRACKED 70 OUTPUT_VARIABLE GEANT4_GIT_UNTRACKED 71 ERROR_VARIABLE GEANT4_GIT_UNTRACKED_ERROR) 71 ERROR_VARIABLE GEANT4_GIT_UNTRACKED_ERROR) 72 72 73 if(GEANT4_GIT_UNTRACKED_ERROR) 73 if(GEANT4_GIT_UNTRACKED_ERROR) 74 message(FATAL_ERROR "geant4_git_find_dirty 74 message(FATAL_ERROR "geant4_git_find_dirty: Calling `git status` failed with error: '${GEANT4_GIT_UNTRACKED_ERROR}'") 75 endif() 75 endif() 76 76 77 if(GEANT4_GIT_UNTRACKED) 77 if(GEANT4_GIT_UNTRACKED) 78 set(_modded_files) 78 set(_modded_files) 79 set(_untracked_files) 79 set(_untracked_files) 80 80 81 string(REPLACE "\n" ";" GEANT4_GIT_UNTRACK 81 string(REPLACE "\n" ";" GEANT4_GIT_UNTRACKED "${GEANT4_GIT_UNTRACKED}") 82 foreach(item ${GEANT4_GIT_UNTRACKED}) 82 foreach(item ${GEANT4_GIT_UNTRACKED}) 83 if(item MATCHES "^ *(M|A|R|D|C)") 83 if(item MATCHES "^ *(M|A|R|D|C)") 84 string(REGEX REPLACE "^ *[MARDC][MARDC 84 string(REGEX REPLACE "^ *[MARDC][MARDC] *" "" _modded_path "${item}") 85 list(APPEND _modded_files ${_modded_pa 85 list(APPEND _modded_files ${_modded_path}) 86 endif() 86 endif() 87 87 88 if(item MATCHES "^ *(\\!|\\?)") 88 if(item MATCHES "^ *(\\!|\\?)") 89 string(REGEX REPLACE "^ *(\\!\\!|\\?\\ 89 string(REGEX REPLACE "^ *(\\!\\!|\\?\\?) *" "" _untracked_path "${item}") 90 list(APPEND _untracked_files "${_untra 90 list(APPEND _untracked_files "${_untracked_path}") 91 endif() 91 endif() 92 endforeach() 92 endforeach() 93 93 94 set(${_output_modified} ${_modded_files} P 94 set(${_output_modified} ${_modded_files} PARENT_SCOPE) 95 set(${_output_untracked} ${_untracked_file 95 set(${_output_untracked} ${_untracked_files} PARENT_SCOPE) 96 endif() 96 endif() 97 endfunction() 97 endfunction()