如何将其他文件指定为导致ASDF重新编译程序的先决条件
我编写了一个程序,该程序使用读取时间评估来读取文本文件中包含的字符串。在此示例中,文本文件为1.TXT
和2.txt
,两者都包含在读取期间将读取的文本。问题:当我编辑1.txt
或2.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.TXT
和2.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.TXT
或2.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用
:static-file
指令将辅助文件作为其他依赖项包含在附加依赖项中:Just include the auxiliary files as additional dependencies, using the
:static-file
directive: