Commit 1f594d1a authored by Eric Timmons's avatar Eric Timmons
Browse files

Move version computation into clpm-asdf

Now it can be used when naming release archives
parent 7d3e2afe
......@@ -6,14 +6,16 @@
(load-system :asdf-release-ops)
(defsystem #:clpm-asdf
:version (:read-file-form "clpm/version.lisp" :at (2 2))
:version (:read-file-form "version.lisp-expr")
:description "ASDF bootstrapping for CLPM"
:license "BSD-2-Clause"
:pathname "clpm-asdf/"
:depends-on (#:asdf-release-ops
#:cl-semver
#:trivial-features)
:components ((:file "package")
(:file "features" :depends-on ("package"))
(:file "system" :depends-on ("package" "features"))
(:file "version" :depends-on ("package"))
(:file "system" :depends-on ("package" "features" "version"))
(:file "dependencies-license-op" :depends-on ("package" "system"))
(:file "client" :depends-on ("package" "system"))))
......@@ -10,3 +10,6 @@
(defmethod ops:program-image-features (o (s clpm-system))
(augment-features (clpm-features)))
(defmethod ops::release-system-version-designator ((s clpm-system))
(clpm-version))
;;;; CLPM version definitions
;;;;
;;;; This software is part of CLPM. See README.org for more information. See
;;;; LICENSE for license information.
(in-package #:clpm-asdf)
;;; Application Version
(defun base-version ()
(uiop:read-file-form (asdf:system-relative-pathname :clpm-asdf "version.lisp-expr")))
(defparameter *full-version* nil
"Cache the full version information as of when the executable was built. Is
NIL until an image is dumped and is set by ~cache-full-version~.")
(defun clpm-git (args &rest keys)
(uiop:with-current-directory ((asdf:system-relative-pathname :clpm ""))
(apply #'uiop:run-program
`("git" ,@args)
keys)))
(defun git-exists-p ()
"Returns T iff git exists and is callable."
(ignore-errors
(uiop:run-program '("git" "--version"))
(clpm-git '("describe"))
t))
(defun get-git-branch ()
(or
(ignore-errors
(clpm-git '("symbolic-ref" "--short" "HEAD")
:output '(:string :stripped t)))
"HEAD"))
(defun get-git-commit ()
(clpm-git '("rev-parse" "--short" "HEAD")
:output '(:string :stripped t)))
(defun get-git-dirty-p ()
(not (zerop (nth-value 2
(clpm-git '("diff-index" "--quiet" "HEAD")
:ignore-error-status t)))))
(defun get-git-describe (&optional ref)
(uiop:split-string
(clpm-git `("describe" "--tags" "--match" "v*" ,@(when ref (list ref)))
:output '(:string :stripped t))
:max 3
:separator '(#\-)))
(defun get-git-common-ancestor ()
(clpm-git '("merge-base" "HEAD" "origin/master")
:output '(:string :stripped t)))
(defun get-git-distance-from-master ()
(parse-integer (clpm-git '("rev-list" "--count" "HEAD" "--not" "origin/master")
:output '(:string :stripped t))))
(defun get-git-tag-p ()
(zerop (nth-value 2
(clpm-git '("describe" "--tags" "--exact-match" "HEAD")
:ignore-error-status t))))
(defun get-full-version ()
(if (git-exists-p)
(let ((git-branch (get-git-branch))
(git-describe (get-git-describe))
(git-dirty-p (get-git-dirty-p)))
(if (get-git-tag-p)
;; This is a tagged version, just return the base version number.
(base-version)
;; Here's the fun part, assemble the entire version string.
(let* ((version (cl-semver:read-version-from-string (base-version)))
(primary-version (list (cl-semver:version-major version)
(cl-semver:version-minor version)
(cl-semver:version-patch version)))
(prerelease-category (cl-semver:version-pre-release-identifiers version)))
(unless prerelease-category
(setf prerelease-category '(0)))
(if (equal git-branch "master")
(format nil "~{~A~^.~}-~{~A~^.~}.~A+~A~:[~;-dirty~]"
primary-version
prerelease-category
(second git-describe)
(third git-describe)
git-dirty-p)
(let* ((ancestor (get-git-common-ancestor))
(ancestor-describe (get-git-describe ancestor))
(distance-from-master (get-git-distance-from-master)))
(format nil "~{~A~^.~}-~{~A~^.~}.~A.0.~A.~A+~A~:[~;-dirty~]"
primary-version prerelease-category
(second ancestor-describe)
git-branch
distance-from-master
(third git-describe)
git-dirty-p))))))
;; We don't have git... Best we can currently do is return the base
;; version number.
(base-version)))
(defun cache-full-version ()
"Cache the full version into ~*full-version*~."
(setf *full-version* (get-full-version)))
(uiop:register-image-dump-hook 'cache-full-version)
(defun clpm-version ()
"Return the CLPM version string."
(or
*full-version*
(get-full-version)))
......@@ -9,7 +9,7 @@
(in-package :asdf-user)
(defsystem #:clpm-cli
:version (:read-file-form "clpm/version.lisp" :at (2 2))
:version (:read-file-form "version.lisp-expr")
:description "Command Line Interface for CLPM"
:license "BSD-2-Clause"
:pathname "cli/"
......
......@@ -12,7 +12,7 @@
(load-system :clpm-asdf)
(defsystem #:clpm
:version (:read-file-form "clpm/version.lisp" :at (2 2))
:version (:read-file-form "version.lisp-expr")
:description "A Common Lisp Package Manager"
:license "BSD-2-Clause"
:pathname "clpm/"
......
......@@ -4,119 +4,9 @@
;;;; LICENSE for license information.
(uiop:define-package #:clpm/version
(:use #:cl
#:clpm/version-strings)
(:use #:cl)
(:import-from #:clpm-asdf
#:clpm-version)
(:export #:clpm-version))
(in-package #:clpm/version)
;;; Application Version
;; NOTE: If this form changes position in this file you *must* update clpm.asd as
;; well.
(defparameter *version-for-asdf* "0.4.0"
"ASDF is overly picky about its version numbers. This should be the primary
version number (no prerelease info) as ~*base-version*~.")
(defparameter *base-version* "0.4.0"
"The base version number of CLPM.")
(defparameter *full-version* nil
"Cache the full version information as of when the executable was built. Is
NIL until an image is dumped and is set by ~cache-full-version~.")
(defun git-exists-p ()
"Returns T iff git exists and is callable."
(ignore-errors
(uiop:run-program '("git" "--version"))
(clpm-git '("describe"))
t))
(defun clpm-git (args &rest keys)
(uiop:with-current-directory ((asdf:system-relative-pathname :clpm ""))
(apply #'uiop:run-program
`("git" ,@args)
keys)))
(defun get-git-branch ()
(or
(ignore-errors
(clpm-git '("symbolic-ref" "--short" "HEAD")
:output '(:string :stripped t)))
"HEAD"))
(defun get-git-commit ()
(clpm-git '("rev-parse" "--short" "HEAD")
:output '(:string :stripped t)))
(defun get-git-dirty-p ()
(not (zerop (nth-value 2
(clpm-git '("diff-index" "--quiet" "HEAD")
:ignore-error-status t)))))
(defun get-git-describe (&optional ref)
(uiop:split-string
(clpm-git `("describe" "--tags" "--match" "v*" ,@(when ref (list ref)))
:output '(:string :stripped t))
:max 3
:separator '(#\-)))
(defun get-git-common-ancestor ()
(clpm-git '("merge-base" "HEAD" "origin/master")
:output '(:string :stripped t)))
(defun get-git-distance-from-master ()
(parse-integer (clpm-git '("rev-list" "--count" "HEAD" "--not" "origin/master")
:output '(:string :stripped t))))
(defun get-git-tag-p ()
(zerop (nth-value 2
(clpm-git '("describe" "--tags" "--exact-match" "HEAD")
:ignore-error-status t))))
(defun get-full-version ()
(if (git-exists-p)
(let ((git-branch (get-git-branch))
(git-describe (get-git-describe))
(git-dirty-p (get-git-dirty-p)))
(if (get-git-tag-p)
;; This is a tagged version, just return the base version number.
*base-version*
;; Here's the fun part, assemble the entire version string.
(destructuring-bind (primary-version prerelease-category build-meta)
(parse-semantic-version *base-version*)
(declare (ignore build-meta))
(unless prerelease-category
(setf prerelease-category '(0)))
(if (equal git-branch "master")
(format nil "~{~A~^.~}-~{~A~^.~}.~A+~A~:[~;-dirty~]"
primary-version
prerelease-category
(second git-describe)
(third git-describe)
git-dirty-p)
(let* ((ancestor (get-git-common-ancestor))
(ancestor-describe (get-git-describe ancestor))
(distance-from-master (get-git-distance-from-master)))
(format nil "~{~A~^.~}-~{~A~^.~}.~A.0.~A.~A+~A~:[~;-dirty~]"
primary-version prerelease-category
(second ancestor-describe)
git-branch
distance-from-master
(third git-describe)
git-dirty-p))))))
;; We don't have git... Best we can currently do is return the base
;; version number.
*base-version*))
(defun cache-full-version ()
"Cache the full version into ~*full-version*~."
(setf *full-version* (get-full-version)))
(uiop:register-image-dump-hook 'cache-full-version)
(defun clpm-version ()
"Return the CLPM version string."
(or
*full-version*
(get-full-version)))
;;;; -*- Mode: common-lisp; -*-
;;;;
;;;; This file contains a single string naming the version that is being
;;;; currently worked on. It should be bumped immediately after releasing the
;;;; version. This should not contain any prerelease info.
"0.4.0"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment