From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxim Cournoyer Newsgroups: gmane.lisp.guile.bugs Subject: bug#66046: Relative includes in R7RS define-library seem broken Date: Mon, 06 Nov 2023 23:42:41 -0500 Message-ID: <878r7akwce.fsf@gmail.com> References: <6C8500AC-6352-4849-A2C9-2DFEB34F21D5@nonceword.org> <87cywmzqbj.fsf@ngyro.com> <87h6lylnvi.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31017"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 66046@debbugs.gnu.org, Daphne Preston-Kendal To: Timothy Sample Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Tue Nov 07 05:43:56 2023 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r0DwR-0007y2-M4 for guile-bugs@m.gmane-mx.org; Tue, 07 Nov 2023 05:43:55 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r0Dvz-0003bH-B7; Mon, 06 Nov 2023 23:43:27 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r0Dvx-0003YO-4m for bug-guile@gnu.org; Mon, 06 Nov 2023 23:43:25 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r0Dvw-0001T0-TE for bug-guile@gnu.org; Mon, 06 Nov 2023 23:43:24 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r0DwY-0001CG-D4 for bug-guile@gnu.org; Mon, 06 Nov 2023 23:44:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 07 Nov 2023 04:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66046 X-GNU-PR-Package: guile Original-Received: via spool by 66046-submit@debbugs.gnu.org id=B66046.16993322144540 (code B ref 66046); Tue, 07 Nov 2023 04:44:02 +0000 Original-Received: (at 66046) by debbugs.gnu.org; 7 Nov 2023 04:43:34 +0000 Original-Received: from localhost ([127.0.0.1]:41123 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r0Dw5-0001B8-NR for submit@debbugs.gnu.org; Mon, 06 Nov 2023 23:43:34 -0500 Original-Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]:45550) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r0Dvz-0001AX-5W for 66046@debbugs.gnu.org; Mon, 06 Nov 2023 23:43:28 -0500 Original-Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-7789577b53fso344558685a.3 for <66046@debbugs.gnu.org>; Mon, 06 Nov 2023 20:42:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699332163; x=1699936963; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=4SsBSLj5Gk9A6Fu6rKOYXMGveZqYJLyxPxhjQP9qnXA=; b=bUsmh++yijVcOd7+7guM37FjwvlVeHpmbBzouL7CFFqx9niVYmLPeYMpRKrZSnHvvK gNWLsZatBeYjiqHP2aLdbYyV269TJ/BYhB7FxTYkZ9dzdmlsT0hJSSkoUanQUVjZC+oh oSZdONtsxY1laQZLJchvRuqp9QfFfgkXSaeuHpFnfBQcY8ElGvRVMmRtrTypKyObhCCy snaU/PsWPKFy1TZNHOlBxgGZ046kJ3e83fEiGekVLqW+wUHkVqLPbVwnyKsbPGBwu8Y8 Xhow11uvWZxXSj3kTtmhWbE8AStWencSKpXfIYbL0LCeDKEFcHi45lNTBY5lzLjhhzlO p+eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699332163; x=1699936963; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4SsBSLj5Gk9A6Fu6rKOYXMGveZqYJLyxPxhjQP9qnXA=; b=NjJCvscR/NAWQSxnEe1RZzCOqb373AC1vxGUYQI7MDTNMTBkUJ1TZ8q0kiQpeFRSog cZwiB221VMiMHv16+xh0gktFAVKnXtVs9Ac6VT67XWVYMWRpG+1QDccr2ykEul7KVhx6 c45I/RCJA3d2G8Nhuv8oM40kUX3yZ9XsdH0/fqfywhrekuYc3UTzhcFeTlnNORmwqZs1 yicxtGv4UkTyxkyL/zFqufYpnTrJfFUwUaIVbJYEFA/SwZs9t1WyWYpBTrgrEO7uQvlI 3isFSQ3TBNHAeA8docJFEEeJ+fFjWDsjEpFEkm5CnWbggCJWWPhPg+dDXDYWN15daER3 uAkg== X-Gm-Message-State: AOJu0YxBeRNds3uL7mf5MbQZefmrrwUMMyCiZiKfUe6omnzTpmh+JeTe YOTXS6It0Kh4XKvcn4yX0C2NWvWAv1Q= X-Google-Smtp-Source: AGHT+IGi2kn6xKIQ0dnSbEbIxsxfWYEUjpSvmBLNkbzRCQl7nACEO6ljEJhs/GaZ7CUaZbeV0nABGg== X-Received: by 2002:a05:6214:f2c:b0:670:710f:2042 with SMTP id iw12-20020a0562140f2c00b00670710f2042mr38093244qvb.15.1699332163574; Mon, 06 Nov 2023 20:42:43 -0800 (PST) Original-Received: from hurd (dsl-10-130-87.b2b2c.ca. [72.10.130.87]) by smtp.gmail.com with ESMTPSA id f12-20020a0cf7cc000000b0065b0554ae78sm4024702qvo.100.2023.11.06.20.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 20:42:42 -0800 (PST) In-Reply-To: <87h6lylnvi.fsf@gmail.com> (Maxim Cournoyer's message of "Mon, 06 Nov 2023 13:48:01 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10690 Archived-At: --=-=-= Content-Type: text/plain Hello, Here's a new test that reproduces the issue: --=-=-= Content-Type: text/x-patch Content-Disposition: inline 1 file changed, 65 insertions(+) test-suite/tests/compiler.test | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ modified test-suite/tests/compiler.test @@ -18,6 +18,7 @@ (define-module (tests compiler) #:use-module (test-suite lib) #:use-module (test-suite guile-test) + #:use-module (ice-9 ftw) #:use-module (system base compile) #:use-module ((language tree-il) #:select (tree-il-src call-args)) @@ -27,6 +28,39 @@ (define read-and-compile (@@ (system base compile) read-and-compile)) +;;; Based on 'with-directory-excursion', from (guix build utils). +(define-syntax-rule (with-temporary-directory body ...) + "Run BODY with DIR as the process's current directory." + (let ((init (getcwd)) + (dir (mkdtemp "tempdir.XXXXXX"))) + (dynamic-wind + (lambda () + (chdir dir)) + (lambda () + body ...) + (lambda () + (chdir init) + (delete-file-recursively dir))))) + +;;; XXX: Adapted from (guix build utils). +(define* (delete-file-recursively dir) + "Delete DIR recursively, like `rm -rf', without following symlinks." + (file-system-fold (const #t) ;enter + (lambda (file stat result) ; leaf + (delete-file file)) + (const #t) ; down + (lambda (dir stat result) ; up + (rmdir dir)) + (const #t) ; skip + (lambda (file stat errno result) + (format (current-error-port) + "warning: failed to delete ~a: ~a~%" + file (strerror errno))) + #t + dir + + ;; Don't follow symlinks. + lstat)) (with-test-prefix "basic" @@ -434,3 +468,34 @@ (set! proc ((load-thunk-from-memory bytecode))) (procedure? proc))) (pass-if-equal "proc executes" 42 (proc)))) + +(with-test-prefix "compile-file" + ;; Setup test library sources in a temporary directory. + (let ((top-sexp '(define-library (hello) + (import (scheme base) + (scheme write)) + (export hello) + (include "hello/hello-impl.scm"))) + (included-sexp '(define (hello) + (display "hello!\n")))) + (with-temporary-directory + (mkdir "module") + (call-with-output-file "module/hello.scm" + (lambda (port) + (write top-sexp port))) + (mkdir "module/hello") + (call-with-output-file "module/hello/hello-impl.scm" + (lambda (port) + (write included-sexp port))) + (mkdir "build") + (chdir "build") + + (pass-if "relative include works" + (compile-file "../module/hello.scm" #:output-file "hello.go") + #t) + + (pass-if "relative include works with load path canonicalization" + (begin + (add-to-load-path (string-append (getcwd) "/../module")) + (compile-file "../module/hello.scm" #:output-file "hello.go") + #t))))) --=-=-= Content-Type: text/plain I run it like: --8<---------------cut here---------------start------------->8--- ./meta/guile -L test-suite -L . test-suite/tests/compiler.test --8<---------------cut here---------------end--------------->8--- And I see: --8<---------------cut here---------------start------------->8--- ERROR: compile-file: relative include works with load path canonicalization - arguments: ((system-error "open-file" "~A: ~S" ("Aucun fichier ou dossier de ce type" "./hello/hello-impl.scm") (2))) --8<---------------cut here---------------end--------------->8--- That's the include directive failing because scm_i_relativize_path caused the path to be stripped from "../module/hello.scm" to "hello.scm"; then include, through its call-with-include-port helper, calls (dirname "hello.scm"), which produces ".". Finally, the same helper calls (in-vicinity "." "hello/hello-impl.scm"), which produces the unresolvable "./hello/hello-impl.scm" file name seen in the error above. -- Thanks, Maxim --=-=-=--