Changeset View
Standalone View
modules/ECMSourceVersionControl.cmake
Context not available. | |||||
12 | 12 | | |||
---|---|---|---|---|---|
13 | #============================================================================= | 13 | #============================================================================= | ||
14 | # Copyright 2019 Harald Sitter <sitter@kde.org> | 14 | # Copyright 2019 Harald Sitter <sitter@kde.org> | ||
15 | # Copyright 2019 Thomas Fischer <fischer@unix-ag.uni-kl.de> | ||||
15 | # | 16 | # | ||
16 | # Redistribution and use in source and binary forms, with or without | 17 | # Redistribution and use in source and binary forms, with or without | ||
17 | # modification, are permitted provided that the following conditions | 18 | # modification, are permitted provided that the following conditions | ||
Context not available. | |||||
36 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 37 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
37 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 38 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
38 | 39 | | |||
39 | if(EXISTS "${CMAKE_SOURCE_DIR}/.git" OR | 40 | if(EXISTS "${CMAKE_SOURCE_DIR}/.git") | ||
40 | EXISTS "${CMAKE_SOURCE_DIR}/.svn" OR | 41 | # Git | ||
41 | EXISTS "${CMAKE_SOURCE_DIR}/.hg" OR | | |||
42 | EXISTS "${CMAKE_SOURCE_DIR}/.bzr") | | |||
43 | set(ECM_SOURCE_UNDER_VERSION_CONTROL TRUE) | 42 | set(ECM_SOURCE_UNDER_VERSION_CONTROL TRUE) | ||
43 | set(ECM_SOURCE_VERSION_CONTROL_WHICH "git") | ||||
44 | elseif(EXISTS "${CMAKE_SOURCE_DIR}/.svn") | ||||
45 | # Subversion | ||||
46 | set(ECM_SOURCE_UNDER_VERSION_CONTROL TRUE) | ||||
47 | set(ECM_SOURCE_VERSION_CONTROL_WHICH "svn") | ||||
48 | elseif(EXISTS "${CMAKE_SOURCE_DIR}/.hg") | ||||
49 | # Mercurial | ||||
50 | set(ECM_SOURCE_UNDER_VERSION_CONTROL TRUE) | ||||
51 | set(ECM_SOURCE_VERSION_CONTROL_WHICH "hg") | ||||
52 | elseif(EXISTS "${CMAKE_SOURCE_DIR}/.bzr") | ||||
53 | # Bazaar | ||||
54 | set(ECM_SOURCE_UNDER_VERSION_CONTROL TRUE) | ||||
55 | set(ECM_SOURCE_VERSION_CONTROL_WHICH "bzr") | ||||
44 | else() | 56 | else() | ||
57 | unset(ECM_SOURCE_VERSION_CONTROL_WHICH) | ||||
45 | set(ECM_SOURCE_UNDER_VERSION_CONTROL FALSE) | 58 | set(ECM_SOURCE_UNDER_VERSION_CONTROL FALSE) | ||
46 | endif() | 59 | endif() | ||
60 | | ||||
61 | macro(ecm_source_version_control_stat) | ||||
sitter: Do we really need this? It seems to me we could just spam it for every call, in the grand… | |||||
62 | unset(ECM_SOURCE_VERSION_CONTROL_REVISION) | ||||
63 | unset(ECM_SOURCE_VERSION_CONTROL_BRANCH) | ||||
64 | unset(ECM_SOURCE_VERSION_CONTROL_COMMIT_COUNT) | ||||
65 | if(NOT ${ECM_SOURCE_UNDER_VERSION_CONTROL}) | ||||
66 | message("Source directory not managed by a supported version control system (Git)") | ||||
67 | elseif(${ECM_SOURCE_VERSION_CONTROL_WHICH} STREQUAL "git") | ||||
68 | # Git | ||||
69 | message(STATUS "Source directory '${CMAKE_SOURCE_DIR}' is under version control by Git.") | ||||
70 | find_program(GIT_EXECUTABLE | ||||
I think you are leaking this variable into the parent scope. I am not super sure how to deal with this but I think I've seen _prefixes, or you use a function and explicitly forward into the PARENT_SCOPE (https://cmake.org/cmake/help/v3.0/command/set.html). Alternatively with a multi-function approach I'd probably just make it ECM_SOURCE_VERSION_CONTROL_EXECUTABLE so it only needs finding on the first call. sitter: I think you are leaking this variable into the parent scope. I am not super sure how to deal… | |||||
71 | NAMES git.bat git # for Windows, 'git.bat' must be found before 'git' | ||||
72 | ) | ||||
73 | if(GIT_EXECUTABLE) | ||||
74 | execute_process( | ||||
75 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" | ||||
I'd move the exec detection and missing reporting into its own helper which gets called by all "public" functions. Currently the logic is duped in both functions. sitter: I'd move the exec detection and missing reporting into its own helper which gets called by all… | |||||
76 | COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD | ||||
77 | OUTPUT_VARIABLE ECM_SOURCE_VERSION_CONTROL_REVISION | ||||
78 | OUTPUT_STRIP_TRAILING_WHITESPACE | ||||
79 | ) | ||||
80 | execute_process( | ||||
81 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" | ||||
82 | COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD | ||||
83 | OUTPUT_VARIABLE ECM_SOURCE_VERSION_CONTROL_BRANCH | ||||
84 | OUTPUT_STRIP_TRAILING_WHITESPACE | ||||
85 | ) | ||||
86 | execute_process( | ||||
87 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" | ||||
I think it's more idiomatic if you accept the variable name as a function argument instead of hardcoding one. For example find_program, but really most helpers work like that off the top of my head. sitter: I think it's more idiomatic if you accept the variable name as a function argument instead of… | |||||
88 | COMMAND "${GIT_EXECUTABLE}" rev-list --count HEAD | ||||
89 | OUTPUT_VARIABLE ECM_SOURCE_VERSION_CONTROL_COMMIT_COUNT | ||||
90 | OUTPUT_STRIP_TRAILING_WHITESPACE | ||||
91 | ) | ||||
92 | message(STATUS "The current Git checkout is branch '${ECM_SOURCE_VERSION_CONTROL_BRANCH}' at commit ${ECM_SOURCE_VERSION_CONTROL_REVISION} which traces back ${ECM_SOURCE_VERSION_CONTROL_COMMIT_COUNT} commits to initialization.") | ||||
93 | else() | ||||
94 | message(WARNING "No Git executable found despite .git directory located in source directory") | ||||
95 | endif() | ||||
96 | else() | ||||
97 | message(WARNING "Cannot retrieve data for version control system '${ECM_SOURCE_VERSION_CONTROL_WHICH}'") | ||||
98 | endif() | ||||
99 | endmacro() | ||||
Context not available. |
Do we really need this? It seems to me we could just spam it for every call, in the grand scheme of things it makes no difference but is less logic one has to worry about when extending this module.