Repository navigation
Fix header include path for output outside the current directory - #877
Conversation
|
Could we check whether the two directories refer to the same directory on disk before using the header’s basename? I reproduced this with: mkdir -p build actual/sub
ln -s ../actual/sub build/link
lrama -o build/link/../parser.c --header="$PWD/build/parser.h" grammar.y
cc -c build/link/../parser.cThe C file ends up in Could we add a regression test for this case as well? |
Co-authored-by: Claude <noreply@anthropic.com>
|
Thank you for the review and the reproduction steps. I could reproduce the problem. I changed the comparison to use Bison 3.8.2 outputs |
Lrama::Outputbuilds the#includepath withheader_file_path.sub("./", "").String#subwith a string pattern replaces the first occurrence of the pattern, so../y.tab.hbecomes.y.tab.h.When the header and the output file are in the same directory on disk, the include is now the header's base name, which is what Bison 3.8.2 emits. The directories are compared with
File.identical?, which follows symlinks before applying... For-o build/link/../parser.cwithbuild/linka symlink, the comparison uses the symlink target's parent, where the compiler looks for a quoted include. The change also turns-d -o ext/y.tab.cfrom#include "ext/y.tab.h"into#include "y.tab.h". When the two files are in different directories, the path is kept as given and only a leading./is removed.