Skip to content

Commit 070f561

Browse files
authored
Add maint scripts for checking and updating library version & updated dates (#635)
The workflow shall be: * When the release number is bumped, all references to that release number need to be bumped immediately. (For example, when the source code moves from 10.45 → 10.46, the man pages must do so as well.) * When documentation is updated, there's no need to update the "last modified" dates by hand. We can sweep those all up during the release process. Or update them immediately - there's no harm in it; we simply aren't obliged to.
1 parent e84e6e7 commit 070f561

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

maint/PrepareRelease

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
# "HYPHEN" if the system is using a UTF-8 locale (like "C.UTF-8").
3535
export LANG=C
3636

37+
# Extract the current release version from configure.ac.
38+
CURRENT_RELEASE=`grep -E 'm4_define\(pcre2_(major|minor|prerelease)' configure.ac | \
39+
grep -E -o '\[.*\]' | \
40+
sed -E -e '1s/$/./' | \
41+
tr -d '[]\n'`
42+
3743
# First, sort out the documentation. Remove pcre2demo.3 first because it won't
3844
# pass the markup check (it is created below, using markup that none of the
3945
# other pages use).
@@ -48,6 +54,15 @@ echo Processing documentation
4854
perl ../maint/CheckMan *.1 *.3
4955
if [ $? != 0 ] ; then exit 1; fi
5056

57+
# Verify the version number in the man pages
58+
59+
for file in *.1 *.3 ; do
60+
if ! grep -E ".TH.*\"PCRE2 $CURRENT_RELEASE\"" "$file" >/dev/null ; then
61+
echo "Version number in $file does not match current release"
62+
exit 1
63+
fi
64+
done
65+
5166
# Make Text form of the documentation. It needs some mangling to make it
5267
# tidy for online reading. Concatenate all the .3 stuff, but omit the
5368
# individual function pages.
@@ -293,6 +308,12 @@ perl maint/CheckTxt "${files[@]}"
293308
perl maint/CheckTxt -ascii "${c_files[@]}"
294309
perl maint/CheckTxt -crlf "${crlf_files[@]}"
295310

311+
# Verify the version number in the Bazel file
312+
if ! grep -E "version = \"$CURRENT_RELEASE\"" MODULE.bazel >/dev/null ; then
313+
echo "Version number in MODULE.bazel does not match current release"
314+
exit 1
315+
fi
316+
296317
echo Done
297318

298319
#End

maint/UpdateCommon.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Common helpers for UpdateRelease.py and UpdateDates.py.
2+
3+
import re
4+
5+
def get_current_release():
6+
with open('configure.ac', 'r') as file:
7+
content = file.read()
8+
9+
matches = [match[1] for match in re.findall(r"m4_define\(pcre2_(major|minor|prerelease), \[(.*?)\]\)", content)]
10+
current_release = '%s.%s%s' % tuple(matches)
11+
12+
return current_release
13+
14+
CURRENT_RELEASE = get_current_release()
15+
16+
# Update a file, using a pattern. Verify that it matches the file, and perform
17+
# the replacement.
18+
def update_file(filename, pattern, replacement):
19+
with open(filename, 'r') as file:
20+
content = file.read()
21+
22+
if not re.search(pattern, content):
23+
raise Exception('Pattern not found in %s' % filename)
24+
25+
content = re.sub(pattern, replacement, content)
26+
27+
with open(filename, 'w') as file:
28+
file.write(content)

maint/UpdateDates.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#! /usr/bin/env python3
2+
3+
# Script to update all the hardcoded dates in the source tree.
4+
# - Documentation manpages have a "last updated" header and footer.
5+
# - So do the READMEs.
6+
# - The source files have copyright headers.
7+
8+
# This script should be run in the main PCRE2 directory.
9+
10+
import glob
11+
import re
12+
import subprocess
13+
14+
from UpdateCommon import update_file
15+
16+
date_regex = r'\d+ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\w* \d+'
17+
header_regex = r'(?m)^(.TH.*? )"%s"' % date_regex
18+
last_updated_regex = r'(?m)^Last updated: %s' % date_regex
19+
20+
def get_last_date(filename):
21+
result = subprocess.run(['git', 'log', '-n1', '--date=format:%d %B %Y', '--format=%cd', '--grep', '#noupdate', '--invert-grep', filename], capture_output=True, text=True)
22+
return result.stdout.strip()
23+
24+
def check_no_match(filename, pattern):
25+
with open(filename, 'r') as file:
26+
content = file.read()
27+
28+
if re.search(pattern, content):
29+
raise Exception('Pattern unexpectedly found in %s' % filename)
30+
31+
def update_man_date(filename):
32+
print(' Updating %s' % filename)
33+
file_date = get_last_date(filename)
34+
35+
update_file(filename, header_regex, '\\1"%s"' % file_date)
36+
37+
if filename.startswith('doc/pcre2_') or filename == 'doc/pcre2demo.3':
38+
check_no_match(filename, last_updated_regex)
39+
else:
40+
update_file(filename, last_updated_regex, 'Last updated: %s' % file_date)
41+
42+
print('Updating man pages')
43+
44+
# doc/*.1
45+
for filename in glob.glob('doc/*.1'):
46+
update_man_date(filename)
47+
48+
# doc/*.3
49+
for filename in glob.glob('doc/*.3'):
50+
update_man_date(filename)
51+
52+
# README, NON-AUTOTOOLS-BUILD
53+
print('Updating README and NON-AUTOTOOLS-BUILD')
54+
for filename in ['README', 'NON-AUTOTOOLS-BUILD']:
55+
line = 'Last updated: %s' % get_last_date(filename)
56+
padding = '=' * len(line)
57+
update_file(filename, r'(?i)=+\nLast updated: .*?\n=+', '%s\n%s\n%s' % (padding, line, padding))

maint/UpdateRelease.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#! /usr/bin/env python3
2+
3+
# Script to update all the hardcoded release numbers in the source tree.
4+
# - Documentation manpages.
5+
# - Bazel MODULE file.
6+
7+
# This script should be run in the main PCRE2 directory.
8+
9+
import glob
10+
11+
from UpdateCommon import update_file, CURRENT_RELEASE
12+
13+
def update_man_version(filename):
14+
print(' Updating %s' % filename)
15+
update_file(filename, r'(.TH.*? )"PCRE2 .*?"', '\\1"PCRE2 %s"' % CURRENT_RELEASE)
16+
17+
print('Updating man pages')
18+
19+
# doc/*.1
20+
for filename in glob.glob('doc/*.1'):
21+
update_man_version(filename)
22+
23+
# doc/*.3
24+
for filename in glob.glob('doc/*.3'):
25+
update_man_version(filename)
26+
27+
# MODULE.bazel
28+
print('Updating MODULE.bazel')
29+
update_file('MODULE.bazel', r'(?m)^ version = ".*?"', ' version = "%s"' % CURRENT_RELEASE)

0 commit comments

Comments
 (0)