diff mbox series

intl: Unbreak intl build with bison 3 when no regeneration is needed [PR92008]

Message ID 20200416094533.GK2424@tucnak
State New
Headers show
Series intl: Unbreak intl build with bison 3 when no regeneration is needed [PR92008] | expand

Commit Message

Jakub Jelinek April 16, 2020, 9:45 a.m. UTC
Hi!

As Iain reported, my change broke the case when one has bison >= 3,
but make decides there is no reason to regenerate plural.c, unfortunately
that seems to be a scenario I haven't tested.  The problem is that
the pregenerated plural.c has been generated with bison 1.35, but when
config.h says HAVE_BISON3, the code assumes it is the bison3 variant.
What used to work fine is when one has bison >= 3 and plural.c has been
regenerated (e.g. do touch intl/plural.y and it will work), or when
one doesn't have any bison (then nothing is regenerated, but HAVE_BISON3
isn't defined either), or when one has bison < 3 and doesn't need to
regenerate, or when one has bison < 3 and it is regenerated.

The following patch fixes this, by killing the HAVE_BISON3 macro from
config.h, and instead remembering the fact whether plural.c has been created
with bison < 3 or bison >= 3 in a separate new plural-config.h header.
The way this works:
- user doesn't have bison
- user has bison >= 3, but intl/{plural-config.h,plural.c} aren't older than intl/plural.y
- user has bison < 3, but intl/{plural-config.h,plural.c} aren't older than intl/plural.y
	pregenerated !USE_BISON3 plural.c and plural-config.h from source
	dir is used, nothing in the objdir
- user has bison >= 3 and intl/plural.y is newer
	Makefile generates plural.c and USE_BISON3 plural-config.h in the
	objdir, which is then used in preference to srcdir copies
- user has bison < 3 and intl/plural.y is newer
	Makefile generates plural.c and !USE_BISON3 plural-config.h in the
	objdir, which is then used in preference to srcdir copies
