An asd declaration accepts a :version:
(asdf:defsystem "myapp"
:version "0.1.1"
How can we get it programmatically?
(asdf/component:component-version (asdf:find-system :myapp))
;; "0.1.1"
We can also append the id of the current git commit, which we get with git describe --always.
(let ((version (asdf/component:component-version (asdf:find-system :myapp)))
(directory (asdf:system-source-directory :myapp)))
(or (ignore-errors
(uiop:with-current-directory (directory)
(multiple-value-bind (current-commit)
(uiop:run-program (list "git" "describe" "--always")
:output '(:string :stripped t))
(concatenate 'string
version
(format nil "-~a" current-commit)))))
version))
It returns "0.1.1-1cbe8".
A more complete version that doesn't append the commit id if we are at a current tag:
;; as seen in the Next project.
(let ((version (asdf/component:component-version (asdf:find-system :next)))
(directory (asdf:system-source-directory :next)))
(or (ignore-errors
(uiop:with-current-directory (directory)
(multiple-value-bind (current-commit)
(uiop:run-program (list "git" "describe" "--always")
:output '(:string :stripped t))
(multiple-value-bind (tag-commit)
(uiop:run-program (list "git" "describe" version "--always")
:output '(:string :stripped t))
(concatenate 'string
version
(when (string/= tag-commit current-commit)
(format nil "-~a" current-commit)))))))
version))
An asd declaration accepts a
:version:How can we get it programmatically?
We can also append the id of the current git commit, which we get with
git describe --always.It returns
"0.1.1-1cbe8".A more complete version that doesn't append the commit id if we are at a current tag: