version.el 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. ;;; version.el --- record version number of Emacs
  2. ;; Copyright (C) 1985, 1992, 1994-1995, 1999-2017 Free Software
  3. ;; Foundation, Inc.
  4. ;; Maintainer: emacs-devel@gnu.org
  5. ;; Keywords: internal
  6. ;; Package: emacs
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;;; Code:
  20. (defconst emacs-major-version
  21. (progn (string-match "^[0-9]+" emacs-version)
  22. (string-to-number (match-string 0 emacs-version)))
  23. "Major version number of this version of Emacs.
  24. This variable first existed in version 19.23.")
  25. (defconst emacs-minor-version
  26. (progn (string-match "^[0-9]+\\.\\([0-9]+\\)" emacs-version)
  27. (string-to-number (match-string 1 emacs-version)))
  28. "Minor version number of this version of Emacs.
  29. This variable first existed in version 19.23.")
  30. (defconst emacs-build-system (system-name)
  31. "Name of the system on which Emacs was built, or nil if not available.")
  32. (defconst emacs-build-time (if emacs-build-system (current-time))
  33. "Time at which Emacs was dumped out, or nil if not available.")
  34. (defconst emacs-build-number 1 ; loadup.el may increment this
  35. "The build number of this version of Emacs.
  36. This is an integer that increments each time Emacs is built in a given
  37. directory (without cleaning). This is likely to only be relevant when
  38. developing Emacs.")
  39. (defvar motif-version-string)
  40. (defvar gtk-version-string)
  41. (defvar ns-version-string)
  42. (defvar cairo-version-string)
  43. (defun emacs-version (&optional here)
  44. "Return string describing the version of Emacs that is running.
  45. If optional argument HERE is non-nil, insert string at point.
  46. Don't use this function in programs to choose actions according
  47. to the system configuration; look at `system-configuration' instead."
  48. (interactive "P")
  49. (let ((version-string
  50. (format "GNU Emacs %s (build %s, %s%s%s%s)%s"
  51. emacs-version
  52. emacs-build-number
  53. system-configuration
  54. (cond ((featurep 'motif)
  55. (concat ", " (substring motif-version-string 4)))
  56. ((featurep 'gtk)
  57. (concat ", GTK+ Version " gtk-version-string))
  58. ((featurep 'x-toolkit) ", X toolkit")
  59. ((featurep 'ns)
  60. (format ", NS %s" ns-version-string))
  61. (t ""))
  62. (if (featurep 'cairo)
  63. (format ", cairo version %s" cairo-version-string)
  64. "")
  65. (if (and (boundp 'x-toolkit-scroll-bars)
  66. (memq x-toolkit-scroll-bars '(xaw xaw3d)))
  67. (format ", %s scroll bars"
  68. (capitalize (symbol-name x-toolkit-scroll-bars)))
  69. "")
  70. (if emacs-build-time
  71. (format-time-string (concat
  72. (if (called-interactively-p
  73. 'interactive)
  74. "" "\n")
  75. " of %Y-%m-%d")
  76. emacs-build-time)
  77. ""))))
  78. (if here
  79. (insert version-string)
  80. (if (called-interactively-p 'interactive)
  81. (message "%s" version-string)
  82. version-string))))
  83. ;; We hope that this alias is easier for people to find.
  84. (defalias 'version 'emacs-version)
  85. ;; Set during dumping, this is a defvar so that it can be setq'd.
  86. (defvar emacs-repository-version nil
  87. "String giving the repository revision from which this Emacs was built.
  88. Value is nil if Emacs was not built from a repository checkout,
  89. or if we could not determine the revision.")
  90. (define-obsolete-variable-alias 'emacs-bzr-version
  91. 'emacs-repository-version "24.4")
  92. (define-obsolete-function-alias 'emacs-bzr-get-version
  93. 'emacs-repository-get-version "24.4")
  94. (defun emacs-repository-version-git (dir)
  95. "Ask git itself for the version information for directory DIR."
  96. (message "Waiting for git...")
  97. (with-temp-buffer
  98. (let ((default-directory (file-name-as-directory dir)))
  99. (and (eq 0
  100. (with-demoted-errors "Error running git rev-parse: %S"
  101. (call-process "git" nil '(t nil) nil "rev-parse" "HEAD")))
  102. (progn (goto-char (point-min))
  103. (looking-at "[0-9a-fA-F]\\{40\\}"))
  104. (match-string 0)))))
  105. (defun emacs-repository-get-version (&optional dir external)
  106. "Try to return as a string the repository revision of the Emacs sources.
  107. The format of the returned string is dependent on the VCS in use.
  108. Value is nil if the sources do not seem to be under version
  109. control, or if we could not determine the revision. Note that
  110. this reports on the current state of the sources, which may not
  111. correspond to the running Emacs.
  112. Optional argument DIR is a directory to use instead of `source-directory'.
  113. Optional argument EXTERNAL is ignored."
  114. (emacs-repository-version-git (or dir source-directory)))
  115. ;; We put version info into the executable in the form that `ident' uses.
  116. (purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version))
  117. " $\n"))
  118. ;;; version.el ends here