Skip to content

yacc tool updates - #4330

Merged
bdbaddog merged 11 commits into
SCons:masterfrom
mwichmann:feature/bison-args
Jun 18, 2023
Merged

bdbaddog merged 11 commits into
SCons:masterfrom
mwichmann:feature/bison-args

Conversation

@mwichmann

@mwichmann mwichmann commented Mar 23, 2023 •

Copy link
Copy Markdown
Collaborator

The yacc tool now recognizes the bison syntax of using --header, --defines and --graph options in YACCFLAGS without supplying an option argument. Note that byacc doesn't allow leaving off the option argument, and would error out in such cases.

Fixes #4326

The yacc tool now recognizes -H as a partial synonym for --header. It only works in the no-option-argument form - giving an option argument will likely break things.

Fixes #4327

Tests are expanded to cover these.

The graph file name (-g) is now generated relative to the requested target file name, not to the source name, to match actual current bison behavior. This is rare case - only kicks in if target explicitly requested with a different base name than source - in this case SCons would emit a different name than bison produces. Unlikely to affect any real usage - you would have to set up the condition described, and additionally use the graph file as a source for some other build target.

The default file suffix for graph files is set to .gv, which is current for Bison as of 1.38. The previous suffix for Bison, dating back to 2.4, was .dot, which is still the suffix byacc uses. Docs updated to better describe when you need to set this. The former default, .vcg, has not been used since 2006.

Obsoleted YACCVCGFILESUFFIX, being replaced by YACC_GRAPH_FILE_SUFFIX. If YACC_GRAPH_FILE_SUFFIX is not set, it will respect YACCVCGFILESUFFIX.

Documentation updated for the two header suffix construction variables to better describe (I hope) what these mean and when to set them. Other doc updates as well.

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt (and read the README.rst)
  • I have updated the appropriate documentation

@mwichmann mwichmann added the Tools Issues related to tools subsystem label Mar 23, 2023
Comment thread CHANGES.txt Resolved
Comment thread SCons/Tool/Tool.xml Resolved
Comment thread SCons/Tool/Tool.xml Resolved
@bdbaddog

Copy link
Copy Markdown
Contributor

can we add that blurb about files with the yacc tool, instaed of CFile() ?

@bdbaddog

bdbaddog commented May 4, 2023

Copy link
Copy Markdown
Contributor

If a user is using an old version of bison or byacc would SCons' expected output files now be incorrect?

mwichmann added 2 commits May 6, 2023 07:11
The yacc tool now recognizes the bison syntax of using --header, --defines
and --graph options in YACCFLAGS without supplying an option argument.
Note that byacc doesn't allow leaving off the option argument, and would
error out in such cases.

Fixes SCons#4326

The yacc tool now recognizes -H as a partial synonym for --header.
It only works in the no-option-argument form - giving an option argument
will likely break things.

Fixes SCons#4327

Tests are expanded to cover these.

The graph file name (-g) is now generated relative to the requested
target file name, not to the source name, to match actual current
behavior. This is rare case - only kicks in if target explicitly requested
with a different base name than source - in this case SCons would emit a
different name than bison produces.  Unlikely to affect any real usage -
you would have to set up the condition described, and additionally use
the graph file as a source for some other build target.

The default file suffix for graph files is set to .gv, which is current
for Bison as of 3.8.  The previous suffix for Bison, dating back to 2.4,
was .dot, which is still the suffix byacc uses.  Docs updated to better
describe when you need to set this. The former default, .vcg, has not
been used since 2006.

Documentation updated for the two header suffix construction variables
to better describe (I hope) what these mean and when to set them. Other
doc updates as well.

Signed-off-by: Mats Wichmann <[email protected]>
Per review requests

Signed-off-by: Mats Wichmann <[email protected]>
@mwichmann
mwichmann force-pushed the feature/bison-args branch from bd69915 to 2ef2269 Compare May 6, 2023 14:01
@mwichmann

Copy link
Copy Markdown
Collaborator Author

If a user is using an old version of bison or byacc would SCons' expected output files now be incorrect?

The only confusion could be about the graph file, where bison has changed file format once, and names twice; byacc has used the same format/suffix since they introduced the feature. This only matters in the quite unlikely case that the graph file is used as the source to some other build - it's intended as a diagnostic output, not as something you'd use as part of a build. It only matters to us so there's something to "clean". A bison old enough to notice the change would be 17+ years old.

@mwichmann

Copy link
Copy Markdown
Collaborator Author

I've updated (RELEASE, doc). Rebasing to current meant I had to force-push so things here will be out of sync.

@mwichmann

Copy link
Copy Markdown
Collaborator Author

The failure here is very odd:

https://ci.appveyor.com/project/SCons/scons/builds/46977299/job/dmkqe6n3umy68di0

The other windows runs didn't take this problem, and because it's an emulated tool (myyacc.py), not trying to use the real bison, it can't be a "tool is too old" problem. First guess is I might have used something that doesn't work in Python 3.6, but will have to investigate.

@jcbrill

jcbrill commented May 6, 2023 •

Copy link
Copy Markdown
Contributor

