From 26baac9f33cb4cf3c1c609c56c7a2d3a715efb67 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 6 Dec 2024 16:42:19 +0100 Subject: [PATCH 1/3] rec: generate metrics files (also) where meson expects them This avoids unneccesary regeneration of files --- pdns/recursordist/meson.build | 2 +- pdns/recursordist/metrics.py | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pdns/recursordist/meson.build b/pdns/recursordist/meson.build index 2cb4799708e4..b443795567d3 100644 --- a/pdns/recursordist/meson.build +++ b/pdns/recursordist/meson.build @@ -274,7 +274,7 @@ py = import('python') python = py.find_installation('python3', required: true) metricfiles = custom_target( - command: [python, '@INPUT0@', '@SOURCE_ROOT@'], + command: [python, '@INPUT0@', '@SOURCE_ROOT@', '@BUILD_ROOT@'], input: metric_sources, output: [ 'rec-metrics-gen.h', diff --git a/pdns/recursordist/metrics.py b/pdns/recursordist/metrics.py index 469ecebad026..78aa1e552c30 100644 --- a/pdns/recursordist/metrics.py +++ b/pdns/recursordist/metrics.py @@ -1,17 +1,21 @@ import os import sys +import shutil # default: 'type': uint64 # ptype: "'counter' (vs gauge') srcdir = '.' -if len(sys.argv) == 2: - print("metrics.py: using srcdir from arguments") +builddir = '.' +if len(sys.argv) == 3: + print("metrics.py: using srcdir and builddir from arguments") srcdir = sys.argv[1] + builddir = sys.argv[2] print("Generating metrics related files") print("metrics.py cwd: " + os.getcwd()) print("metrics.py srcdir: " + srcdir + " = " + os.path.realpath(srcdir)) +print("metrics.py builddir: " + builddir + " = " + os.path.realpath(builddir)) def dedashForSNMP(name): cap = False @@ -31,6 +35,9 @@ def dedashForSNMP(name): with open(srcdir + '/metrics_table.py', mode='r', encoding="utf-8") as file: table = eval(file.read()) +# +# We create various files in the srcdir but copy them into the buildir if neeed to satisfy meson +# with open(srcdir + '/rec-oids-gen.h', 'w', encoding='utf-8') as file: file.write('// THIS IS A GENERATED FILE. DO NOT EDIT. SOURCE metrics.py AND metrics_table.py\n') for entry in table: @@ -44,6 +51,8 @@ def dedashForSNMP(name): file.write(f'static const oid10 {name}OID = {{RECURSOR_STATS_OID, {snmp}}};\n') if 'ifdef' in entry: file.write(f'#endif\n') +if srcdir != builddir: + shutil.copy(srcdir + '/rec-oids-gen.h', builddir) with open(srcdir + '/rec-snmp-gen.h', 'w', encoding='utf-8') as file: file.write('// THIS IS A GENERATED FILE. DO NOT EDIT. SOURCE metrics.py AND metrics_table.py\n') @@ -58,6 +67,8 @@ def dedashForSNMP(name): file.write(f'registerCounter64Stat("{name}", {dname}OID);\n') if 'ifdef' in entry: file.write(f'#endif\n') +if srcdir != builddir: + shutil.copy(srcdir + '/rec-snmp-gen.h', builddir) with open(srcdir + '/rec-prometheus-gen.h', 'w', encoding='utf-8') as file: file.write('// THIS IS A GENERATED FILE. DO NOT EDIT. SOURCE metrics.py AND metrics_table.py\n') @@ -75,6 +86,8 @@ def dedashForSNMP(name): if 'ptype' in entry: ptype = entry['ptype'] file.write(f'{{"{name}", MetricDefinition(PrometheusMetricType::{ptype}, "{desc}")}},\n') +if srcdir != builddir: + shutil.copy(srcdir + '/rec-prometheus-gen.h', builddir) with open(srcdir + '/rec-metrics-gen.h', 'w', encoding='utf-8') as file: file.write('// THIS IS A GENERATED FILE. DO NOT EDIT. SOURCE metrics.py AND metrics_table.py\n') @@ -94,6 +107,8 @@ def dedashForSNMP(name): file.write(f'}}\n') if 'ifdef' in entry: file.write(f'#endif\n') +if srcdir != builddir: + shutil.copy(srcdir + '/rec-metrics-gen.h', builddir) if os.path.isdir(srcdir + '/docs'): with open(srcdir + '/docs/rec-metrics-gen.rst', 'w', encoding='utf-8') as file: @@ -155,9 +170,11 @@ def dedashForSNMP(name): str2 += f',\n {name}' -with open(srcdir + '/RECURSOR-MIB.in', mode='r', encoding='UTF-8') as file: +with open(srcdir + '/RECURSOR-MIB.in', mode='r', encoding='utf-8') as file: text = file.read() text = text.replace('REPL_OBJECTS1', str1) text = text.replace('REPL_OBJECTS2', str2) with open(srcdir + '/RECURSOR-MIB.txt', 'w', encoding='utf-8') as file2: file2.write(text) +if srcdir != builddir: + shutil.copy(srcdir + '/RECURSOR-MIB.txt', builddir) From a0d44dc1b29c1c55bbca244d811f309e1da39bf0 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 9 Dec 2024 09:28:33 +0100 Subject: [PATCH 2/3] Update pdns/recursordist/metrics.py Co-authored-by: Miod Vallat --- pdns/recursordist/metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdns/recursordist/metrics.py b/pdns/recursordist/metrics.py index 78aa1e552c30..cf565f8fc066 100644 --- a/pdns/recursordist/metrics.py +++ b/pdns/recursordist/metrics.py @@ -36,7 +36,7 @@ def dedashForSNMP(name): table = eval(file.read()) # -# We create various files in the srcdir but copy them into the buildir if neeed to satisfy meson +# We create various files in the srcdir but copy them into the buildir if needed to satisfy meson # with open(srcdir + '/rec-oids-gen.h', 'w', encoding='utf-8') as file: file.write('// THIS IS A GENERATED FILE. DO NOT EDIT. SOURCE metrics.py AND metrics_table.py\n') From d0992419026904596f472cdf683f4df527568023 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 10 Dec 2024 10:16:44 +0100 Subject: [PATCH 3/3] Add FIXME comment --- pdns/recursordist/metrics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pdns/recursordist/metrics.py b/pdns/recursordist/metrics.py index cf565f8fc066..3d11b68973df 100644 --- a/pdns/recursordist/metrics.py +++ b/pdns/recursordist/metrics.py @@ -36,7 +36,8 @@ def dedashForSNMP(name): table = eval(file.read()) # -# We create various files in the srcdir but copy them into the buildir if needed to satisfy meson +# We create various files in the srcdir but copy them into the builddir if needed to satisfy meson +# FIXME: only generate in builddir once autotools have been dropped # with open(srcdir + '/rec-oids-gen.h', 'w', encoding='utf-8') as file: file.write('// THIS IS A GENERATED FILE. DO NOT EDIT. SOURCE metrics.py AND metrics_table.py\n')