From: Francis Dupont Date: Thu, 20 Feb 2025 00:02:16 +0000 (+0100) Subject: [#3730] Added generate parser X-Git-Tag: Kea-2.7.7~193 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e46ce7668dc6e576833c334e231ac0c12235e4ff;p=thirdparty%2Fkea.git [#3730] Added generate parser --- diff --git a/cd-and-run.sh b/cd-and-run.sh new file mode 100755 index 0000000000..9fe8958b7f --- /dev/null +++ b/cd-and-run.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +cd "$1" || exit 1 +shift +exec "$@" diff --git a/doc/devel/make-devel.sh.in b/doc/devel/make-devel.sh.in index d3bc95d5ff..9fc1c2da5f 100755 --- a/doc/devel/make-devel.sh.in +++ b/doc/devel/make-devel.sh.in @@ -2,8 +2,7 @@ set -v -cd @srcdir@ || exit 1 mkdir -p @builddir@/html -(cat @srcdir@/Doxyfile; echo PROJECT_NUMBER=@PACKAGE_VERSION@) | doxygen - > @builddir@/html/doxygen.log 2> @builddir@/html/doxygen-error.log +(cat Doxyfile; echo PROJECT_NUMBER=@PACKAGE_VERSION@) | doxygen - > @builddir@/html/doxygen.log 2> @builddir@/html/doxygen-error.log echo "$(grep -c ': warning:' @builddir@/html/doxygen-error.log)" warnings/errors detected. diff --git a/doc/devel/meson.build b/doc/devel/meson.build index 96feeb518f..1e344fd92d 100644 --- a/doc/devel/meson.build +++ b/doc/devel/meson.build @@ -2,13 +2,15 @@ if not doxygen_exe.found() subdir_done() endif +current_build_dir = meson.current_build_dir() +current_source_dir = meson.current_source_dir() make_devel_conf_data = configuration_data() -make_devel_conf_data.set('builddir', meson.current_build_dir()) -make_devel_conf_data.set('srcdir', meson.current_source_dir()) +make_devel_conf_data.set('builddir', current_build_dir) make_devel_conf_data.set('PACKAGE_VERSION', project_version) -make_devel = configure_file( +configure_file( input: 'make-devel.sh.in', output: 'make-devel.sh', configuration: make_devel_conf_data, ) -run_target('make-devel', command: [make_devel]) +make_devel = f'@current_build_dir@/make-devel.sh' +run_target('make-devel', command: [CD_AND_RUN, current_source_dir, make_devel]) diff --git a/meson.build b/meson.build index fd4ec04a9e..2f4dacf83c 100644 --- a/meson.build +++ b/meson.build @@ -156,8 +156,8 @@ message(f'Detected system "@SYSTEM@".') #### Programs python_exe = find_program('python3', 'python', required: false) -flex_exe = find_program('flex', required: false) -bison_exe = find_program('bison', required: false) +flex_exe = find_program('flex', version: '>=2.6.4', required: false) +bison_exe = find_program('bison', version: '>=3.3.0', required: false) awk_exe = find_program('gawk', 'awk', required: false) doxygen_exe = find_program('doxygen', required: false) sphinx_exe = find_program('sphinx-build', 'sphinx-build-3', required: false) @@ -169,6 +169,20 @@ pip_compile_exe = find_program('pip-compile', required: false) install_exe = find_program('install', required: true) valgrind_exe = find_program('valgrind', required: false) +if python_exe.found() + PYTHON = python_exe.full_path() +endif +if flex_exe.found() + FLEX = flex_exe.full_path() +endif +if bison_exe.found() + BISON = bison_exe.full_path() +endif +if awk_exe.found() + AWK = awk_exe.full_path() +endif +CD_AND_RUN = f'@TOP_SOURCE_DIR@/cd-and-run.sh' + #### Dependencies boost = dependency('boost', version: '>=1.66') @@ -495,7 +509,7 @@ report_conf_data.set('LD_ID', cpp.get_linker_id()) report_conf_data.set('LD_ARGS', ' '.join(link_args)) if python_exe.found() report_conf_data.set('HAVE_PYTHON', 'yes') - report_conf_data.set('PYTHON_PATH', python_exe.full_path()) + report_conf_data.set('PYTHON_PATH', PYTHON) result = run_command( python_exe, '-c', @@ -580,12 +594,12 @@ else report_conf_data.set('LOG4CPLUS_VERSION', log4cplus.version()) endif if flex_exe.found() - report_conf_data.set('FLEX', flex_exe.full_path()) + report_conf_data.set('FLEX', FLEX) else report_conf_data.set('FLEX', 'unknown') endif if bison_exe.found() - report_conf_data.set('BISON', bison_exe.full_path()) + report_conf_data.set('BISON', BISON) else report_conf_data.set('BISON', 'unknown') endif @@ -670,6 +684,7 @@ config_report = custom_target( LIBS_BUILT_SO_FAR = [] TARGETS_GEN_MESSAGES = [] +TARGETS_GEN_PARSER = [] subdir('tools') subdir('src') subdir('fuzz') @@ -679,6 +694,7 @@ if have_premium endif alias_target('all-targets-gen-messages', TARGETS_GEN_MESSAGES) +alias_target('all-targets-gen-parser', TARGETS_GEN_PARSER) top_docs = [ 'AUTHORS', diff --git a/src/bin/agent/meson.build b/src/bin/agent/meson.build index dc7731209f..89e24e39d7 100644 --- a/src/bin/agent/meson.build +++ b/src/bin/agent/meson.build @@ -25,11 +25,43 @@ executable( ) subdir('tests') +current_source_dir = meson.current_source_dir() if HAS_KEA_MSG_COMPILER - current_source_dir = meson.current_source_dir() target_gen_messages = run_target( 'src-bin-agent-ca_messages', command: [kea_msg_compiler, f'@current_source_dir@/ca_messages.mes'], ) TARGETS_GEN_MESSAGES += [target_gen_messages] endif + +if flex_exe.found() and bison_exe.found() + target_parser = run_target( + 'src-bin-agent-parser', + command: [ + CD_AND_RUN, + current_source_dir, + BISON, + '-Wno-yacc', + '--defines=agent_parser.h', + '--report=all', + '--report-file=agent_parser.report', + '-o', + 'agent_parser.cc', + 'agent_parser.yy', + ], + ) + target_lexer = run_target( + 'src-bin-agent-lexer', + command: [ + CD_AND_RUN, + current_source_dir, + FLEX, + '--prefix', + 'agent_', + '-o', + 'agent_lexer.cc', + 'agent_lexer.ll', + ], + ) + TARGETS_GEN_PARSER += [target_parser, target_lexer] +endif diff --git a/src/bin/d2/meson.build b/src/bin/d2/meson.build index b5abd2f79a..a641a597a7 100644 --- a/src/bin/d2/meson.build +++ b/src/bin/d2/meson.build @@ -28,3 +28,36 @@ executable( link_with: [d2_lib] + LIBS_BUILT_SO_FAR, ) subdir('tests') + +if flex_exe.found() and bison_exe.found() + current_source_dir = meson.current_source_dir() + target_parser = run_target( + 'src-bin-d2-parser', + command: [ + CD_AND_RUN, + current_source_dir, + BISON, + '-Wno-yacc', + '--defines=d2_parser.h', + '--report=all', + '--report-file=d2_parser.report', + '-o', + 'd2_parser.cc', + 'd2_parser.yy', + ], + ) + target_lexer = run_target( + 'src-bin-d2-lexer', + command: [ + CD_AND_RUN, + current_source_dir, + FLEX, + '--prefix', + 'd2_parser_', + '-o', + 'd2_lexer.cc', + 'd2_lexer.ll', + ], + ) + TARGETS_GEN_PARSER += [target_parser, target_lexer] +endif diff --git a/src/bin/dhcp4/meson.build b/src/bin/dhcp4/meson.build index d8084ca743..4303513cd1 100644 --- a/src/bin/dhcp4/meson.build +++ b/src/bin/dhcp4/meson.build @@ -24,11 +24,43 @@ executable( ) subdir('tests') +current_source_dir = meson.current_source_dir() if HAS_KEA_MSG_COMPILER - current_source_dir = meson.current_source_dir() target_gen_messages = run_target( 'src-bin-dhcp4-dhcp4_messages', command: [kea_msg_compiler, f'@current_source_dir@/dhcp4_messages.mes'], ) TARGETS_GEN_MESSAGES += [target_gen_messages] endif + +if flex_exe.found() and bison_exe.found() + target_parser = run_target( + 'src-bin-dhcp4-parser', + command: [ + CD_AND_RUN, + current_source_dir, + BISON, + '-Wno-yacc', + '--defines=dhcp4_parser.h', + '--report=all', + '--report-file=dhcp4_parser.report', + '-o', + 'dhcp4_parser.cc', + 'dhcp4_parser.yy', + ], + ) + target_lexer = run_target( + 'src-bin-dhcp4-lexer', + command: [ + CD_AND_RUN, + current_source_dir, + FLEX, + '--prefix', + 'parser4_', + '-o', + 'dhcp4_lexer.cc', + 'dhcp4_lexer.ll', + ], + ) + TARGETS_GEN_PARSER += [target_parser, target_lexer] +endif diff --git a/src/bin/dhcp6/meson.build b/src/bin/dhcp6/meson.build index 9ea8ed6209..e1a8ac89ff 100644 --- a/src/bin/dhcp6/meson.build +++ b/src/bin/dhcp6/meson.build @@ -25,11 +25,43 @@ executable( ) subdir('tests') +current_source_dir = meson.current_source_dir() if HAS_KEA_MSG_COMPILER - current_source_dir = meson.current_source_dir() target_gen_messages = run_target( 'src-bin-dhcp6-dhcp6_messages', command: [kea_msg_compiler, f'@current_source_dir@/dhcp6_messages.mes'], ) TARGETS_GEN_MESSAGES += [target_gen_messages] endif + +if flex_exe.found() and bison_exe.found() + target_parser = run_target( + 'src-bin-dhcp6-parser', + command: [ + CD_AND_RUN, + current_source_dir, + BISON, + '-Wno-yacc', + '--defines=dhcp6_parser.h', + '--report=all', + '--report-file=dhcp6_parser.report', + '-o', + 'dhcp6_parser.cc', + 'dhcp6_parser.yy', + ], + ) + target_lexer = run_target( + 'src-bin-dhcp6-lexer', + command: [ + CD_AND_RUN, + current_source_dir, + FLEX, + '--prefix', + 'parser6_', + '-o', + 'dhcp6_lexer.cc', + 'dhcp6_lexer.ll', + ], + ) + TARGETS_GEN_PARSER += [target_parser, target_lexer] +endif diff --git a/src/bin/netconf/meson.build b/src/bin/netconf/meson.build index 813c1a6e11..24c93a12e1 100644 --- a/src/bin/netconf/meson.build +++ b/src/bin/netconf/meson.build @@ -38,8 +38,8 @@ executable( subdir('tests') +current_source_dir = meson.current_source_dir() if HAS_KEA_MSG_COMPILER - current_source_dir = meson.current_source_dir() target_gen_messages = run_target( 'src-bin-netconf-netconf_messages', command: [ @@ -49,3 +49,35 @@ if HAS_KEA_MSG_COMPILER ) TARGETS_GEN_MESSAGES += [target_gen_messages] endif + +if flex_exe.found() and bison_exe.found() + target_parser = run_target( + 'src-bin-netconf-parser', + command: [ + CD_AND_RUN, + current_source_dir, + BISON, + '-Wno-yacc', + '--defines=netconf_parser.h', + '--report=all', + '--report-file=netconf_parser.report', + '-o', + 'netconf_parser.cc', + 'netconf_parser.yy', + ], + ) + target_lexer = run_target( + 'src-bin-netconf-lexer', + command: [ + CD_AND_RUN, + current_source_dir, + FLEX, + '--prefix', + 'netconf_', + '-o', + 'netconf_lexer.cc', + 'netconf_lexer.ll', + ], + ) + TARGETS_GEN_PARSER += [target_parser, target_lexer] +endif diff --git a/src/bin/shell/meson.build b/src/bin/shell/meson.build index a193aebd96..f86e4e9211 100644 --- a/src/bin/shell/meson.build +++ b/src/bin/shell/meson.build @@ -3,7 +3,7 @@ if not python_exe.found() endif kea_shell_conf_data = configuration_data() -kea_shell_conf_data.set('PYTHON', python_exe.full_path()) +kea_shell_conf_data.set('PYTHON', PYTHON) kea_shell_conf_data.set('PACKAGE_VERSION', project_version) kea_shell_conf_data.set('EXTENDED_VERSION', project_version + ' (tarball)') diff --git a/src/bin/shell/tests/meson.build b/src/bin/shell/tests/meson.build index 8fe1d36935..334b9cb372 100644 --- a/src/bin/shell/tests/meson.build +++ b/src/bin/shell/tests/meson.build @@ -3,7 +3,7 @@ if not gtest.found() endif shell_tests_conf_data = configuration_data() -shell_tests_conf_data.set('PYTHON', python_exe.full_path()) +shell_tests_conf_data.set('PYTHON', PYTHON) shell_tests_conf_data.set('abs_top_builddir', TOP_BUILD_DIR) shell_tests_conf_data.set('abs_top_srcdir', TOP_SOURCE_DIR) shell_unittest = configure_file( diff --git a/src/lib/eval/meson.build b/src/lib/eval/meson.build index 5df98aba27..def72b171c 100644 --- a/src/lib/eval/meson.build +++ b/src/lib/eval/meson.build @@ -27,11 +27,41 @@ kea_eval_headers = [ ] install_headers(kea_eval_headers, preserve_path: true, subdir: 'kea/eval') +current_source_dir = meson.current_source_dir() if HAS_KEA_MSG_COMPILER - current_source_dir = meson.current_source_dir() target_gen_messages = run_target( 'src-lib-eval-eval_messages', command: [kea_msg_compiler, f'@current_source_dir@/eval_messages.mes'], ) TARGETS_GEN_MESSAGES += [target_gen_messages] endif + +if flex_exe.found() and bison_exe.found() + target_parser = run_target( + 'src-lib-eval-parser', + command: [ + CD_AND_RUN, + current_source_dir, + BISON, + '-Wno-yacc', + '--defines=parser.h', + '-o', + 'parser.cc', + 'parser.yy', + ], + ) + target_lexer = run_target( + 'src-lib-eval-lexer', + command: [ + CD_AND_RUN, + current_source_dir, + FLEX, + '--prefix', + 'eval', + '-o', + 'lexer.cc', + 'lexer.ll', + ], + ) + TARGETS_GEN_PARSER += [target_parser, target_lexer] +endif diff --git a/src/lib/util/python/meson.build b/src/lib/util/python/meson.build index 37634f8c74..3f5996b865 100644 --- a/src/lib/util/python/meson.build +++ b/src/lib/util/python/meson.build @@ -4,7 +4,7 @@ endif configure_file(input: 'const2hdr.py', output: 'const2hdr.py', copy: true) util_python_conf_data = configuration_data() -util_python_conf_data.set('PYTHON', python_exe.full_path()) +util_python_conf_data.set('PYTHON', PYTHON) configure_file( input: 'gen_wiredata.py.in', output: 'gen_wiredata.py', diff --git a/tools/meson.build b/tools/meson.build index 23f6efa9dc..ca59455090 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -6,12 +6,12 @@ tools_conf_data.set('exec_prefix', '${prefix}') tools_conf_data.set('libdir', '${exec_prefix}/' + get_option('libdir')) tools_conf_data.set('SEP', '+') if bison_exe.found() - tools_conf_data.set('YACC', bison_exe.full_path()) + tools_conf_data.set('YACC', BISON) else tools_conf_data.set('YACC', 'bison') endif if awk_exe.found() - tools_conf_data.set('AWK', awk_exe.full_path()) + tools_conf_data.set('AWK', AWK) else tools_conf_data.set('AWK', 'awk') endif