If possible, fail build on option doc mismatch

This adds a bunch of steps to the build process that verify
cyclonedds.xsd, cyclonedds.rnc and options.md as committed match the
configuration tables in the source.

The cyclonedds.rnc and options.md depend on having perl available,
cyclonedds.xsd on having Java and the "trang" conversion tool.  Not
having these tools simply means some of the checks are skipped.

Signed-off-by: Erik Boasson <eb@ilities.com>

makernc: more forgiving of line endings input

Signed-off-by: Erik Boasson <eb@ilities.com>

Ignore line endings comparing cyclonedds XSD, RNC

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2019-11-01 14:54:27 +01:00 committed by eboasson
parent c642f5676a
commit ff79941aeb
3 changed files with 48 additions and 2 deletions

View file

@ -8,5 +8,43 @@
# http://www.eclipse.org/org/documents/edl-v10.php.
#
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
add_subdirectory(manual)
include(FindPerl)
if(PERL_FOUND)
add_custom_command(
OUTPUT
options.md cyclonedds.rnc
COMMAND
${PERL_EXECUTABLE} -w "${CMAKE_CURRENT_SOURCE_DIR}/makernc.pl" "${CMAKE_CURRENT_SOURCE_DIR}/../src/core/ddsi/src/q_config.c" options.md cyclonedds.rnc
COMMAND
${PERL_EXECUTABLE} -w "${CMAKE_CURRENT_SOURCE_DIR}/compare.pl" options.md "${CMAKE_CURRENT_SOURCE_DIR}/manual/options.md"
COMMAND
${PERL_EXECUTABLE} -w "${CMAKE_CURRENT_SOURCE_DIR}/compare.pl" cyclonedds.rnc "${CMAKE_CURRENT_SOURCE_DIR}/../etc/cyclonedds.rnc"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/makernc.pl"
"${CMAKE_CURRENT_SOURCE_DIR}/../src/core/ddsi/src/q_config.c")
add_custom_target(options_doc ALL DEPENDS "options.md" "cyclonedds.rnc")
find_package(Java COMPONENTS Runtime)
if(JAVA_FOUND AND EXISTS "${TRANG_PATH}" OR EXISTS "$ENV{TRANG}")
if(NOT EXISTS "${TRANG_PATH}" AND EXISTS "$ENV{TRANG}")
message(STATUS "Setting TRANG_PATH to $ENV{TRANG}")
set(TRANG_PATH "$ENV{TRANG}" CACHE FILEPATH "Location of 'trang' for converting XML schemas" FORCE)
endif()
add_custom_command(
OUTPUT
cyclonedds.xsd
COMMAND
${Java_JAVA_EXECUTABLE} -jar "${TRANG_PATH}" -I rnc -O xsd cyclonedds.rnc cyclonedds.xsd
COMMAND
${PERL_EXECUTABLE} -w "${CMAKE_CURRENT_SOURCE_DIR}/compare.pl" cyclonedds.xsd "${CMAKE_CURRENT_SOURCE_DIR}/../etc/cyclonedds.xsd"
DEPENDS
"cyclonedds.rnc")
add_custom_target(options_xsd ALL DEPENDS "cyclonedds.xsd")
else()
message(STATUS "Java or not trang not found: not converting/checking RNC to XSD")
endif()
else()
message(STATUS "perl not found: not generating/checking options documentation and RNC")
endif()
add_subdirectory(manual)

8
docs/compare.pl Normal file
View file

@ -0,0 +1,8 @@
open A, "< $ARGV[0]" or die "can't open $ARGV[0]";
open B, "< $ARGV[1]" or die "can't open $ARGV[1]";
while (defined ($a = <A>) && defined ($b = <B>)) {
$a =~ s/[\r\n]+$//s;
$b =~ s/[\r\n]+$//s;
exit 1 unless $a eq $b;
}
exit 0;

View file

@ -495,7 +495,7 @@ sub read_config {
my @stk = (); # stack of conditional nesting, for each: copy/discard/ignore
open FH, "<", $input or die "can't open $input\n";
while (<FH>) {
chomp;
s/[\r\n]+$//s;
# ignore parts guarded by #if/#ifdef/#if!/#ifndef if $incl says so
if (/^\s*\#\s*if(n?def|\s*!)?\s*([A-Za-z_][A-Za-z_0-9]*)\s*(?:\/(?:\/.*|\*.*?\*\/)\s*)?$/) {