[PATCH] libtracefs: improve reproducibility

Oleh Matiusha <[email protected]> Mon, 24 Mar 2025 16:59:11 -0700
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
Currently, the files generated by flex & bison are present among sources
to ease builds for people lacking these tools. However, make rules for them
are also present in Makefile, and while fetching source code, targets might
or might not be created with timestamps older than their prerequisites.
This means in build environments with flex and/or bison available, the
decision whether headers will be regenerated from sqlhist.l and sqlhist.y
is random. Since more fresh versions of these tools make different outputs,
this breaks build determinism, which is essential for people wanting their
builds to be reproducible. Assuming those who have their own flex & bison
want headers to be generated by fresh versions, I modified Makefile to check
for them and add corresponding targets to .PHONY to force re-generation,
retaining fallback option in case of their absence.

Signed-off-by: Oleh Matiusha <[email protected]>
---
 src/Makefile | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/Makefile b/src/Makefile
index be81059..aa0f280 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -29,6 +29,14 @@ OBJS += sqlhist-lex.o
 OBJS += sqlhist.tab.o
 OBJS += tracefs-sqlhist.o
 
+# update lexer and parser headers if tools available
+ifneq ($(shell command -v bison),)
+.PHONY: sqlhist.tab.c
+endif
+ifneq ($(shell command -v flex),)
+.PHONY: sqlhist-lex.c
+endif
+
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
 
 $(LIBTRACEFS_STATIC): $(OBJS)
-- 
2.35.6