Subject: bug#70778: `include' is unable to include local file

From: Владимир ВНИИАЭС<[email-masked]>
Date: Sun, 05 May 2024 14:02:18 +0300

Guile include logic fails when '-L incdir' option is provided.
 
The `syntax-source' function in such case strips out file's directory;
as a result the `call-with-include-port' function is trying to open file
from current directory. Note that `incdir' here is equal to file folder:
 
amaya@t460s:~/tmp$ cat include-test.sh && LANG=C sh include-test.sh
D=/tmp/incdir;    mkdir -p $D
echo                     > $D/a.scm
echo '(include "a.scm")' > $D/b.scm
guile --version
guile -L $D                $D/b.scm
 
guile (GNU Guile) 3.0.9
Copyright (C) 2023 Free Software Foundation, Inc.
 
License LGPLv3+: GNU LGPL 3 or later <http://gnu.org/licenses/lgpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
;;; note: source file /tmp/incdir/b.scm
;;;       newer than compiled /home/amaya/.cache/guile/ccache/3.0-LE-8-4.6/tmp/incdir/b.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /tmp/incdir/b.scm
;;; WARNING: compilation of /tmp/incdir/b.scm failed:
;;; In procedure open-file: No such file or directory: "./a.scm"
Backtrace:
           7 (primitive-load "/tmp/incdir/b.scm")
In ice-9/eval.scm:
   721:20  6 (primitive-eval (include "a.scm"))
In ice-9/psyntax.scm:
  1229:36  5 (expand-top-sequence (#<syntax:b.scm:1:0 (include #<s?>) ?)
  1121:20  4 (parse _ (("placeholder" placeholder)) ((top) #(# # ?)) ?)
  1342:32  3 (syntax-type (include #<syntax:b.scm:1:9 "a.scm">) ((?)) ?)
  1562:32  2 (expand-macro #<procedure 7fa0e7eefa58 at ice-9/psynta?> ?)
  3274:16  1 (_ _ #<procedure 7fa0e8089da0 at ice-9/psyntax.scm:329?> ?)
In unknown file:
           0 (open-file "./a.scm" "r" #:encoding #f #:guess-encoding #)
 
ERROR: In procedure open-file:
In procedure open-file: No such file or directory: "./a.scm"