Skip to contentSkip to conversation

libtracefs: Update sqlhist bison and flex

PATCH New Steven Rostedt 1 participant 3 messages Apr 4, 2025 Kbuild

lore
Share & tools
lore
#0 lore raw

cover libtracefs: Update sqlhist bison and flex

From: "Steven Rostedt (Google)" <[email protected]>

The way that git doesn't save timestamps of files causes the flex and bison source to regenerate the flex and bison output files. This can be annoying when the source of the flex and bison files are not updated. Worse, it can cause the build to fail if the system doesn't have flex nor bison.

Instead add a new make target: sqlhist_remake

The bison and flex utilities will only be run when this target is specified. Otherwise it will not build the output file from bison nor flex.

Steven Rostedt (Google) (2):
libtracefs: Add make sqlhist_remake to run bison and flex
libtracefs: Rerun bison and flex via make sqlhist_remake

 Makefile          |   3 +
 src/Makefile      |  14 +-
 src/sqlhist-lex.c |  66 +++---
 src/sqlhist.l     |   2 +
 src/sqlhist.tab.c | 504 +++++++++++++++++++---------------------------
 src/sqlhist.tab.h |  14 +-
 src/sqlhist.y     |   1 +
 7 files changed, 262 insertions(+), 342 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/2 libtracefs: Add make sqlhist_remake to run bison and flex

From: "Steven Rostedt (Google)" <[email protected]>

Because git tends to not maintain timestamps of files, the sqlhist.y and sqlhist.l can end up having an later timestamp than the files they produce. This triggers bison and flex to be run and recreate the files sqlhist.tab.h, sqlhist.tab.c and sqlhist-lex.c.

At best, this causes git to see the differences, at worse, the system may not even have bison or flex and the build fails.

Add a new make target: make sqlhist_remake

This new target will run the bison and flex portions of the build. It only needs to be run if the files sqlhist.y or sqlhist.l are modified.

---
 Makefile      |  3 +++
 src/Makefile  | 14 ++++++++------
 src/sqlhist.l |  2 ++
 src/sqlhist.y |  1 +
 4 files changed, 14 insertions(+), 6 deletions(-)
Makefile +3 -0
index bd5c76bcd4f0..6e8022609ee7 100644
@@ -400,6 +400,9 @@ sqlhist: samples/sqlhist
 samples: libtracefs.a force
 	$(Q)$(call descend,$(src)/samples,all)
 
+sqlhist_remake:
+	$(Q)$(call descend,$(src)/src,sqlhist_remake)
+
 clean: clean_meson
 	$(Q)$(call descend_clean,utest)
 	$(Q)$(call descend_clean,src)
src/Makefile +8 -6
index be81059ce10a..d981d802f8b1 100644
@@ -46,18 +46,20 @@ $(LIBTRACEFS_SHARED_SO): $(LIBTRACEFS_SHARED_VERSION)
 libtracefs.so: $(LIBTRACEFS_SHARED_SO)
 
 # bison will create both sqlhist.tab.c and sqlhist.tab.h
-sqlhist.tab.h:
-sqlhist.tab.c: sqlhist.y sqlhist.tab.h
-	bison --debug -v --report-file=bison.report -d -o $@ $<
+sqlhist.tab_gen.h:
+sqlhist.tab_gen.c: sqlhist.y sqlhist.tab.h
+	bison --debug -v --report-file=bison.report -d -o $(subst _gen,,$@) $<
 
-sqlhist-lex.c: sqlhist.l sqlhist.tab.c
-	flex -o $@ $<
+sqlhist-lex_gen.c: sqlhist.l sqlhist.tab.c
+	flex -o $(subst _gen,,$@) $<
 
 $(bdir)/%.o: %.c
 	$(Q)$(call do_fpic_compile)
 
 tracefs-sqlhist.o: sqlhist.tab.h
 
+sqlhist_remake: sqlhist.tab_gen.c sqlhist-lex_gen.c
+
 $(OBJS): | $(bdir)
 
 clean:
@@ -67,4 +69,4 @@ clean:
 
 $(bdir)/tracefs-sqlhist.o tracefs-sqlhist.o: sqlhist.tab.h
 
