PostprocessChangeLog.cmake
Go to the documentation of this file.
1 # ============================================================================
2 # Copyright (c) 2011-2012 University of Pennsylvania
3 # Copyright (c) 2013-2016 Andreas Schuh
4 # All rights reserved.
5 #
6 # See COPYING file for license information or visit
7 # https://cmake-basis.github.io/download.html#license
8 # ============================================================================
9 
10 ##############################################################################
11 # @file PostprocessChangeLog.cmake
12 # @brief Script used to postprocess ChangeLog generated from commit history.
13 #
14 # Usage: cmake -DCHANGELOG_FILE=file -DINPUTFORMAT=[SVN|SVN2CL|GIT]
15 # -P PostprocessChangeLog.cmake
16 #
17 # @ingroup CMakeTools
18 ##############################################################################
19 
20 # ----------------------------------------------------------------------------
21 # check required arguments
22 if (NOT CHANGELOG_FILE)
23  message (FATAL_ERROR "Missing CHANGELOG_FILE argument!")
24 endif ()
25 
26 if (NOT INPUTFORMAT)
27  set (INPUTFORMAT SVN)
28 endif ()
29 
30 # ----------------------------------------------------------------------------
31 # read change log
32 file (READ "${CHANGELOG_FILE}" CHANGELOG)
33 
34 # ----------------------------------------------------------------------------
35 # git log
36 if (INPUTFORMAT MATCHES "GIT")
37 
38  # remove git-svn-id entries from commit message body
39  string (REGEX REPLACE "[ \n\r\t]*git-svn-id:[ \n\r]*[^@]*@[0-9]+[ \n\t]+[-0-9a-z]*" "" CHANGELOG "${CHANGELOG}")
40  # group entries of same date and same author
41  string (REGEX MATCHALL "[^\n]+(\n|$)" LINES "${CHANGELOG}")
42  # clear changelog
43  set (CHANGELOG)
44  # process changelog line-by-line and leave out duplicate date and author lines
45  set (PREV)
46  foreach (LINE IN LISTS LINES)
47  string (REGEX REPLACE "[\n]$" "" LINE "${LINE}")
48  # Hack: For some reason the regular expression used above to split the
49  # change log file into lines produces lines with a newline followed
50  # by a semicolon. This could be a bug in CMake as well.
51  string (REGEX REPLACE "[\n];" "\n" LINE "${LINE}")
52  # a line with a date and author marks the beginning of a log entry
53  if (LINE MATCHES "^[0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]? [a-zA-Z ]+$")
54  if (NOT PREV OR NOT LINE STREQUAL PREV)
55  if (PREV)
56  set (CHANGELOG "${CHANGELOG}\n")
57  endif ()
58  set (CHANGELOG "${CHANGELOG}${LINE}\n\n")
59  set (PREV "${LINE}")
60  endif ()
61  else ()
62  set (CHANGELOG "${CHANGELOG}${LINE}\n")
63  endif ()
64  endforeach ()
65 
66 endif ()
67 
68 # ----------------------------------------------------------------------------
69 # write change log
70 file (WRITE "${CHANGELOG_FILE}" "${CHANGELOG}")
cmake PREV
if(oldcoutbuf)
cmake INPUTFORMAT
cmake CHANGELOG