如何将其他文件指定为导致ASDF重新编译程序的先决条件

发布于 2025-01-26 05:31:38 字数 1898 浏览 3 评论 0原文

我编写了一个程序,该程序使用读取时间评估来读取文本文件中包含的字符串。在此示例中,文本文件为1.TXT2.txt,两者都包含在读取期间将读取的文本。问题:当我编辑1.txt2.txt时,ASDF不会重新编译程序,即使这些文件的内容会影响程序的行为。如何将这两个文件添加为附加的“先决条件”,如果修改了文件,该文件会导致程序重新编译?

这是有问题的程序:

myProg.asd

(defpackage myprog-asd
  (:use :cl :asdf))
(in-package :myprog-asd)

(defsystem "myprog"
  :components ((:file "myprog")))

myprog.lisp

(in-package :cl-user)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defun read-file-string (path)
    "Returns the contents of the file as a string"
    (with-open-file (stream path :direction :input)
      (let ((str (make-string (file-length stream))))
        (read-sequence str stream)
        str))))

(defun run-main ()
  (princ #.(read-file-string "1.txt"))
  (princ #.(read-file-string "2.txt"))
  nil)

创建1.TXT2.txt :

$ echo 'Hello' > 1.txt
$ echo 'World' > 2.txt

编译并运行程序:

$ sbcl
* (require "asdf")
* (asdf:load-asd (merge-pathnames "myprog.asd" (uiop:getcwd)))
* (asdf:load-system :myprog)
* (run-main)
Hello
World
NIL

如果我修改1.TXT2.txt,则不会重新编译该程序,从而导致错误的输出(( run-main)

$ echo 'Hi!' > 1.txt
$ echo 'Bye!' > 2.txt
$ sbcl
* (require "asdf")
* (asdf:load-asd (merge-pathnames "myprog.asd" (uiop:getcwd)))
* (asdf:load-system :myprog)
* (run-main)
Hello
World
NIL

如何解决此问题? (ASDF:LOAD-SYSTEM:myProg:force t)可以解决问题,但即使没有更改,也可以重新编译程序。

(SBCL 2.2.2; ASDF 3.3.5; Ubuntu 20.04)

I have written a program that uses read-time evaluation to read strings contained in text files. In this example, the text files are 1.txt and 2.txt, both of which contain text that will be read during read-time. The problem: ASDF will not recompile the program when I edit 1.txt or 2.txt even though the contents of these files affect the behavior of the program. How do I add these two files as additional "prerequisites" that would cause the program to be recompiled if the files are modified?

This is the program in question:

myprog.asd:

(defpackage myprog-asd
  (:use :cl :asdf))
(in-package :myprog-asd)

(defsystem "myprog"
  :components ((:file "myprog")))

myprog.lisp:

(in-package :cl-user)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defun read-file-string (path)
    "Returns the contents of the file as a string"
    (with-open-file (stream path :direction :input)
      (let ((str (make-string (file-length stream))))
        (read-sequence str stream)
        str))))

(defun run-main ()
  (princ #.(read-file-string "1.txt"))
  (princ #.(read-file-string "2.txt"))
  nil)

Create the 1.txt and 2.txt:

$ echo 'Hello' > 1.txt
$ echo 'World' > 2.txt

Compile and run the program:

$ sbcl
* (require "asdf")
* (asdf:load-asd (merge-pathnames "myprog.asd" (uiop:getcwd)))
* (asdf:load-system :myprog)
* (run-main)
Hello
World
NIL

If I modify 1.txt or 2.txt, the program would not be recompiled, resulting in wrong output for (run-main):

$ echo 'Hi!' > 1.txt
$ echo 'Bye!' > 2.txt
$ sbcl
* (require "asdf")
* (asdf:load-asd (merge-pathnames "myprog.asd" (uiop:getcwd)))
* (asdf:load-system :myprog)
* (run-main)
Hello
World
NIL

How do I fix this problem? (asdf:load-system :myprog :force t) could fix the problem but it recompiles the program even when there are no changes.

(SBCL 2.2.2; ASDF 3.3.5; Ubuntu 20.04)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗷兮 2025-02-02 05:31:38

只需使用:static-file指令将辅助文件作为其他依赖项包含在附加依赖项中:

(defsystem "myprog"
  :components ((:static-file "1.txt")
               (:static-file "2.txt")
               (:file "myprog" :depends-on ("1.txt" "2.txt"))))

Just include the auxiliary files as additional dependencies, using the :static-file directive:

(defsystem "myprog"
  :components ((:static-file "1.txt")
               (:static-file "2.txt")
               (:file "myprog" :depends-on ("1.txt" "2.txt"))))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文