branch: elpa/vm
commit 6ada98940a73108744e7bbfc8831eda7eb5ec64a
Merge: 1e96a3c67b b845c4b1d4
Author: Mark Diekhans <ma...@ucsc.edu>
Commit: Mark Diekhans <ma...@ucsc.edu>

    Merge branch 'main' into 'main'
    
    switch to storing version and commit in a generate .el instead of text 
files...
    
    Closes #312
    
    See merge request emacs-vm/vm!40
---
 .gitignore                                         |  12 +-
 .../design}/elp-stuff-folder-data.txt              |   0
 {design => dev-docs/design}/passwords.org          |   0
 {design => dev-docs/design}/threading.txt          |   0
 {design => dev-docs/design}/virtual-revolution.txt |   0
 dev-docs/releasing.org                             |   3 +
 dev-tools/autoloads.py                             | 123 ++++++++++++++++++++
 getversion.sh                                      |  26 -----
 lisp/Makefile.in                                   |  31 ++---
 lisp/autoloads.py                                  | 126 ---------------------
 lisp/vm-version.el                                 |  75 ++++++------
 lisp/vm.el                                         |   8 +-
 12 files changed, 190 insertions(+), 214 deletions(-)

diff --git a/.gitignore b/.gitignore
index a82fb359c3..af79030249 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,6 @@ qp-decode.exe
 qp-encode.exe
 *.info*
 *.diff
-*.patch
 *.log
 *.aux
 *.cp*
@@ -37,12 +36,6 @@ config.status
 configure
 release
 snapshot
-info/version.texinfo
-lisp/version.txt
-/lisp/vm-autoloads.el
-/vm-autoloads.el
-/vm-pkg.el
-lisp/vm-cus-load.el
 *.orig
 *.rej
 *.saved
@@ -50,4 +43,9 @@ package-info
 _pkg.el
 commit.msg
 
+/info/version.texinfo
+/lisp/vm-autoloads.el
+/lisp/vm-version-conf.el
+/lisp/vm-cus-load.el
+
 .emacs.bak/