I have tested all these cases and make all-yes worked in all the cases.
If one uses the unsupported ./configure where srcdir == objdir, I guess
(though haven't tested) that it should still work, just it would be nice
if such people didn't try to check in the plural{.c,-config.h} they have
regenerated.
What doesn't work, but didn't work before either (just tested gcc-9 branch
too) is when one doesn't have bison and plural.y is newer than plural.c.
Don't do that ;)

Sorry for the breakage.

Ok for trunk?

2020-04-16  Jakub Jelinek  <jakub@redhat.com>

	PR bootstrap/92008
intl/
	* configure.ac: Remove HAVE_BISON3 AC_DEFINE.
	* Makefile.in (HEADERS): Add plural-config.h.
	(.y.c): Also create plural-config.h.
	(dcigettext.o loadmsgcat.o plural.o plural-exp.o): Also depend
	on plural-config.h.
	(plural-config.h): Depend on plural.c.
	* plural-exp.h: Include plural-config.h.  Use USE_BISON3 instead
	of HAVE_BISON3.
	* plural.y: Use USE_BISON3 instead of HAVE_BISON3.
	* configure: Regenerated.
	* plural.c: Regenerated.
	* config.h.in: Regenerated.
	* plural-config.h: Generated.
contrib/
	* gcc_update: Add intl/plural.y dependency for intl/plural-config.h.


	Jakub

Comments

Richard Biener April 16, 2020, 9:52 a.m. UTC | #1
On Thu, 16 Apr 2020, Jakub Jelinek wrote:

> Hi!
> 
> As Iain reported, my change broke the case when one has bison >= 3,
> but make decides there is no reason to regenerate plural.c, unfortunately
> that seems to be a scenario I haven't tested.  The problem is that
> the pregenerated plural.c has been generated with bison 1.35, but when
> config.h says HAVE_BISON3, the code assumes it is the bison3 variant.
> What used to work fine is when one has bison >= 3 and plural.c has been
> regenerated (e.g. do touch intl/plural.y and it will work), or when
> one doesn't have any bison (then nothing is regenerated, but HAVE_BISON3
> isn't defined either), or when one has bison < 3 and doesn't need to
> regenerate, or when one has bison < 3 and it is regenerated.
> 
> The following patch fixes this, by killing the HAVE_BISON3 macro from
> config.h, and instead remembering the fact whether plural.c has been created
> with bison < 3 or bison >= 3 in a separate new plural-config.h header.
> The way this works:
> - user doesn't have bison
> - user has bison >= 3, but intl/{plural-config.h,plural.c} aren't older than intl/plural.y
> - user has bison < 3, but intl/{plural-config.h,plural.c} aren't older than intl/plural.y
> 	pregenerated !USE_BISON3 plural.c and plural-config.h from source
> 	dir is used, nothing in the objdir
> - user has bison >= 3 and intl/plural.y is newer
> 	Makefile generates plural.c and USE_BISON3 plural-config.h in the
> 	objdir, which is then used in preference to srcdir copies
> - user has bison < 3 and intl/plural.y is newer
> 	Makefile generates plural.c and !USE_BISON3 plural-config.h in the
> 	objdir, which is then used in preference to srcdir copies
> I have tested all these cases and make all-yes worked in all the cases.
> If one uses the unsupported ./configure where srcdir == objdir, I guess
> (though haven't tested) that it should still work, just it would be nice
> if such people didn't try to check in the plural{.c,-config.h} they have
> regenerated.
> What doesn't work, but didn't work before either (just tested gcc-9 branch
> too) is when one doesn't have bison and plural.y is newer than plural.c.
> Don't do that ;)
> 
> Sorry for the breakage.
> 
> Ok for trunk?

OK.

> 2020-04-16  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR bootstrap/92008
> intl/
> 	* configure.ac: Remove HAVE_BISON3 AC_DEFINE.
> 	* Makefile.in (HEADERS): Add plural-config.h.
> 	(.y.c): Also create plural-config.h.
> 	(dcigettext.o loadmsgcat.o plural.o plural-exp.o): Also depend
> 	on plural-config.h.
> 	(plural-config.h): Depend on plural.c.
> 	* plural-exp.h: Include plural-config.h.  Use USE_BISON3 instead
> 	of HAVE_BISON3.
> 	* plural.y: Use USE_BISON3 instead of HAVE_BISON3.
> 	* configure: Regenerated.
> 	* plural.c: Regenerated.
> 	* config.h.in: Regenerated.
> 	* plural-config.h: Generated.
> contrib/
> 	* gcc_update: Add intl/plural.y dependency for intl/plural-config.h.
> 
> --- intl/configure.ac.jj	2020-04-16 10:11:49.709094977 +0200
> +++ intl/configure.ac	2020-04-16 10:57:24.033935892 +0200
> @@ -62,7 +62,6 @@ changequote([,])dnl
>    esac
>    AC_MSG_RESULT([$ac_prog_version])
>    if test $ac_bison3 = yes; then
> -    AC_DEFINE(HAVE_BISON3, 1, [Define if bison 3 or later is used.])
>      BISON3_YES=
>      BISON3_NO='#'
>    fi
> --- intl/Makefile.in.jj	2020-04-16 10:11:49.715094886 +0200
> +++ intl/Makefile.in	2020-04-16 11:13:17.134602990 +0200
> @@ -57,6 +57,7 @@ HEADERS = \
>    gettextP.h \
>    hash-string.h \
>    loadinfo.h \
> +  plural-config.h \
>    plural-exp.h \
>    eval-plural.h \
>    localcharset.h \
> @@ -133,10 +134,12 @@ libintl.h: $(srcdir)/libgnuintl.h
>  	$(COMPILE) $<
>  
>  .y.c:
> +@BISON3_YES@	echo '#define USE_BISON3' > $(patsubst %.c,%-config.h,$@)
>  @BISON3_YES@	sed 's,%pure_parser,,;s,^/\* BISON3 \(.*\) \*/$$,\1,' $< > $@.y
>  @BISON3_YES@	$(YACC) $(YFLAGS) --output $@.c $@.y
>  @BISON3_YES@	sed 's/\.c\.y"/.y"/' $@.c > $@
>  @BISON3_YES@	rm -f $@.c $@.y $@.h
> +@BISON3_NO@	echo '/* #define USE_BISON3 */' > $(patsubst %.c,%-config.h,$@)
>  @BISON3_NO@	$(YACC) $(YFLAGS) --output $@ $<
>  	rm -f $*.h
>  
> @@ -165,7 +168,7 @@ dngettext.o finddomain.o gettext.o intl-
>  localealias.o ngettext.o textdomain.o: gettextP.h gmo.h loadinfo.h
>  dcigettext.o loadmsgcat.o: hash-string.h
>  explodename.o l10nflist.o: loadinfo.h
> -dcigettext.o loadmsgcat.o plural.o plural-exp.o: plural-exp.h
> +dcigettext.o loadmsgcat.o plural.o plural-exp.o: plural-exp.h plural-config.h
>  dcigettext.o: eval-plural.h
>  localcharset.o: localcharset.h
>  localealias.o localcharset.o relocatable.o: relocatable.h
> @@ -242,6 +245,8 @@ $(srcdir)/aclocal.m4: @MAINT@ $(aclocal_
>  config.h: stamp-h1
>  	test -f config.h || (rm -f stamp-h1 && $(MAKE) stamp-h1)
>  
> +plural-config.h: plural.c
> +
>  stamp-h1: $(srcdir)/config.h.in config.status
>  	-rm -f stamp-h1
>  	$(SHELL) ./config.status config.h
> --- intl/plural-exp.h.jj	2020-04-16 10:11:49.728094690 +0200
> +++ intl/plural-exp.h	2020-04-16 11:11:45.862973814 +0200
> @@ -20,6 +20,8 @@
>  #ifndef _PLURAL_EXP_H
>  #define _PLURAL_EXP_H
>  
> +#include <plural-config.h>
> +
>  #ifndef PARAMS
>  # if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
>  #  define PARAMS(args) args
> @@ -111,7 +113,7 @@ struct parse_args
>  
>  extern void FREE_EXPRESSION PARAMS ((struct expression *exp))
>       internal_function;
> -#ifdef HAVE_BISON3
> +#ifdef USE_BISON3
>  extern int PLURAL_PARSE PARAMS ((struct parse_args *arg));
>  #else
>  extern int PLURAL_PARSE PARAMS ((void *arg));
> --- intl/plural.y.jj	2020-04-16 10:45:39.015545975 +0200
> +++ intl/plural.y	2020-04-16 11:16:26.741755250 +0200
> @@ -40,7 +40,7 @@
>  # define __gettextparse PLURAL_PARSE
>  #endif
>  
> -#ifndef HAVE_BISON3
> +#ifndef USE_BISON3
>  #define YYLEX_PARAM	&((struct parse_args *) arg)->cp
>  #define YYPARSE_PARAM	arg
>  #endif
> @@ -71,7 +71,7 @@ static inline struct expression *new_exp
>  						   struct expression *bexp,
>  						   struct expression *tbranch,
>  						   struct expression *fbranch));
> -#ifdef HAVE_BISON3
> +#ifdef USE_BISON3
>  static int yylex PARAMS ((YYSTYPE *lval, struct parse_args *arg));
>  static void yyerror PARAMS ((struct parse_args *arg, const char *str));
>  #else
> @@ -266,7 +266,7 @@ FREE_EXPRESSION (exp)
>  }
>  
>  
> -#ifdef HAVE_BISON3
> +#ifdef USE_BISON3
>  static int
>  yylex (lval, arg)
>       YYSTYPE *lval;
> @@ -420,7 +420,7 @@ yylex (lval, pexp)
>  }
>  
>  
> -#ifdef HAVE_BISON3
> +#ifdef USE_BISON3
>  static void
>  yyerror (arg, str)
>       struct parse_args *arg;
> --- intl/configure.jj	2020-04-16 10:11:58.867957071 +0200
> +++ intl/configure	2020-04-16 10:57:35.471763771 +0200
> @@ -6808,9 +6808,6 @@ $as_echo_n "checking bison 3 or later...
>    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5
>  $as_echo "$ac_prog_version" >&6; }
>    if test $ac_bison3 = yes; then
> -
> -$as_echo "#define HAVE_BISON3 1" >>confdefs.h
> -
>      BISON3_YES=
>      BISON3_NO='#'
>    fi
> --- intl/plural.c.jj	2020-04-16 10:11:58.867957071 +0200
> +++ intl/plural.c	2020-04-16 11:16:03.718101046 +0200
> @@ -59,7 +59,7 @@
>  # define __gettextparse PLURAL_PARSE
>  #endif
>  
> -#ifndef HAVE_BISON3
> +#ifndef USE_BISON3
>  #define YYLEX_PARAM	&((struct parse_args *) arg)->cp
>  #define YYPARSE_PARAM	arg
>  #endif
> @@ -89,7 +89,7 @@ static inline struct expression *new_exp
>  						   struct expression *bexp,
>  						   struct expression *tbranch,
>  						   struct expression *fbranch));
> -#ifdef HAVE_BISON3
> +#ifdef USE_BISON3
>  static int yylex PARAMS ((YYSTYPE *lval, struct parse_args *arg));
>  static void yyerror PARAMS ((struct parse_args *arg, const char *str));
>  #else
> @@ -1372,7 +1372,7 @@ FREE_EXPRESSION (exp)
>  }
>  
>  
> -#ifdef HAVE_BISON3
> +#ifdef USE_BISON3
>  static int
>  yylex (lval, arg)
>       YYSTYPE *lval;
> @@ -1526,7 +1526,7 @@ yylex (lval, pexp)
>  }
>  
>  
> -#ifdef HAVE_BISON3
> +#ifdef USE_BISON3
>  static void
>  yyerror (arg, str)
>       struct parse_args *arg;
> --- intl/config.h.in.jj	2020-04-16 10:11:58.867957071 +0200
> +++ intl/config.h.in	2020-04-16 10:57:37.656730890 +0200
> @@ -28,9 +28,6 @@
>  /* Define to 1 if you have the <argz.h> header file. */
>  #undef HAVE_ARGZ_H
>  
> -/* Define if bison 3 or later is used. */
> -#undef HAVE_BISON3
> -
>  /* Define if the GNU dcgettext() function is already present or preinstalled.
>     */
>  #undef HAVE_DCGETTEXT
> --- intl/plural-config.h.jj	2020-04-16 11:02:19.083495908 +0200
> +++ intl/plural-config.h	2020-04-16 11:16:03.718101046 +0200
> @@ -0,0 +1 @@
> +/* #define USE_BISON3 */
> --- contrib/gcc_update.jj	2020-01-17 09:31:28.519196430 +0100
> +++ contrib/gcc_update	2020-04-16 11:19:08.350328031 +0200
> @@ -72,6 +72,7 @@ fixincludes/configure: fixincludes/confi
>  fixincludes/config.h.in: fixincludes/configure.ac fixincludes/aclocal.m4
>  # intl library
>  intl/plural.c: intl/plural.y
> +intl/plural-config.h: intl/plural.y
>  intl/configure: intl/configure.ac intl/aclocal.m4
>  intl/config.h.in: intl/configure.ac intl/aclocal.m4
>  # Now, proceed to gcc automatically generated files
> 
> 	Jakub
> 
>
diff mbox series

