bump-version 2.88 KB
Newer Older
1
#!/bin/sh
2 3 4
":" ; exec sbcl --script "$0" "$@" ; exit # -*- Lisp -*-
;;; Really runs on any decent Common Lisp implementation

5 6 7 8
(setf *load-verbose* nil *load-print* nil
      *compile-verbose* nil *compile-print* nil)

(format t "Loading ASDF... ~%")
9 10
(require :asdf)
(in-package :asdf)
11 12 13 14
#-asdf2 (error "Not ASDF2, you lose!")
(format t "Initializing the source registry... ~%")
(initialize-source-registry)
(format t "Making sure that's the latest... ~%")
15
(upgrade-asdf)
16
(format t "Now load some dependencies... ~%")
17 18 19 20
(load-systems :cl-ppcre :xcvb-utils)

(in-package :xcvb-utils)

21
(format t "And the debug utilities... ~%")
22 23
(asdf-debug)

24
(DBG "There we are!")
25 26
(resume-image)

27 28 29 30 31 32
(defun afile (x)
  (asdf:system-relative-pathname :asdf x))

(defparameter *version-file*
  (afile "version.lisp-expr"))

33 34
(defparameter *old-version* nil)
(defparameter *new-version* nil)
35 36 37 38 39 40

(defun next-version (v)
  (let ((pv (parse-version v)))
    (incf (third pv))
    (unparse-version pv)))

41 42 43 44 45 46 47 48 49 50 51 52
(defun version-from-file ()
  (safe-read-first-file-form *version-file*))

(defun versions-from-argv (argv)
  (ecase (length argv)
    ((2) (values (second argv) (first argv)))
    ((1) (values (version-from-file) (first argv)))
    ((0) (let ((old (version-from-file)))
           (values old (next-version old))))))

(multiple-value-setq (*old-version* *new-version*)
  (versions-from-argv *command-line-arguments*))
53 54 55 56 57 58 59

(format t "Bumping ASDF version from ~A to ~A~%" *old-version* *new-version*)

(deftype byte-vector () '(array (unsigned-byte 8) (*)))

(defun maybe-replace-file (file transformer
                           &key (reader 'read-file-string)
60
                             (writer nil) (comparator 'equalp)
61
                             (external-format *utf-8-external-format*))
62
  (format t "Transforming file ~A... " (file-namestring file))
63 64
  (let* ((old-contents (funcall reader file))
         (new-contents (funcall transformer old-contents)))
65
    (if (funcall comparator old-contents new-contents)
66
        (format t "no changes needed!~%")
67 68 69 70 71 72
        (let ((written-contents
                (if writer
                    (with-output (s ())
                      (funcall writer s new-contents))
                    new-contents)))
          (check-type written-contents (or string (byte-vector)))
73 74
          (clobber-file-with-vector file written-contents :external-format external-format)
          (format t "done.~%")))))
75 76 77 78 79 80 81

(defun version-transform (text)
  (flet ((v1 (ver) (format nil "~S" ver))
         (v2 (ver) (format nil "This is ASDF ~A:" ver))
         (f (fun text)
           (cl-ppcre:regex-replace-all
            (funcall fun *old-version*) text (funcall fun *new-version*))))
82
    (f #'v2 (f #'v1 text))))
83 84

(defparameter *versioned-files*
85
  '("version.lisp-expr" "asdf.asd" "header.lisp" "build/asdf.lisp" "upgrade.lisp"))
86 87 88 89 90

(defun transform-file (x)
  (maybe-replace-file (afile x) #'version-transform))

(map () 'transform-file *versioned-files*)