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