Patch

--- intl/configure.ac.jj	2020-04-16 10:11:49.709094977 +0200
+++ intl/configure.ac	2020-04-16 10:57:24.033935892 +0200
@@ -62,7 +62,6 @@  changequote([,])dnl
   esac
   AC_MSG_RESULT([$ac_prog_version])
   if test $ac_bison3 = yes; then
-    AC_DEFINE(HAVE_BISON3, 1, [Define if bison 3 or later is used.])
     BISON3_YES=
     BISON3_NO='#'
   fi
--- intl/Makefile.in.jj	2020-04-16 10:11:49.715094886 +0200
+++ intl/Makefile.in	2020-04-16 11:13:17.134602990 +0200
@@ -57,6 +57,7 @@  HEADERS = \
   gettextP.h \
   hash-string.h \
   loadinfo.h \
+  plural-config.h \
   plural-exp.h \
   eval-plural.h \
   localcharset.h \
@@ -133,10 +134,12 @@  libintl.h: $(srcdir)/libgnuintl.h
 	$(COMPILE) $<
 
 .y.c:
+@BISON3_YES@	echo '#define USE_BISON3' > $(patsubst %.c,%-config.h,$@)
 @BISON3_YES@	sed 's,%pure_parser,,;s,^/\* BISON3 \(.*\) \*/$$,\1,' $< > $@.y
 @BISON3_YES@	$(YACC) $(YFLAGS) --output $@.c $@.y
 @BISON3_YES@	sed 's/\.c\.y"/.y"/' $@.c > $@
 @BISON3_YES@	rm -f $@.c $@.y $@.h