diff --git a/design/elp-stuff-folder-data.txt 
b/dev-docs/design/elp-stuff-folder-data.txt
similarity index 100%
rename from design/elp-stuff-folder-data.txt
rename to dev-docs/design/elp-stuff-folder-data.txt
diff --git a/design/passwords.org b/dev-docs/design/passwords.org
similarity index 100%
rename from design/passwords.org
rename to dev-docs/design/passwords.org
diff --git a/design/threading.txt b/dev-docs/design/threading.txt
similarity index 100%
rename from design/threading.txt
rename to dev-docs/design/threading.txt
diff --git a/design/virtual-revolution.txt 
b/dev-docs/design/virtual-revolution.txt
similarity index 100%
rename from design/virtual-revolution.txt
rename to dev-docs/design/virtual-revolution.txt
diff --git a/dev-docs/releasing.org b/dev-docs/releasing.org
new file mode 100644
index 0000000000..f74ac2c40f
--- /dev/null
+++ b/dev-docs/releasing.org
@@ -0,0 +1,3 @@
+Releasing VM
+
+
diff --git a/dev-tools/autoloads.py b/dev-tools/autoloads.py
new file mode 100755
index 0000000000..34a06f28b3
--- /dev/null
+++ b/dev-tools/autoloads.py
@@ -0,0 +1,123 @@
+#!/usr/bin/env python3
+# -*- python -*-
+
+##
+# program to find missing autoload tokens.
+##
+
+import sys
+
+def identifier_start(string, startpos=0):
+    # print string, startpos
+    while (startpos < len(string) and
+           ("() \t\r\n.,".find(string[startpos]) != -1)):
+        startpos = startpos + 1
+    return startpos
+
+def identifier_end(string, startpos=0):
+    # print string, startpos
+    while (startpos < len(string) and
+           ("() \t\r\n.,".find(string[startpos]) == -1)):
+        startpos = startpos + 1
+    return startpos
+
+class Def:
+    def __init__(self, filename, lineno, autoload, symbol):
+        self.filename = filename
+        self.lineno = lineno
+        self.autoload = autoload
+        self.symbol = symbol
+
+    def __str__(self):
+        return ("%s:%d %s %s" % (self.filename,
+                                 self.lineno,
+                                 self.symbol,
+                                 self.autoload))
+
+def find_defs(filename, pattern="(defun", pos=0):
+    """Find definitions of pattern in the given file.
+    Returns defined symbols."""
+    symbols = []
+
+    fd = open(filename)
+    lineno = 0
+    autoload = False
+    for l in fd:
+        lineno = lineno + 1
+        if l.startswith(";;;###autoload"):
+            autoload = True
+            continue
+        s = l.find(pattern)
+        if s == -1 or s != pos:
+            continue
+        s = identifier_start(l, s + len(pattern))
+        while "() \t\r\n.,".find(l[s]) != -1:
+            s = s + 1
+        e = identifier_end(l, s)
+        if s == e:
+            raise "Could not find identifier end in " + repr(l)
+            continue
+        symbols.append(Def(filename, lineno, autoload, l[s: e]))
+        autoload = False
+    fd.close()
+    return symbols
+
+preloaded = ["vm-version.el", "vm-misc.el", "vm-macro.el", "vm-folder.el",
+             "vm-summary.el", "vm-minibuf.el", "vm-motion.el", "vm-page.el",
+             "vm-mouse.el", "vm-window.el", "vm-menu.el", "vm-message.el",
+             "vm-toolbar.el", "vm.el", "vm-undo.el", "vm-mime.el",
+             "vm-vars.el"]
+
+def check_calls(filename, funs, missing):
+    fd = open(filename)
+    required = []
+    for l in fd:
+        s = l.find("(require")
+        if s != -1:
+            s = identifier_start(l, s + len("(require '"))
+            e = identifier_end(l, s)
+            required.append(l[s:e] + ".el")
+            continue
+
+        # check for calls to external function without autoloads or require
+        for c in l.split("("):
+            s = identifier_start(c, 0)
+            e = identifier_end(c, s)
+
+            # print repr(c)
+            s = identifier_start(c, 0)
+            e = identifier_end(c, s)
+            f = c[s:e]
+            if f not in funs:
+                continue
+            d = funs[f]
+            if ((d.filename != filename) and (not d.autoload) and
+                (d.filename not in preloaded) and
+                (d.filename not in required)):
+                # print preloaded
+                if d.filename not in missing:
+                    missing[d.filename] = []
+                if f not in missing[d.filename]:
+                    missing[d.filename].append(f)
+    fd.close()
+
+
+def main():
+    """emit cross references with missing autoloads"""
+    funs = {}
+    for filename in sys.argv[3:]:
+        for d in find_defs(filename):
+            if d.symbol in funs:
+                print("Duplicate %s <> %s" % (d, funs[d.symbol]))
+            else:
+                funs[d.symbol] = d
+    missing = {}
+    for filename in sys.argv[3:]:
+        check_calls(filename, funs, missing)
+    for f in missing.keys():
+        print(f)
+        for m in missing[f]:
+            print("\t", m)
+
+if __name__ == '__main__':
+    main()
diff --git a/getversion.sh b/getversion.sh
deleted file mode 100755
index 277bf7e037..0000000000
--- a/getversion.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/env bash
-# -*- shell-script -*-
-
-bzr="bzr --no-plugins --no-aliases"
-$bzr rocks > /dev/null || (echo "ERROR: cannot run bzr." && exit 1)
-nick=`$bzr nick`
-news=NEWS
-#news=`$bzr root`/NEWS
-tag=vm-`head -1 $news | cut -c 4-`
-devo=`head -1 $news | fgrep -s devo > /dev/null && echo devo`
-revno=`$bzr revno`
-
-if [ "$devo" = "devo" ] ; then
-  rdir=$tag-$revno
-  version=$rdir
-else
-  tag=(`$bzr tags --sort=time | tail -1`)
-  if [ "${tag[1]}" != "$revno" ]; then
-    echo "ERROR: No tag present at the head revision."
-    echo "ERROR: First you must create a release tag!"
-    exit -1
-  fi
-  tag=${tag[0]}
-  rdir=$tag
-  version=$tag
-fi
diff --git a/lisp/Makefile.in b/lisp/Makefile.in
index c4dcdbc257..aea42e8409 100644
--- a/lisp/Makefile.in
+++ b/lisp/Makefile.in
@@ -59,6 +59,7 @@ SOURCES += vm-virtual.el
 SOURCES += vm-window.el
 SOURCES += vm-w3m.el
 SOURCES += vm-w3.el
