-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4a6abc
commit 516ec5b
Showing
11 changed files
with
432 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
;;; gen-autoloads.el --- generate autoloads file -*- lexical-binding: t; -*- | ||
|
||
;; Copyright 2021 Google LLC | ||
;; | ||
;; Licensed under the Apache License, Version 2.0 (the "License"); | ||
;; you may not use this file except in compliance with the License. | ||
;; You may obtain a copy of the License at | ||
;; | ||
;; https://www.apache.org/licenses/LICENSE-2.0 | ||
;; | ||
;; Unless required by applicable law or agreed to in writing, software | ||
;; distributed under the License is distributed on an "AS IS" BASIS, | ||
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
;; See the License for the specific language governing permissions and | ||
;; limitations under the License. | ||
|
||
;;; Commentary: | ||
|
||
;; Generate an autoloads file. | ||
;; | ||
;; Usage: | ||
;; | ||
;; emacs --quick --batch --load=gen-autoloads.el \ | ||
;; --funcall=elisp/gen-autoloads-and-exit DEST SOURCE... | ||
;; | ||
;; Generates an autoloads file DEST for the SOURCE Emacs Lisp files. | ||
;; | ||
;; Exits with a zero status only if successful. | ||
|
||
;;; Code: | ||
|
||
(require 'autoload) | ||
(require 'cl-lib) | ||
(require 'nadvice) | ||
|
||
(defun elisp/gen-autoloads-and-exit () | ||
"Generate an autoloads file and exit Emacs. | ||
See the file commentary for details." | ||
(unless noninteractive | ||
(error "This function works only in batch mode")) | ||
|
||
;; Make output deterministic. | ||
;; The autoload definitions file contains the current time, therefore we | ||
;; override `current-time'. | ||
(advice-add 'current-time :override (lambda () '(0 0 0 0))) | ||
;; Return constant file attributes to make builds deterministic. | ||
(advice-add 'file-attributes :around | ||
(lambda (func &rest args) | ||
(let ((ret (apply func args))) | ||
(when ret | ||
(cl-destructuring-bind | ||
(type links uid gid atime mtime ctime size mode change inode dev) | ||
ret | ||
(list type links 0 0 '(0 0 0 0) '(0 0 0 0) '(0 0 0 0) | ||
size mode nil 42 42)))))) | ||
(add-to-list 'ignored-local-variables 'generated-autoload-file) | ||
|
||
(let* ((out (pop command-line-args-left)) | ||
(srcs command-line-args-left) | ||
;; Leaving these enabled leads to undefined behavior and doesn’t make | ||
;; sense in batch mode. | ||
(attempt-stack-overflow-recovery nil) | ||
(attempt-orderly-shutdown-on-fatal-signal nil) | ||
(create-lockfiles nil) | ||
(workdir (file-name-as-directory (make-temp-file "workdir" :dir))) | ||
(generated-autoload-file (expand-file-name (file-name-nondirectory out) workdir))) | ||
(unwind-protect | ||
(progn | ||
(write-region (autoload-rubric out "package" :feature) nil generated-autoload-file) | ||
(dolist (f srcs) | ||
(copy-file f workdir)) | ||
(update-directory-autoloads workdir) | ||
(copy-file generated-autoload-file out t)) | ||
(delete-directory workdir :recursive)) | ||
(kill-emacs 0))) | ||
|
||
(provide 'elisp/gen-autoloads) | ||
;;; gen-autoloads.el ends here |
Oops, something went wrong.