Warning, /geant4/cmake/Modules/G4GitUtilities.cmake is written in an unsupported language. File is not indexed.
0001 #.rst:
0002 # G4GitUtilities
0003 # --------------
0004 #
0005 # .. code-block::cmake
0006 #
0007 # include(G4GitUtilities)
0008 #
0009 # CMake functions and macros for working with Git where needed in
0010 # Geant4's build/packaging systems.
0011 #
0012
0013 #-----------------------------------------------------------------
0014 # License and Disclaimer
0015 #
0016 # The Geant4 software is copyright of the Copyright Holders of
0017 # the Geant4 Collaboration. It is provided under the terms and
0018 # conditions of the Geant4 Software License, included in the file
0019 # LICENSE and available at http://cern.ch/geant4/license . These
0020 # include a list of copyright holders.
0021 #
0022 # Neither the authors of this software system, nor their employing
0023 # institutes,nor the agencies providing financial support for this
0024 # work make any representation or warranty, express or implied,
0025 # regarding this software system or assume any liability for its
0026 # use. Please see the license in the file LICENSE and URL above
0027 # for the full disclaimer and the limitation of liability.
0028 #
0029 # This code implementation is the result of the scientific and
0030 # technical work of the GEANT4 collaboration.
0031 # By using, copying, modifying or distributing the software (or
0032 # any work based on the software) you agree to acknowledge its
0033 # use in resulting scientific publications, and indicate your
0034 # acceptance of all terms of the Geant4 Software license.
0035 #
0036 #-----------------------------------------------------------------
0037
0038 include_guard(GLOBAL)
0039
0040 #-----------------------------------------------------------------------
0041 #.rst:
0042 # .. cmake:command:: geant4_git_find_dirty
0043 #
0044 # .. code-block:: cmake
0045 #
0046 # geant4_git_find_dirty(<basedir> <modified> <untracked>)
0047 #
0048 # Runs ``git status`` in the ``<basedir>``, writing lists of modified
0049 # and untracked/ignored files to ``<modified>`` and ``<untracked>``
0050 # respectively.
0051 #
0052 # ``<basedir>`` must be the root of the repository queried, i.e. containing
0053 # the ``.git/`` directory.
0054 #
0055 # Nothing is returned in the output variables if ``<basedir>`` is not a
0056 # git repository or if a ``git`` executable cannot be located.
0057 #
0058 function(geant4_git_find_dirty _basedir _output_modified _output_untracked)
0059 if(NOT EXISTS "${_basedir}/.git")
0060 return()
0061 endif()
0062
0063 find_package(Git QUIET)
0064 if(NOT Git_FOUND)
0065 return()
0066 endif()
0067
0068 execute_process(COMMAND ${GIT_EXECUTABLE} status -s --ignored
0069 WORKING_DIRECTORY "${_basedir}"
0070 OUTPUT_VARIABLE GEANT4_GIT_UNTRACKED
0071 ERROR_VARIABLE GEANT4_GIT_UNTRACKED_ERROR)
0072
0073 if(GEANT4_GIT_UNTRACKED_ERROR)
0074 message(FATAL_ERROR "geant4_git_find_dirty: Calling `git status` failed with error: '${GEANT4_GIT_UNTRACKED_ERROR}'")
0075 endif()
0076
0077 if(GEANT4_GIT_UNTRACKED)
0078 set(_modded_files)
0079 set(_untracked_files)
0080
0081 string(REPLACE "\n" ";" GEANT4_GIT_UNTRACKED "${GEANT4_GIT_UNTRACKED}")
0082 foreach(item ${GEANT4_GIT_UNTRACKED})
0083 if(item MATCHES "^ *(M|A|R|D|C)")
0084 string(REGEX REPLACE "^ *[MARDC][MARDC] *" "" _modded_path "${item}")
0085 list(APPEND _modded_files ${_modded_path})
0086 endif()
0087
0088 if(item MATCHES "^ *(\\!|\\?)")
0089 string(REGEX REPLACE "^ *(\\!\\!|\\?\\?) *" "" _untracked_path "${item}")
0090 list(APPEND _untracked_files "${_untracked_path}")
0091 endif()
0092 endforeach()
0093
0094 set(${_output_modified} ${_modded_files} PARENT_SCOPE)
0095 set(${_output_untracked} ${_untracked_files} PARENT_SCOPE)
0096 endif()
0097 endfunction()