+@BISON3_NO@	echo '/* #define USE_BISON3 */' > $(patsubst %.c,%-config.h,$@)
 @BISON3_NO@	$(YACC) $(YFLAGS) --output $@ $<
 	rm -f $*.h
 
@@ -165,7 +168,7 @@  dngettext.o finddomain.o gettext.o intl-
 localealias.o ngettext.o textdomain.o: gettextP.h gmo.h loadinfo.h
 dcigettext.o loadmsgcat.o: hash-string.h
 explodename.o l10nflist.o: loadinfo.h
-dcigettext.o loadmsgcat.o plural.o plural-exp.o: plural-exp.h
+dcigettext.o loadmsgcat.o plural.o plural-exp.o: plural-exp.h plural-config.h
 dcigettext.o: eval-plural.h
 localcharset.o: localcharset.h
 localealias.o localcharset.o relocatable.o: relocatable.h
@@ -242,6 +245,8 @@  $(srcdir)/aclocal.m4: @MAINT@ $(aclocal_
 config.h: stamp-h1
 	test -f config.h || (rm -f stamp-h1 && $(MAKE) stamp-h1)
 
+plural-config.h: plural.c
+
 stamp-h1: $(srcdir)/config.h.in config.status
 	-rm -f stamp-h1
 	$(SHELL) ./config.status config.h
--- intl/plural-exp.h.jj	2020-04-16 10:11:49.728094690 +0200
+++ intl/plural-exp.h	2020-04-16 11:11:45.862973814 +0200
@@ -20,6 +20,8 @@ 
 #ifndef _PLURAL_EXP_H
 #define _PLURAL_EXP_H
 
+#include <plural-config.h>
+
 #ifndef PARAMS
 # if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
 #  define PARAMS(args) args
@@ -111,7 +113,7 @@  struct parse_args
 
 extern void FREE_EXPRESSION PARAMS ((struct expression *exp))
      internal_function;
-#ifdef HAVE_BISON3
+#ifdef USE_BISON3
 extern int PLURAL_PARSE PARAMS ((struct parse_args *arg));
 #else
 extern int PLURAL_PARSE PARAMS ((void *arg));
--- intl/plural.y.jj	2020-04-16 10:45:39.015545975 +0200
+++ intl/plural.y	2020-04-16 11:16:26.741755250 +0200
@@ -40,7 +40,7 @@ 
 # define __gettextparse PLURAL_PARSE
 #endif
 
-#ifndef HAVE_BISON3
+#ifndef USE_BISON3
 #define YYLEX_PARAM	&((struct parse_args *) arg)->cp
 #define YYPARSE_PARAM	arg
 #endif
@@ -71,7 +71,7 @@  static inline struct expression *new_exp
 						   struct expression *bexp,
 						   struct expression *tbranch,
 						   struct expression *fbranch));
-#ifdef HAVE_BISON3
+#ifdef USE_BISON3
 static int yylex PARAMS ((YYSTYPE *lval, struct parse_args *arg));
 static void yyerror PARAMS ((struct parse_args *arg, const char *str));
 #else
@@ -266,7 +266,7 @@  FREE_EXPRESSION (exp)
 }
 
 
-#ifdef HAVE_BISON3
+#ifdef USE_BISON3
 static int
 yylex (lval, arg)
      YYSTYPE *lval;
@@ -420,7 +420,7 @@  yylex (lval, pexp)
 }
 
 
-#ifdef HAVE_BISON3
+#ifdef USE_BISON3
 static void
 yyerror (arg, str)
      struct parse_args *arg;
--- intl/configure.jj	2020-04-16 10:11:58.867957071 +0200
+++ intl/configure	2020-04-16 10:57:35.471763771 +0200
@@ -6808,9 +6808,6 @@  $as_echo_n "checking bison 3 or later...
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5
 $as_echo "$ac_prog_version" >&6; }
   if test $ac_bison3 = yes; then
-
-$as_echo "#define HAVE_BISON3 1" >>confdefs.h
-
     BISON3_YES=
     BISON3_NO='#'
   fi
--- intl/plural.c.jj	2020-04-16 10:11:58.867957071 +0200
+++ intl/plural.c	2020-04-16 11:16:03.718101046 +0200
@@ -59,7 +59,7 @@ 
 # define __gettextparse PLURAL_PARSE
 #endif
 