+SOURCES += vm-version-conf.el
 
 SOURCES += vcard.el
 SOURCES += tapestry.el
@@ -75,10 +76,7 @@ xemacs_OBJECTS = auto-autoloads.elc custom-load.elc
 
 OBJECTS = ${@EMACS_FLAVOR@_OBJECTS} $(SOURCES:.el=.elc)
 
-AUX_FILES = version.txt
-
 INSTALL_FILES += $(OBJECTS:.elc=.el) $(OBJECTS)
-INSTALL_FILES += $(AUX_FILES)
 
 # for autoload generation
 AUTOLOAD_PACKAGE_NAME = (setq autoload-package-name \"vm\")
@@ -124,17 +122,18 @@ all: $(OBJECTS)
 
 $(OBJECTS): $(AUTOLOADS)
 
-install: install-el install-elc install-aux
+install: install-el install-elc
 
 ##############################################################################
-vm-version.elc: vm-version.el version.txt
-
-version.txt:
-       echo "$(PACKAGE_VERSION)" > $@.tmp
+# Create file with version and commit
+vm-version-conf.el: Makefile
+       echo ";;; Generated file do not commit " > $@.tmp
+       echo '(defconst vm-version-config "'"$(PACKAGE_VERSION)"'")' >> $@.tmp
        if [ -d "$(GIT_DIR)" ]; then \
-               $(GIT) --git-dir="$(GIT_DIR)" rev-parse HEAD >> $@.tmp; \
+               commit=`$(GIT) --git-dir="$(GIT_DIR)" rev-parse HEAD`; \
+               echo '(defconst vm-version-commit-config "'"$${commit}"'")' >> 
$@.tmp ; \
        else \
-               echo "unknown" >> $@.tp; \
+               echo '(defconst vm-version-commit-config "unknown")' >> $@.tmp 
; \
        fi
        mv -f $@.tmp $@
 
@@ -169,9 +168,6 @@ vm-cus-load.el: $(SOURCES:%=@srcdir@/%)
 # XEmacs#s auto-autoloads and custom-load file
 auto-autoloads.el: $(SOURCES:%=@srcdir@/%)
        -$(RM) -f $@
-#      (build_dir=`pwd`; cd "@srcdir@"; \
-#       $(EMACS_PROG) $(FLAGS) -l autoload \
-#              -f vm-built-autoloads "@abs_builddir@/$@" "`pwd`")
        $(EMACS_COMP) \
                 -eval "$(AUTOLOAD_PACKAGE_NAME)" \
                 -eval "$(AUTOLOAD_FILE)" \
@@ -242,20 +238,13 @@ install-elc: all $(INSTALL_FILES)
            done;                                            \
        fi;
 
-install-aux: $(AUX_FILES)
-       $(INSTALL) -d -m 0755 "$(DESTDIR)$(lispdir)/"
-       for i in $(AUX_FILES); do                                 \
-           echo "Install $$i in $(DESTDIR)$(lispdir)/";   \
-           $(INSTALL_DATA) $$i "$(DESTDIR)$(lispdir)/";   \
-        done;
-
 ##############################################################################
 Makefile: @srcdir@/Makefile.in
        cd .. ; ./config.status
 
 ##############################################################################
 clean:
-       -$(RM) -f version.txt *.elc vm-autoloads.el auto-autoloads.el 
custom-load.el
+       -$(RM) -f vm-version-conf.el *.elc vm-autoloads.el auto-autoloads.el 
custom-load.el
 
 distclean: clean
        -$(RM) -f Makefile vm-cus-load.el
diff --git a/lisp/autoloads.py b/lisp/autoloads.py
deleted file mode 100755
index b7ebec2611..0000000000
--- a/lisp/autoloads.py
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/python
-# -*- python -*-
-
-import sys
-
-def identifier_start(string, startpos=0):
-    #print string, startpos
-    while (startpos < len(string) and
-          ("() \t\r\n.,".find(string[startpos]) != -1)):
-       startpos = startpos + 1
-    return startpos
-
-def identifier_end(string, startpos=0):
-    #print string, startpos
-    while (startpos < len(string) and
-          ("() \t\r\n.,".find(string[startpos]) == -1)):
-       startpos = startpos + 1
-    return startpos
-
-class Def:
-    def __init__(self, filename, lineno, autoload, symbol):
-       self.filename = filename
-       self.lineno = lineno
-       self.autoload = autoload
-       self.symbol = symbol
-    def __str__(self):
-       return ("%s:%d %s %s" % (self.filename,
-                                self.lineno,
-                                self.symbol,
-                                self.autoload))
-
-def find_defs(filename, pattern="(defun", pos=0):
-    """Find definitions of pattern in the given file.
-    Returns defined symbols."""
-    symbols = []
-
-    fd = open(filename)
-    lineno = 0
-    autoload = False
-    for l in fd:
-       lineno = lineno + 1
-       if l.startswith(";;;###autoload"):
-           autoload = True
-           continue
-       s = l.find(pattern)
-       if s == -1 or s != pos:
-           continue
-       s = identifier_start(l, s + len(pattern))
-       while "() \t\r\n.,".find(l[s]) != -1:
-           s = s + 1
-       e = identifier_end(l, s) 
-       if s == e:
-           raise "Could not find identifier end in " + repr(l)
-           continue
-       #print s, e
-       #print l[s : e]
-       symbols.append(Def(filename, lineno, autoload, l[s : e]))
-       autoload = False
-    fd.close()
-    return symbols
-
-preloaded = ["vm-version.el", "vm-misc.el", "vm-macro.el", "vm-folder.el",
-            "vm-summary.el", "vm-minibuf.el", "vm-motion.el", "vm-page.el",
-            "vm-mouse.el", "vm-window.el", "vm-menu.el", "vm-message.el",
-            "vm-toolbar.el", "vm.el", "vm-undo.el", "vm-mime.el",
-            "vm-vars.el"]
-
-def check_calls(filename, funs, missing):
-    #print "-" * 50
-    #print filename
-    fd = open(filename)
-    required = []
-    for l in fd:
-       s = l.find("(require")
-       if s != -1:
-           s = identifier_start(l, s + len("(require '" ))
-           e = identifier_end(l, s)
-           #print l[s:e], "*" * 50
-           required.append(l[s:e] + ".el")
-           #print required
-           continue
-                                  
-       # check for calls to external function without autoloads or require
-       for c in l.split("("):
-           s = identifier_start(c, 0)
-           e = identifier_end(c, s)
-               
-           #print repr(c)
-           s = identifier_start(c, 0)
-           e = identifier_end(c, s)
-           f = c[s:e]
-           if f not in funs:
-               continue
-           d = funs[f]
-           if ((d.filename != filename) and (not d.autoload) and
-               (d.filename not in preloaded) and
-               (d.filename not in required)):
-               #print preloaded
-               #print "'%s' : '%s' => '%s' %s" % (filename, f, d.filename,
-                                                 #d.filename in preloaded)
-               #print preloaded
-               if not missing.has_key(d.filename):
-                   missing[d.filename] = []
-               if f not in  missing[d.filename]:
-                   missing[d.filename].append(f)
-    fd.close()
-    
-
-# emit cross references with missing autoloads 
-if __name__ == '__main__':
-    funs = {}
-    for filename in sys.argv[3:]:
-       for d in find_defs(filename):
-           if funs.has_key(d.symbol):
-               print "Duplicate %s <> %s" % (d, funs[d.symbol])
-           else:
-               funs[d.symbol] = d
-    missing = {}
-    for filename in sys.argv[3:]:
-       check_calls(filename, funs, missing)
-    for f in missing.keys():
-       print f
-       for m in missing[f]:
-           print "\t", m
-       
-    
diff --git a/lisp/vm-version.el b/lisp/vm-version.el
index 0fece92b4f..03632f9b40 100644
--- a/lisp/vm-version.el
+++ b/lisp/vm-version.el
@@ -21,52 +21,61 @@
 ;;; Code:
 
 (require 'vm-macro)
+(require 'package)
 
 ;; Don't use vm-device-type here because it may not not be loaded yet.
 (declare-function device-type "vm-xemacs" ())
 (declare-function device-matching-specifier-tag-list "vm-xemacs" ())
 
-(defun vm-read-version-file (file-name line-number)
-  "Read the a line from of FILE-NAME, remove all whitespace, and return it as 
a string.
-Returns \"undefined\" if the file cannot be read."
-  (let ((file-path (expand-file-name
-                    file-name
-                    (and load-file-name (file-name-directory 
load-file-name)))))
-    (condition-case nil
-        (with-temp-buffer
-          (insert-file-contents-literally file-path)
-          (goto-char (point-min))
-          (forward-line (1- line-number))
-          (replace-regexp-in-string "\\s-" "" ; Remove all whitespace
-                                    (buffer-substring-no-properties
-                                      (line-beginning-position) 
(line-end-position))))
-      (file-error "undefined"))))
-
-(defconst vm-version (vm-read-version-file "version.txt" 1)
-  "Version number of VM.")
+(defun vm--version-info-from-conf ()
+  "Return version and commit from vm-version-conf.el if it exists."
+  (when (ignore-errors (load "vm-version-conf"))
+    (list vm-version-config vm-version-commit-config)))
+
+(defun vm--commit-from-package (pkg)
+  "Get commit hash from PKG, whether VC-installed or archive-installed."
+  (let ((desc (package-get-descriptor pkg)))
+    (or (when (package-vc-p desc)
+          (package-vc-commit desc))
+        (alist-get :commit (package-desc-extras desc)))))
+
+(defun vm--version-info-from-package ()
+  "Return version and commit if VM is loaded from a package."
+  (let ((package-version (vm-get-package-version)))
+    (if package-version
+        (list package-version (vm--commit-from-package 'vm))
+      (list nil nil))))
+
+;; Define vm-version and vm-version-commit
+(let ((version-info (or (vm--version-info-from-conf)
+                        (vm--version-info-from-package)
+                        (list nil nil))))
+  (defconst vm-version (nth 0 version-info)
+    "Version number of VM.")
+  (defconst vm-version-commit (nth 1 version-info)
+    "Git commit number of VM.")
+  (unless vm-version
+    (warn "Can't obtain vm-version from package or vm-version-conf.el"))
+  (unless vm-version-commit
+    (warn "Can't obtain vm-version-commit from package or 
vm-version-conf.el")))
 
 (defun vm-version ()
-  "Return the value of the variable `vm-version'."
+  "Display and return the value of the variable `vm-version'."
   (interactive)
   (when (vm-interactive-p)
-    (or (and (stringp vm-version)
-            (string-match "[0-9]" vm-version))
-       (error "Cannot determine VM version!"))
-    (message "VM version is: %s" vm-version))
-  vm-version)
-
-(defconst vm-version-commit (vm-read-version-file "version.txt" 2)
-  "git commit number of VM.")
+    (if vm-version
+        (message "VM version is: %s" vm-version)
+      (message "VM version was not discovered when VM was loaded"))
+  vm-version))
 
 (defun vm-version-commit ()
-  "Return the value of the variable `vm-version-commit'."
+  "Display and the value of the variable `vm-version-commit'."
   (interactive)
   (when (vm-interactive-p)
-    (or (and (stringp vm-version-commit)
-            (string-match "[a-f0-9]+" vm-version-commit))
-       (error "Cannot determine VM commit!"))
-    (message "VM commit is: %s" vm-version-commit))
-  vm-version-commit)
+    (if vm-version-commit
+        (message "VM commit is: %s" vm-version-commit)
+      (message "VM commit was not discovered when VM was loaded"))
+  vm-version-commit))
 
 (defun vm-menu-can-eval-item-name ()
   (and (featurep 'xemacs)
diff --git a/lisp/vm.el b/lisp/vm.el
index f80436248f..9c2a098eba 100644
--- a/lisp/vm.el
+++ b/lisp/vm.el
@@ -56,7 +56,7 @@
 (require 'vm-sort)
 (require 'vm-reply)
 (eval-when-compile (require 'cl-lib))
-
+(require 'package)
 
 (defvar enable-multibyte-characters)
 
@@ -1675,4 +1675,10 @@ draft messages."
 (autoload 'tapestry-nullify-tapestry-elements "tapestry")
 (autoload 'tapestry-remove-frame-parameters "tapestry")
 
+(defun vm-get-package-version ()
+  "Return version of VM if it was installed as a package"
+  ;; N.B. this must be in this file, as package-get-version wants
+  ;; to be called from the file containg the `Version:' header.
+  (package-get-version))
+
 ;;; vm.el ends here

Reply via email to