-.PHONY: $(LIBTRACEFS_SHARED_SO) $(LIBTRACEFS_STATIC)
+.PHONY: $(LIBTRACEFS_SHARED_SO) $(LIBTRACEFS_STATIC) sqlhist.tab_gen.c sqlhist-lex_gen.c
src/sqlhist.l +2 -0
index 86e156e52ff7..8b22049a067b 100644
@@ -1,6 +1,8 @@
 %{
 /* code here */
 
+/* If you change this file, run: make sqlhist_remake */
+
 #include <stdarg.h>
 #include "sqlhist-parse.h"
 
src/sqlhist.y +1 -0
index 7caa364da28d..c35a1a37f8ce 100644
@@ -1,4 +1,5 @@
 %{
+/* If you change this file, run: make sqlhist_remake */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
Signature · 1 line
2.47.2
#2 lore raw

PATCH 2/2 libtracefs: Rerun bison and flex via make sqlhist_remake

In reply to Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

Update the bison and flex code with the latest bison and flex from Debian. This uses the new make sqlhist_remake option and includes the added comments that were added to sqlhist.y and sqlhist.l.

---
 src/sqlhist-lex.c |  66 +++---
 src/sqlhist.tab.c | 504 +++++++++++++++++++---------------------------
 src/sqlhist.tab.h |  14 +-
 3 files changed, 248 insertions(+), 336 deletions(-)
src/sqlhist-lex.c +34 -32
index aaea71c35c98..d6342c5ee7d6 100644
@@ -1,6 +1,6 @@
-#line 1 "sqlhist-lex.c"
+#line 2 "sqlhist-lex.c"
 
-#line 3 "sqlhist-lex.c"
+#line 4 "sqlhist-lex.c"
 
 #define  YY_INT_ALIGNED short int
 
@@ -506,6 +506,8 @@ static const flex_int16_t yy_chk[234] =
 #line 2 "sqlhist.l"
 /* code here */
 
+/* If you change this file, run: make sqlhist_remake */
+
 #include <stdarg.h>
 #include "sqlhist-parse.h"
 
@@ -524,8 +526,8 @@ extern int tfs_my_yyinput(void *extra, char *buf, int max);
 #define TRACE_SB	((struct sqlhist_bison *)yyextra)
 #define HANDLE_COLUMN do { TRACE_SB->line_idx += strlen(yytext); } while (0)
 
-#line 527 "sqlhist-lex.c"
-#line 528 "sqlhist-lex.c"
+#line 530 "sqlhist-lex.c"
+#line 531 "sqlhist-lex.c"
 
 #define INITIAL 0
 
@@ -799,10 +801,10 @@ YY_DECL
 		}
 
 	{
-#line 33 "sqlhist.l"
+#line 35 "sqlhist.l"
 
 
-#line 805 "sqlhist-lex.c"
+#line 808 "sqlhist-lex.c"
 
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
 		{
@@ -861,42 +863,42 @@ do_action:	/* This label is used only to access EOF actions. */
 
 case 1:
 YY_RULE_SETUP
-#line 35 "sqlhist.l"
+#line 37 "sqlhist.l"
 { HANDLE_COLUMN; return SELECT; }
 	YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 36 "sqlhist.l"
+#line 38 "sqlhist.l"
 { HANDLE_COLUMN; return AS; }
 	YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 37 "sqlhist.l"
+#line 39 "sqlhist.l"
 { HANDLE_COLUMN; return FROM; }
 	YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 38 "sqlhist.l"
+#line 40 "sqlhist.l"
 { HANDLE_COLUMN; return JOIN; }
 	YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 39 "sqlhist.l"
+#line 41 "sqlhist.l"
 { HANDLE_COLUMN; return ON; }
 	YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 40 "sqlhist.l"
+#line 42 "sqlhist.l"
 { HANDLE_COLUMN; return WHERE; }
 	YY_BREAK
 case 7:
 YY_RULE_SETUP
-#line 41 "sqlhist.l"
+#line 43 "sqlhist.l"
 { HANDLE_COLUMN; return CAST; }
 	YY_BREAK
 case 8:
 YY_RULE_SETUP
-#line 43 "sqlhist.l"
+#line 45 "sqlhist.l"
 {
 	HANDLE_COLUMN;
 	yylval->string = tfs_store_str(TRACE_SB, yyg->yytext_r);
@@ -906,7 +908,7 @@ YY_RULE_SETUP
 case 9:
 /* rule 9 can match eol */
 YY_RULE_SETUP
-#line 49 "sqlhist.l"
+#line 51 "sqlhist.l"
 {
 	HANDLE_COLUMN;
 	yylval->string = tfs_store_str(TRACE_SB, yyg->yytext_r);
@@ -915,7 +917,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 10:
 YY_RULE_SETUP
-#line 55 "sqlhist.l"
+#line 57 "sqlhist.l"
 {
 	const char *str = yyg->yytext_r;
 	HANDLE_COLUMN;
@@ -926,7 +928,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 11:
 YY_RULE_SETUP
-#line 63 "sqlhist.l"
+#line 65 "sqlhist.l"
 {
 	HANDLE_COLUMN;
 	yylval->number = strtol(yyg->yytext_r, NULL, 0);
@@ -935,7 +937,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 12:
 YY_RULE_SETUP
-#line 69 "sqlhist.l"
+#line 71 "sqlhist.l"
 {
 	HANDLE_COLUMN;
 	yylval->number = strtol(yyg->yytext_r, NULL, 0);
@@ -944,66 +946,66 @@ YY_RULE_SETUP
 	YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 75 "sqlhist.l"
+#line 77 "sqlhist.l"
 { HANDLE_COLUMN; return NEQ; }
 	YY_BREAK
 case 14:
 YY_RULE_SETUP
-#line 76 "sqlhist.l"
+#line 78 "sqlhist.l"
 { HANDLE_COLUMN; return LE; }
 	YY_BREAK
 case 15:
 YY_RULE_SETUP
-#line 77 "sqlhist.l"
+#line 79 "sqlhist.l"
 { HANDLE_COLUMN; return GE; }
 	YY_BREAK
 case 16:
 YY_RULE_SETUP
-#line 78 "sqlhist.l"
+#line 80 "sqlhist.l"
 { HANDLE_COLUMN; return EQ; }
 	YY_BREAK
 case 17:
 YY_RULE_SETUP
-#line 79 "sqlhist.l"
+#line 81 "sqlhist.l"
 { HANDLE_COLUMN; return AND; }
 	YY_BREAK
 case 18:
 YY_RULE_SETUP
-#line 80 "sqlhist.l"
+#line 82 "sqlhist.l"
 { HANDLE_COLUMN; return OR; }
 	YY_BREAK
 case 19:
 YY_RULE_SETUP
-#line 81 "sqlhist.l"
+#line 83 "sqlhist.l"
 { HANDLE_COLUMN; return yytext[0]; }
 	YY_BREAK
 case 20:
 YY_RULE_SETUP
-#line 83 "sqlhist.l"
+#line 85 "sqlhist.l"
 { HANDLE_COLUMN; return yytext[0]; }
 	YY_BREAK
 case 21:
 YY_RULE_SETUP
-#line 85 "sqlhist.l"
+#line 87 "sqlhist.l"
 { HANDLE_COLUMN; }
 	YY_BREAK
 case 22:
 /* rule 22 can match eol */
 YY_RULE_SETUP
-#line 86 "sqlhist.l"
+#line 88 "sqlhist.l"
 { TRACE_SB->line_idx = 0; TRACE_SB->line_no++; }
 	YY_BREAK
 case 23:
 YY_RULE_SETUP
-#line 88 "sqlhist.l"
+#line 90 "sqlhist.l"
 { HANDLE_COLUMN; return PARSE_ERROR; }
 	YY_BREAK
 case 24:
 YY_RULE_SETUP
-#line 89 "sqlhist.l"
+#line 91 "sqlhist.l"
 ECHO;
 	YY_BREAK
-#line 1006 "sqlhist-lex.c"
+#line 1009 "sqlhist-lex.c"
 case YY_STATE_EOF(INITIAL):
 	yyterminate();
 
@@ -2184,7 +2186,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
 
 #define YYTABLES_NAME "yytables"
 
-#line 89 "sqlhist.l"
+#line 91 "sqlhist.l"
 
 
 int yywrap(void *data)
src/sqlhist.tab.c +206 -298

879 lines not on this page · raw message

src/sqlhist.tab.h +8 -6
index b02a782d61b5..f735ee75a135 100644
@@ -1,8 +1,8 @@
-/* A Bison parser, made by GNU Bison 3.6.4.  */
+/* A Bison parser, made by GNU Bison 3.8.2.  */
 
 /* Bison interface for Yacc-like parsers in C
 
-   Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
+   Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
    Inc.
 
    This program is free software: you can redistribute it and/or modify
@@ -16,7 +16,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
 /* As a special exception, you may create a larger work that contains
    part or all of the Bison parser skeleton and distribute that work
@@ -88,7 +88,7 @@ extern int tracefs_debug;
 #if ! defined TRACEFS_STYPE && ! defined TRACEFS_STYPE_IS_DECLARED
 union TRACEFS_STYPE
 {
-#line 46 "sqlhist.y"
+#line 47 "sqlhist.y"
 
 	int	s32;
 	char	*string;
@@ -105,14 +105,16 @@ typedef union TRACEFS_STYPE TRACEFS_STYPE;
 
 
 
+
 int tracefs_parse (struct sqlhist_bison *sb);
+
 /* "%code provides" blocks.  */
-#line 37 "sqlhist.y"
+#line 38 "sqlhist.y"
 
   #define YYSTYPE TRACEFS_STYPE
   #define yylex tracefs_lex
   #define yyerror tracefs_error
 
-#line 117 "sqlhist.tab.h"
+#line 119 "sqlhist.tab.h"
 
 #endif /* !YY_TRACEFS_SQLHIST_TAB_H_INCLUDED  */
Signature · 1 line
2.47.2