-#ifndef HAVE_BISON3
+#ifndef USE_BISON3
 #define YYLEX_PARAM	&((struct parse_args *) arg)->cp
 #define YYPARSE_PARAM	arg
 #endif
@@ -89,7 +89,7 @@  static inline struct expression *new_exp
 						   struct expression *bexp,
 						   struct expression *tbranch,
 						   struct expression *fbranch));
-#ifdef HAVE_BISON3
+#ifdef USE_BISON3
 static int yylex PARAMS ((YYSTYPE *lval, struct parse_args *arg));
 static void yyerror PARAMS ((struct parse_args *arg, const char *str));
 #else
@@ -1372,7 +1372,7 @@  FREE_EXPRESSION (exp)
 }
 
 
-#ifdef HAVE_BISON3
+#ifdef USE_BISON3
 static int
 yylex (lval, arg)
      YYSTYPE *lval;
@@ -1526,7 +1526,7 @@  yylex (lval, pexp)
 }
 
 
-#ifdef HAVE_BISON3
+#ifdef USE_BISON3
 static void
 yyerror (arg, str)
      struct parse_args *arg;
--- intl/config.h.in.jj	2020-04-16 10:11:58.867957071 +0200
+++ intl/config.h.in	2020-04-16 10:57:37.656730890 +0200
@@ -28,9 +28,6 @@ 
 /* Define to 1 if you have the <argz.h> header file. */
 #undef HAVE_ARGZ_H
 
-/* Define if bison 3 or later is used. */
-#undef HAVE_BISON3
-
 /* Define if the GNU dcgettext() function is already present or preinstalled.
    */
 #undef HAVE_DCGETTEXT
--- intl/plural-config.h.jj	2020-04-16 11:02:19.083495908 +0200
+++ intl/plural-config.h	2020-04-16 11:16:03.718101046 +0200
@@ -0,0 +1 @@ 
+/* #define USE_BISON3 */
--- contrib/gcc_update.jj	2020-01-17 09:31:28.519196430 +0100
+++ contrib/gcc_update	2020-04-16 11:19:08.350328031 +0200
@@ -72,6 +72,7 @@  fixincludes/configure: fixincludes/confi
 fixincludes/config.h.in: fixincludes/configure.ac fixincludes/aclocal.m4
 # intl library
 intl/plural.c: intl/plural.y
+intl/plural-config.h: intl/plural.y
 intl/configure: intl/configure.ac intl/aclocal.m4
 intl/config.h.in: intl/configure.ac intl/aclocal.m4
 # Now, proceed to gcc automatically generated files