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