]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
meson: daemon/kres-gen - fix lua file generation
authorTomas Krizek <tomas.krizek@nic.cz>
Tue, 19 Feb 2019 13:56:37 +0000 (14:56 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 12 Mar 2019 09:43:33 +0000 (10:43 +0100)
daemon/lua/kres-gen.sh
daemon/lua/meson.build
scripts/gen-cdefs.sh

index e87ed2dfea9b499651a671ac927fe202a807220e..1f626beb1194c2c346bab5b91b553eb393ce5684 100755 (executable)
@@ -1,17 +1,22 @@
 #!/bin/bash
-set -o pipefail -o errexit
+# Run with "ninja kres-gen" to re-generate kres-gen.lua
+set -o pipefail -o errexit -o nounset
 
 cd "$(dirname ${0})"
 CDEFS="../../scripts/gen-cdefs.sh"
+LIBKRES="${MESON_BUILD_ROOT}/lib/libkres.so"
 
-# Write to .kres-gen.lua.tmp instead of STDOUT
-exec 1<&-
-exec 1<>.kres-gen.lua.tmp
-err_handle() {
+# Write to kres-gen.lua instead of stdout
+mv kres-gen.lua{,.bak} ||:
+exec 1>&-
+exec 1<>kres-gen.lua
+
+restore() {
+    exec 1>&-
+    mv kres-gen.lua{.bak,} ||:
     (>&2 echo "Failed to re-generate kres-gen.lua! Missing debugsymbols?")
-    rm -f .kres-gen.lua.tmp
 }
-trap err_handle ERR INT TERM
+trap restore ERR INT TERM
 
 ### Dev's guide
 #
@@ -52,7 +57,7 @@ typedef void (*trace_log_f) (const struct kr_query *, const char *, const char *
 typedef void (*trace_callback_f)(struct kr_request *);
 "
 
-${CDEFS} libkres types <<-EOF
+${CDEFS} ${LIBKRES} types <<-EOF
        knot_section_t
        knot_rrinfo_t
        knot_dname_t
@@ -61,13 +66,13 @@ ${CDEFS} libkres types <<-EOF
 EOF
 
 genResType() {
-       echo "$1" | ${CDEFS} libkres types
+       echo "$1" | ${CDEFS} ${LIBKRES} types
 }
 
 # No simple way to fixup this rename in ./kres.lua AFAIK.
 genResType "knot_rrset_t" | sed 's/\<owner\>/_owner/; s/\<ttl\>/_ttl/'
 
-${CDEFS} libkres types <<-EOF
+${CDEFS} ${LIBKRES} types <<-EOF
        knot_pkt_t
        knot_edns_options_t
        knot_pktsection_t
@@ -141,7 +146,7 @@ ${CDEFS} libknot functions <<-EOF
 EOF
 
 ## libkres API
-${CDEFS} libkres functions <<-EOF
+${CDEFS} ${LIBKRES} functions <<-EOF
 # Resolution request
        kr_resolve_plan
        kr_resolve_pool
@@ -228,7 +233,7 @@ EOF
 
 printf "]]\n"
 
-mv .kres-gen-lua.tmp kres-gen.lua
-(>&2 echo "Successfully re-generated "${PWD}/kres-gen.lua")
+rm kres-gen.lua.bak ||:
+(>&2 echo "Successfully re-generated ${PWD}/kres-gen.lua")
 
 exit 0
index 8ea6887773d5178f37d765e446d1ceb80463274f..54ce16b9f3bf12ea606fcc2ca87bdfc32b641221 100644 (file)
@@ -20,6 +20,11 @@ config_lua = configure_file(
   configuration: ta_config,
 )
 
+run_target(  # run manually to re-generate kres-gen.lua
+  'kres-gen',
+  command: find_program('./kres-gen.sh'),
+)
+
 # install daemon lua sources
 install_data([
     config_lua,
index 0627fa40bbc73fc7170edf7be297c546702c747f..ae7ed9fcaadafac4b13e8d06b23813042b3bfa5e 100755 (executable)
@@ -26,7 +26,7 @@ fi
 case "$1" in
        libknot) library="$(PATH="$(pkg-config libknot --variable=libdir)" command -v "$1.so")" ;;
        libzscanner) library="$(PATH="$(pkg-config libzscanner --variable=libdir)" command -v "$1.so")" ;;
-       *) library="$(PATH="$(pwd)/lib" command -v "$1.so")"
+       *) library="$(command -v "$1")"  # use absolute path to library
 esac
 
 if [ -z "$library" ]; then
@@ -60,6 +60,8 @@ grep -v '^#\|^$' | while read -r ident; do
        output="$(echo "$output" | sed 's/\buint\b/unsigned int/g')"
        # GDB 8.2+ added source line prefix to output
        output="$(echo "$output" | sed 's/^[0-9]\+:[[:space:]]*//g')"
+       # use tabs instead of spaces
+       output="$(echo "$output" | sed 's/    /\t/g')"
 
        # abort on empty output
        if [ -z "$(echo "$output" | tr -d "\n;")" ]; then