如何将其他文件指定为导致 ASDF 重新编译程序的先决条件
How to specify additional files as prerequisites that would cause ASDF to recompile the program
我编写了一个程序,它使用读取时求值来读取文本文件中包含的字符串。在此示例中,文本文件为 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)
使用 :static-file
指令将辅助文件作为附加依赖项包含在内:
(defsystem "myprog"
:components ((:static-file "1.txt")
(:static-file "2.txt")
(:file "myprog" :depends-on ("1.txt" "2.txt"))))
我编写了一个程序,它使用读取时求值来读取文本文件中包含的字符串。在此示例中,文本文件为 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)
使用 :static-file
指令将辅助文件作为附加依赖项包含在内:
(defsystem "myprog"
:components ((:static-file "1.txt")
(:static-file "2.txt")
(:file "myprog" :depends-on ("1.txt" "2.txt"))))