1 | #!/usr/bin/env kmk_ash
|
---|
2 | # $Id: docbook-changelog-to-manual-dita.sh 105199 2024-07-08 18:33:43Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # Helper script for converting the changelog into a ditamap and a topic
|
---|
5 | # file per version.
|
---|
6 | #
|
---|
7 |
|
---|
8 | #
|
---|
9 | # Copyright (C) 2023 Oracle and/or its affiliates.
|
---|
10 | #
|
---|
11 | # This file is part of VirtualBox base platform packages, as
|
---|
12 | # available from https://www.virtualbox.org.
|
---|
13 | #
|
---|
14 | # This program is free software; you can redistribute it and/or
|
---|
15 | # modify it under the terms of the GNU General Public License
|
---|
16 | # as published by the Free Software Foundation, in version 3 of the
|
---|
17 | # License.
|
---|
18 | #
|
---|
19 | # This program is distributed in the hope that it will be useful, but
|
---|
20 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
22 | # General Public License for more details.
|
---|
23 | #
|
---|
24 | # You should have received a copy of the GNU General Public License
|
---|
25 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
26 | #
|
---|
27 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
28 | #
|
---|
29 |
|
---|
30 | #
|
---|
31 | # Globals.
|
---|
32 | #
|
---|
33 | MY_SED=kmk_sed
|
---|
34 |
|
---|
35 | #
|
---|
36 | # This script is very internal, so we got the following fixed position parameters:
|
---|
37 | # 1: user_ChangeLogImpl.xml to use as input.
|
---|
38 | # 2: docbook-changelog-to-manual-dita.xsl
|
---|
39 | # 5: The out directory.
|
---|
40 | # 6: '--'
|
---|
41 | # 7+: xsltproc invocation (sans output, input and xslt file).
|
---|
42 | #
|
---|
43 | if test $# -lt 8; then
|
---|
44 | echo "syntax error: too few arguments" 1>&2;
|
---|
45 | exit 2;
|
---|
46 | fi
|
---|
47 | MY_INPUT_FILE="$1"
|
---|
48 | MY_XSLT="$2"
|
---|
49 | MY_GENERATED_KMK="$3"
|
---|
50 | MY_GENERATED_KMK_VARIABLE="$4"
|
---|
51 | MY_OUTPUT_DIR="$5"
|
---|
52 | if test "$6" != "--"; then
|
---|
53 | echo "syntax error: Expected '--' as the 6th parameter, got: $6" 1>&2;
|
---|
54 | exit 2;
|
---|
55 | fi
|
---|
56 | shift 6
|
---|
57 |
|
---|
58 | if ! test -f "${MY_INPUT_FILE}"; then
|
---|
59 | echo "error: Input file does not exists or is not a regular file: ${MY_INPUT_FILE}" 1>&2;
|
---|
60 | exit 1;
|
---|
61 | fi
|
---|
62 | if ! test -f "${MY_XSLT}"; then
|
---|
63 | echo "error: The given dita-refentry-flat-topic-ids.xsl file does not exists or is not a regular file: ${MY_XSLT_TOPIC_IDS}" 1>&2;
|
---|
64 | exit 1;
|
---|
65 | fi
|
---|
66 | if ! test -d "${MY_OUTPUT_DIR}"; then
|
---|
67 | echo "error: Destination directory does not exists or not a directory: ${MY_OUTPUT_DIR}" 1>&2;
|
---|
68 | exit 1;
|
---|
69 | fi
|
---|
70 |
|
---|
71 | # Exit on failure.
|
---|
72 | set -e
|
---|
73 |
|
---|
74 | #
|
---|
75 | # First get the ID list from it.
|
---|
76 | # We drop the first line with the <?xml ... ?> stuff.
|
---|
77 | #
|
---|
78 | MY_TOPIC_IDS=$($* --stringparam g_sMode ids "${MY_XSLT}" "${MY_INPUT_FILE}" | ${MY_SED} -e 1d)
|
---|
79 |
|
---|
80 | echo "${MY_GENERATED_KMK_VARIABLE} += \\" > "${MY_GENERATED_KMK}"
|
---|
81 |
|
---|
82 | #
|
---|
83 | # Extract each topic.
|
---|
84 | #
|
---|
85 | for MY_ID in ${MY_TOPIC_IDS};
|
---|
86 | do
|
---|
87 | $* \
|
---|
88 | --stringparam g_sMode topic \
|
---|
89 | --stringparam g_idTopic "${MY_ID}" \
|
---|
90 | --output "${MY_OUTPUT_DIR}/${MY_ID}.dita" "${MY_XSLT}" "${MY_INPUT_FILE}"
|
---|
91 | echo " ${MY_OUTPUT_DIR}/${MY_ID}.dita \\" >> "${MY_GENERATED_KMK}"
|
---|
92 | done
|
---|
93 |
|
---|
94 | #
|
---|
95 | # Now for the ditamap file.
|
---|
96 | #
|
---|
97 | $* --stringparam g_sMode map --output "${MY_OUTPUT_DIR}/changelog-versions.ditamap" "${MY_XSLT}" "${MY_INPUT_FILE}"
|
---|
98 | echo "" >> "${MY_GENERATED_KMK}"
|
---|
99 | exit 0
|
---|