Fix 'make relupd'
authorRichard Levitte <levitte@openssl.org>
Tue, 31 Mar 2020 09:24:47 +0000 (11:24 +0200)
committerRichard Levitte <levitte@openssl.org>
Tue, 31 Mar 2020 12:12:46 +0000 (14:12 +0200)
The release updating targets relied on the files CHANGES and NEWS.
With OpenSSL 3.0, those have changed name to CHANGES.md and NEWS.md,
so an adjustment is needed.

Experience shows that we get the best output with a 'commonmark'
pandoc reader, and a little bit of post processing the output.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/web/pull/166)

Makefile
bin/from-tt
bin/post-process-html5 [new file with mode: 0755]

index df2d75e1fe91bf8699d88f502f435bf4c1dabce2..d31a473212d5586c4ef3bdde064cb20ce18e030d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -161,9 +161,10 @@ docs/fips.inc: $(wildcard docs/fips/*) bin/mk-filelist
        @rm -f $@
        ./bin/mk-filelist docs/fips fips/ '*' >$@
 
-news/changelog.inc: news/changelog.txt bin/mk-changelog
+news/changelog.inc: news/changelog.md bin/mk-changelog
        @rm -f $@
-       ./bin/mk-changelog <news/changelog.txt >$@
+       (echo 'Table of contents'; sed -e '1,/^OpenSSL Releases$$/d' < $<) \
+               | pandoc -t html5 -f commonmark | ./bin/post-process-html5 >$@
 news/changelog.html: news/changelog.html.tt news/changelog.inc
        @rm -f $@
        ./bin/from-tt 'releases=$(SERIES)' $<
@@ -175,41 +176,42 @@ news/changelog.html: $(foreach S,$(SERIES),news/cl$(subst .,,$(S)).txt)
 # mknews_changelogtxt creates a target and ruleset for any changelog text
 # file depending on the CHANGES file from the target release.
 #
-# $(1) = output file, $(2) = source directory in CHECKOUTS
+# $(1) = output file, $(2) = CHANGES files, relative to CHECKOUTS
 define mknews_changelogtxt
-news/$(1): $(CHECKOUTS)/$(2)/CHANGES
+news/$(1): $(CHECKOUTS)/$(2)
        @rm -f $$@
        cp $$? $$@
 endef
 
 # Create the target 'news/changelog.txt', taking the source from
-# $(CHECKOUTS)/openssl/CHANGES
-$(eval $(call mknews_changelogtxt,changelog.txt,openssl))
+# $(CHECKOUTS)/openssl/CHANGES.md
+$(eval $(call mknews_changelogtxt,changelog.md,openssl/CHANGES.md))
 
 # Create the targets 'news/clxyz.txt' for all current releases, taking the
 # source from $(CHECKOUTS)/openssl-x.y.z-stable/CHANGES
 $(foreach S,$(SERIES),\
-$(eval $(call mknews_changelogtxt,cl$(subst .,,$(S)).txt,openssl-$(S)-stable)))
+$(eval $(call mknews_changelogtxt,cl$(subst .,,$(S)).txt,openssl-$(S)-stable/CHANGES)))
 
 # mknews_noteshtml creates two targets and rulesets for creating notes from
 # the NEWS file for each release.  One target is to create a wrapping HTML
 # file from a template, the other is to create the inclusion file with the
 # actual text.
 #
-# $(1) = release version
+# $(1) = release version, $(2) = NEWS file, relative to CHECKOUTS
 define mknews_noteshtml
 news/openssl-$(1)-notes.html: news/openssl-notes.html.tt
        @rm -f $$@
-       ./bin/from-tt -d news release='$(1)' < $$< > $$@
-news/openssl-$(1)-notes.inc: $(CHECKOUTS)/openssl-$(1)-stable/NEWS bin/mk-notes
+       ./bin/from-tt -d news -i $$< -o $$@ release='$(1)'
+news/openssl-$(1)-notes.inc: $(CHECKOUTS)/$(2) bin/mk-notes
        @rm -f $$@
-       ./bin/mk-notes $(1) < $(CHECKOUTS)/openssl-$(1)-stable/NEWS > $$@
+       ./bin/mk-notes $(1) < $(CHECKOUTS)/$(2) > $$@
 endef
 
 # Create the targets 'news/openssl-x.y.z-notes.html' and
 # 'news/openssl-x.y.z-notes.inc' for each release number x.y.z, taking
-# the source from $(CHECKOUTS)/openssl-$(1)-stable/NEWS
-$(foreach S,$(SERIES),$(eval $(call mknews_noteshtml,$(S))))
+# the source from the news file given as second argument.
+$(foreach S,$(SERIES),\
+$(eval $(call mknews_noteshtml,$(S),openssl-$(S)-stable/NEWS)))
 
 news/newsflash.inc: news/newsflash.txt
        sed <$? >$@ \
index e3ddf791669ae137cfc71f39196bcabe7a6d57c5..b5018b68c3b1fcc52bc848c69baac28cf9e8230f 100755 (executable)
@@ -4,24 +4,31 @@ HERE=$(cd $(dirname $0); pwd)
 THIS=$(basename $0)
 
 dir=
+input=
+output=
 
-shortopts='d:h'
-longopts='dir:,help'
+shortopts='d:i:o:h'
+longopts='dir:,input:,output:,help'
 usage="\
 Usage 1: $THIS [ options ] [ key=value ... ] < file.tt > file
 Usage 2: $THIS [ options ] [ key=value ... ] file.tt ...
 
 Options:
     -d, --dir=DIR               Directory of the output file
+    -i, --input=FILE            Input file (usage 1 only)
+    -o, --output=FILE           Output file (usage 1 only)
     -h, --help                  Output this usage and do nothing else
 
-In usage 1, the template is read from standard input and the processing
-result is output to standard output.  In this usage, the --dir option is
-mandatory.
+In usage 1, the template is read from standard input or the file given
+with --input and the processing result is output to standard output or
+the file given with --output.  When the output goes to stdout, the --dir
+option is mandatory.
 
 In usage 2, the templates are read from the files given as argument, and
 the processing result for each of them is written to a corresponding file
 without the '.tt' suffix.  All given file names must have the '.tt' suffix.
+In this usage, --input, --output, standard input and standard output are
+ignored.
 
 In both usages, one can also set template variables with with the form
 key=value.  They must come before any file name."
@@ -42,6 +49,16 @@ while true; do
            shift 2
            continue
            ;;
+       '-i' | '--input' )
+           input="$2"
+           shift 2
+           continue
+           ;;
+       '-o' | '--output' )
+           output="$2"
+           shift 2
+           continue
+           ;;
        '-h' | '--help' )
            echo >&2 "$usage"
            exit 0
@@ -80,8 +97,10 @@ if [ $# -eq 0 ]; then
     fi
     (
        cd $dir
-       ( cat $HERE/../inc/common.tt; cat ) | \
-           eval "$tpagecmd --define 'dir=${dir:-filedir}'"
+       ( cat $HERE/../inc/common.tt;
+          if [ -n "$input" ]; then cat "$input"; else cat; fi ) \
+        | eval "$tpagecmd --define 'dir=${dir:-filedir}'" \
+        | ( if [ -n "$output" ]; then cat > "$output"; else cat; fi )
     )
 else
     errfiles=
diff --git a/bin/post-process-html5 b/bin/post-process-html5
new file mode 100755 (executable)
index 0000000..fb6459c
--- /dev/null
@@ -0,0 +1,18 @@
+#! /usr/bin/perl
+
+use strict;
+
+while ( <STDIN> ) {
+    s/<h(\d)/"<h".($1 + 1)/eg;
+    s/<\/h(\d)/"<\/h".($1 + 1)/eg;
+
+    # This is for OpenSSL's CHANGES.md
+    my $gfmid = sub {
+        my $x = lc $_[0];
+        $x =~ s/\s+/-/g;
+        $x =~ s/\.//g;
+        $x
+    };
+    s/(<h3)(>)(OpenSSL .*?)(<\/h3>)/$1.' id="'.$gfmid->($3).'"'.$2.$3.$4/eg;
+    print;
+}