First guess is I might have used something that doesn't work in Python 3.6, but will have to investigate.

After a REALLY QUICK (and possibly misguided) experiment, it appears that 3.6 needs a space after the "-I".

This fails in 3.6: "-Iout -Iin"
This passes in 3.6: "-I out -I in"

Both seem to work in 3.8.

@mwichmann

Copy link
Copy Markdown
Collaborator Author

Thanks for that. Maybe this is something in the argparse module - the mock tool didn't use that previously, it used getopt (I already forgot that change was made here, I thought I did that the last time I fiddled with this tool).

@bdbaddog

bdbaddog commented May 6, 2023

Copy link
Copy Markdown
Contributor

If a user is using an old version of bison or byacc would SCons' expected output files now be incorrect?

The only confusion could be about the graph file, where bison has changed file format once, and names twice; byacc has used the same format/suffix since they introduced the feature. This only matters in the quite unlikely case that the graph file is used as the source to some other build - it's intended as a diagnostic output, not as something you'd use as part of a build. It only matters to us so there's something to "clean". A bison old enough to notice the change would be 17+ years old.

Couldn't this be used to generate some document for the software being built?
To generate the correct output file, we'd need to interrogate the tool to see which version is being used?

@mwichmann

Copy link
Copy Markdown
Collaborator Author

Maybe wait for someone to request that?

@mwichmann

Copy link
Copy Markdown
Collaborator Author

To follow up on the error a bit, here's the thing that goes wrong extracted - I can reproduce this fail on Linux also:

$ python3.6 myyacc.py -x -Iout -Iin -o out/aaa.c in/aaa.y
usage: myyacc.py [-h] [-g [GRAPH]] [-d] [-v] [-x] [-H [HEADER]] -o OUT
                 [-I I_ARGUMENTS]
                 files [files ...]
myyacc.py: error: unrecognized arguments: -Iout -Iin
$ python3.7 myyacc.py -x -Iout -Iin -o out/aaa.c in/aaa.y
usage: myyacc.py [-h] [-g [GRAPH]] [-d] [-v] [-x] [-H [HEADER]] -o OUT
                 [-I I_ARGUMENTS]
                 files [files ...]
myyacc.py: error: unrecognized arguments: -Iout -Iin
$ python3.8 myyacc.py -x -Iout -Iin -o out/aaa.c in/aaa.y
$

So 3.6 and 3.7 fail this, 3.8 and later passes. The argparse docs don't list any 3.8 behavioral change that could affect this, so presumably it was a "bugfix".

Since the argument isn't a yacc argument but something specific to the mock command, we can fix this up in the test by including the space so it works on all versions. The mock command needs a tweak for that.

mwichmann added 3 commits May 8, 2023 09:23
When the mock tool was revised to use argparse instead of getopt,
it stumbled across the problem that argparse apparently doesn't deal
with a single-letter option and its option-argument not having a
space between them until Python 3.8 - 3.6 and 3.7 failed the test.
Change to use the space in the test/mock tool.

Signed-off-by: Mats Wichmann <[email protected]>
A review request suggested removing the note in CFile/CXXFile tool doc
on yacc filenames. I removed only the CFile one, this does the CXXFile
one as well.

Signed-off-by: Mats Wichmann <[email protected]>
@bdbaddog

bdbaddog commented May 9, 2023

Copy link
Copy Markdown
Contributor

So here's my concern. Often parsers depend on a specific version of bison/yacc/byacc. Changing the version may introduce changes which will break the logic.
Bison 3.8 is a 2021 release, so relatively recent.

But as you said this is only for the graph output file?
So maybe just a more explicit note
NOTE: If you are using Bison < 3.8, and outputting a graph file, SCons will expect the incorrect version. Please send email to [email protected] or let us know on our discord server.

@mwichmann

Copy link
Copy Markdown
Collaborator Author

I suppose. bison switched way long ago to using .dot. byacc then followed suit. Then the graphviz folks told the bison folks "don't do that, .dot is ambiguous as a suffix". byacc didn't follow suit. Leaves us with a fairly impossible situation.

The .gv suffix has been around quite a bit longer, this just flipped the suffix default "if you say nothing".

+  In conformance with the recommendations of the GraphViz team, if %require
+  "3.4" (or better) is specified, the option --graph generates a *.gv file
+  by default, instead of *.dot.

Further, you can specify the filename you want via other mechanisms. These are just ugly compat things that don't really work well with SCons anyway - $YACC_GRAPH_FILE is preferred.

Does that make you any happier?

bdbaddog and others added 5 commits May 17, 2023 20:59
@mwichmann

Copy link
Copy Markdown
Collaborator Author

Cleaned up conflicts.

@bdbaddog
bdbaddog merged commit 570eeba into SCons:master Jun 18, 2023
@mwichmann mwichmann added this to the NextRelease milestone Jun 18, 2023
@mwichmann
mwichmann deleted the feature/bison-args branch June 18, 2023 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Tools Issues related to tools subsystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for the GNU Bison option -H GNU Bison options --header and --defines are not recognised by SCons when they don't have an argument

3 participants