Skip to content

Retrieve the version of a system with ASDF (and Git) #30

Description

@vindarel

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))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions