manuals: generate VTY reference for osmo-pcap-{client,server}

Change-Id: I28353f51de798535a3bb6efdc6c2da443d96ddfb
Tweaked-By: Vadim Yanitskiy <vyanitskiy@sysmocom.de>
This commit is contained in:
Joachim Steiger 2021-04-09 23:57:01 +02:00 committed by Vadim Yanitskiy
parent 611fd19fa3
commit 52f06fd54b
10 changed files with 214 additions and 3 deletions

9
.gitignore vendored
View File

@ -37,3 +37,12 @@ tests/testsuite
tests/testsuite.log
contrib/osmo-pcap.spec
# manuals
doc/manuals/generated/
doc/manuals/vty/osmo-pcap-*-vty-reference.pdf
doc/manuals/vty/osmo-pcap-*-vty-reference.xml
doc/manuals/vty/osmo-pcap-*-vty-reference.xml.inc.gen
doc/manuals/vty/osmo-pcap-*-vty-reference.xml.inc.merged
doc/manuals/common
doc/manuals/build

View File

@ -5,6 +5,46 @@ AC_INIT([osmo-pcap],
AM_INIT_AUTOMAKE([dist-bzip2])
AC_CONFIG_TESTDIR(tests)
AC_ARG_ENABLE(manuals,
[AS_HELP_STRING(
[--enable-manuals],
[Generate manual PDFs [default=no]],
)],
[osmo_ac_build_manuals=$enableval], [osmo_ac_build_manuals="no"])
AM_CONDITIONAL([BUILD_MANUALS], [test x"$osmo_ac_build_manuals" = x"yes"])
AC_ARG_VAR(OSMO_GSM_MANUALS_DIR, [path to common osmo-gsm-manuals files, overriding pkg-config and "../osmo-gsm-manuals"
fallback])
if test x"$osmo_ac_build_manuals" = x"yes"
then
# Find OSMO_GSM_MANUALS_DIR (env, pkg-conf, fallback)
if test -n "$OSMO_GSM_MANUALS_DIR"; then
echo "checking for OSMO_GSM_MANUALS_DIR... $OSMO_GSM_MANUALS_DIR (from env)"
else
OSMO_GSM_MANUALS_DIR="$($PKG_CONFIG osmo-gsm-manuals --variable=osmogsmmanualsdir 2>/dev/null)"
if test -n "$OSMO_GSM_MANUALS_DIR"; then
echo "checking for OSMO_GSM_MANUALS_DIR... $OSMO_GSM_MANUALS_DIR (from pkg-conf)"
else
OSMO_GSM_MANUALS_DIR="../osmo-gsm-manuals"
echo "checking for OSMO_GSM_MANUALS_DIR... $OSMO_GSM_MANUALS_DIR (fallback)"
fi
fi
if ! test -d "$OSMO_GSM_MANUALS_DIR"; then
AC_MSG_ERROR("OSMO_GSM_MANUALS_DIR does not exist! Install osmo-gsm-manuals or set OSMO_GSM_MANUALS_DIR.")
fi
# Find and run check-depends
CHECK_DEPENDS="$OSMO_GSM_MANUALS_DIR/check-depends.sh"
if ! test -x "$CHECK_DEPENDS"; then
CHECK_DEPENDS="osmo-gsm-manuals-check-depends"
fi
if ! $CHECK_DEPENDS; then
AC_MSG_ERROR("missing dependencies for --enable-manuals")
fi
# Put in Makefile with absolute path
OSMO_GSM_MANUALS_DIR="$(realpath "$OSMO_GSM_MANUALS_DIR")"
AC_SUBST([OSMO_GSM_MANUALS_DIR])
fi
CFLAGS="$CFLAGS -std=gnu11"
@ -150,5 +190,6 @@ AC_OUTPUT(
contrib/osmo-pcap.spec
doc/Makefile
doc/examples/Makefile
doc/manuals/Makefile
tests/Makefile
Makefile)

View File

@ -41,6 +41,11 @@ $MAKE check || cat-testlogs.sh
DISTCHECK_CONFIGURE_FLAGS="--with-pcap-config=/bin/true" \
PCAP_LIBS="-lpcap" PCAP_CFLAGS="" \
$MAKE distcheck || cat-testlogs.sh
if [ "$WITH_MANUALS" = "1" ] && [ "$PUBLISH" = "1" ]; then
make -C "$base/doc/manuals" publish
fi
$MAKE maintainer-clean
osmo-clean-workspace.sh

View File

@ -1 +1,4 @@
SUBDIRS = examples
SUBDIRS = \
examples \
manuals \
$(NULL)

11
doc/manuals/Makefile.am Normal file
View File

@ -0,0 +1,11 @@
EXTRA_DIST = vty
if BUILD_MANUALS
# This is a significantly modified, multi-target adopted copy of
# $(OSMO_GSM_MANUALS_DIR)/build/Makefile.vty-reference.inc
VARIANTS = client server
include $(srcdir)/vty/Makefile.vty-reference.inc
OSMO_REPOSITORY = osmo-pcap
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.common.inc
endif

View File

@ -0,0 +1,37 @@
DOCBOOKS = $(foreach v,$(VARIANTS),vty/osmo-pcap-$(v)-vty-reference.xml)
DOCBOOKS_DEPS = $(DOCBOOKS) $(addsuffix .inc,$(DOCBOOKS))
INC_DIR = $(abspath $(builddir)/vty)
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.docbook.inc
CLEAN_FILES += $(DOCBOOKS_DEPS)
CLEAN_FILES += $(addsuffix .inc.gen,$(DOCBOOKS))
CLEAN_FILES += $(addsuffix .inc.merged,$(DOCBOOKS))
$(INC_DIR):
mkdir -p $@
vty/osmo-pcap-%-vty-reference.xml: $(top_builddir)/src/osmo-pcap-% $(INC_DIR)
sed -e "s|@@GENERATED@@|$@.inc|" \
-e "s|@@VARIANT@@|$(notdir $<)|" \
-e "s|@@REV_NUMBER@@|$(VERSION)|" \
-e "s|@@REV_DATE@@|$(shell date +"%dth %B %Y")|" \
-e "s|@@CR_YEAR@@|$(shell date +"%Y")|" \
$(srcdir)/vty/osmo-pcap-vty-reference.xml > $@
vty/osmo-pcap-%-vty-reference.xml.inc: $(top_builddir)/src/osmo-pcap-% \
$(OSMO_GSM_MANUALS_DIR)/common/vty_additions.xml \
$(OSMO_GSM_MANUALS_DIR)/common/chapters/vty.xml \
$(OSMO_GSM_MANUALS_DIR)/vty_reference.xsl \
$(srcdir)/vty/*.xml $(INC_DIR)
# a) Invoke osmo-pcap-% to generate the list of commands first
$< --vty-ref-mode default --vty-ref-xml > "$@.gen"
# ... filter garbage potentially printed by libraries to stdout
sed -i '/^<vtydoc/,$$!d' "$@.gen"
# b) Merge the result of a) with global and local additions
$(OSMO_GSM_MANUALS_DIR)/build/vty_reference_combine.sh \
$(realpath $(OSMO_GSM_MANUALS_DIR)/merge_doc.xsl) "$@.gen" \
$(OSMO_GSM_MANUALS_DIR)/common/vty_additions.xml \
$(srcdir)/vty/vty_additions.xml > "$@.merged"
# c) Convert the result of b) into a valid docbook
xsltproc $(OSMO_GSM_MANUALS_DIR)/vty_reference.xsl "$@.merged" > $@

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML 5.0//EN"
"http://docbook.org/xml/5.0/dtd/docbook.dtd" [
<!ENTITY chapter-vty SYSTEM "./common/chapters/vty.xml" >
<!ENTITY sections-vty SYSTEM "@@GENERATED@@" >
]>
<book>
<info>
<revhistory>
<revision>
<revnumber>v1</revnumber>
<date>@@REV_DATE@@</date>
<authorinitials>s.f.m.c.</authorinitials>
<revremark>Automatic build (@@REV_NUMBER@@)</revremark>
</revision>
</revhistory>
<title>OsmoPCAP VTY Reference</title>
<subtitle>@@VARIANT@@</subtitle>
<copyright>
<year>@@CR_YEAR@@</year>
</copyright>
<legalnotice>
<para>This work is copyright by <orgname>sysmocom - s.f.m.c. GmbH</orgname>. All rights reserved.
</para>
</legalnotice>
</info>
<!-- Main chapters-->
&chapter-vty;
</book>

View File

@ -0,0 +1,2 @@
<vtydoc xmlns='urn:osmocom:xml:libosmocore:vty:doc:1.0'>
</vtydoc>

View File

@ -98,12 +98,41 @@ static void print_help()
printf(" -T --timestamp. Print a timestamp in the debug output.\n");
printf(" -e --log-level number. Set a global loglevel.\n");
printf(" -c --config-file filename The config file to use.\n");
printf("\nVTY reference generation:\n");
printf(" --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n");
printf(" --vty-ref-xml Generate the VTY reference XML output and exit.\n");
}
static void handle_long_options(const char *prog_name, const int long_option)
{
static int vty_ref_mode = VTY_REF_GEN_MODE_DEFAULT;
switch (long_option) {
case 1:
vty_ref_mode = get_string_value(vty_ref_gen_mode_names, optarg);
if (vty_ref_mode < 0) {
fprintf(stderr, "%s: Unknown VTY reference generation "
"mode '%s'\n", prog_name, optarg);
exit(2);
}
break;
case 2:
fprintf(stderr, "Generating the VTY reference in mode '%s' (%s)\n",
get_value_string(vty_ref_gen_mode_names, vty_ref_mode),
get_value_string(vty_ref_gen_mode_desc, vty_ref_mode));
vty_dump_xml_ref_mode(stdout, (enum vty_ref_gen_mode) vty_ref_mode);
exit(0);
default:
fprintf(stderr, "%s: error parsing cmdline options\n", prog_name);
exit(2);
}
}
static void handle_options(int argc, char **argv)
{
while (1) {
int option_index = 0, c;
static int long_option = 0;
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"daemonize", 0, 0, 'D'},
@ -112,6 +141,8 @@ static void handle_options(int argc, char **argv)
{"timestamp", 0, 0, 'T'},
{"log-level", 1, 0, 'e'},
{"config-file", 1, 0, 'c'},
{"vty-ref-mode", 1, &long_option, 1},
{"vty-ref-xml", 0, &long_option, 2},
{0, 0, 0, 0}
};
@ -125,6 +156,9 @@ static void handle_options(int argc, char **argv)
print_usage();
print_help();
exit(0);
case 0:
handle_long_options(argv[0], long_option);
break;
case 'D':
daemonize = 1;
break;
@ -197,6 +231,7 @@ int main(int argc, char **argv)
vty_init(&vty_info);
logging_vty_add_cmds();
osmo_stats_vty_add_cmds();
vty_client_init(tall_cli_ctx);
/* parse options */
handle_options(argc, argv);
@ -226,7 +261,6 @@ int main(int argc, char **argv)
LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate osmo_pcap_client.\n");
exit(1);
}
vty_client_init(pcap_client);
/* initialize the queue */
INIT_LLIST_HEAD(&pcap_client->conns);

View File

@ -108,12 +108,41 @@ static void print_help()
printf(" -T --timestamp. Print a timestamp in the debug output.\n");
printf(" -e --log-level number. Set a global loglevel.\n");
printf(" -c --config-file filename The config file to use.\n");
printf("\nVTY reference generation:\n");
printf(" --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n");
printf(" --vty-ref-xml Generate the VTY reference XML output and exit.\n");
}
static void handle_long_options(const char *prog_name, const int long_option)
{
static int vty_ref_mode = VTY_REF_GEN_MODE_DEFAULT;
switch (long_option) {
case 1:
vty_ref_mode = get_string_value(vty_ref_gen_mode_names, optarg);
if (vty_ref_mode < 0) {
fprintf(stderr, "%s: Unknown VTY reference generation "
"mode '%s'\n", prog_name, optarg);
exit(2);
}
break;
case 2:
fprintf(stderr, "Generating the VTY reference in mode '%s' (%s)\n",
get_value_string(vty_ref_gen_mode_names, vty_ref_mode),
get_value_string(vty_ref_gen_mode_desc, vty_ref_mode));
vty_dump_xml_ref_mode(stdout, (enum vty_ref_gen_mode) vty_ref_mode);
exit(0);
default:
fprintf(stderr, "%s: error parsing cmdline options\n", prog_name);
exit(2);
}
}
static void handle_options(int argc, char **argv)
{
while (1) {
int option_index = 0, c;
static int long_option = 0;
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"daemonize", 0, 0, 'D'},
@ -122,6 +151,8 @@ static void handle_options(int argc, char **argv)
{"timestamp", 0, 0, 'T'},
{"log-level", 1, 0, 'e'},
{"config-file", 1, 0, 'c'},
{"vty-ref-mode", 1, &long_option, 1},
{"vty-ref-xml", 0, &long_option, 2},
{0, 0, 0, 0}
};
@ -135,6 +166,9 @@ static void handle_options(int argc, char **argv)
print_usage();
print_help();
exit(0);
case 0:
handle_long_options(argv[0], long_option);
break;
case 'D':
daemonize = 1;
break;
@ -210,6 +244,7 @@ int main(int argc, char **argv)
vty_init(&vty_info);
logging_vty_add_cmds();
osmo_stats_vty_add_cmds();
vty_server_init(tall_srv_ctx);
/* parse options */
handle_options(argc, argv);
@ -249,7 +284,6 @@ int main(int argc, char **argv)
pcap_server->base_path = talloc_strdup(pcap_server, "./");
pcap_server->max_size = 1073741824;
pcap_server->max_snaplen = DEFAULT_SNAPLEN;
vty_server_init(pcap_server);
if (vty_read_config_file(config_file, NULL) < 0) {
LOGP(DSERVER, LOGL_ERROR,