Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / 7d / 56df8668a15688a5b4510328040d78151c1134
1 Return-Path: <amdragon@mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 18AD1431FC9\r
6         for <notmuch@notmuchmail.org>; Fri, 17 May 2013 13:13:50 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id vo4gRRxCiyal for <notmuch@notmuchmail.org>;\r
16         Fri, 17 May 2013 13:13:42 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
18         [18.9.25.14])\r
19         by olra.theworths.org (Postfix) with ESMTP id DC1BF431FC7\r
20         for <notmuch@notmuchmail.org>; Fri, 17 May 2013 13:13:41 -0700 (PDT)\r
21 X-AuditID: 1209190e-b7f4f6d000005142-85-51968f75759e\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 3F.92.20802.57F86915; Fri, 17 May 2013 16:13:41 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH-1.MIT.EDU [18.9.28.11])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id r4HKDct6013850; \r
27         Fri, 17 May 2013 16:13:38 -0400\r
28 Received: from drake.dyndns.org (26-4-182.dynamic.csail.mit.edu [18.26.4.182])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r4HKDaMa004347\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Fri, 17 May 2013 16:13:37 -0400\r
34 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1UdR20-0006Hn-BQ; Fri, 17 May 2013 16:13:36 -0400\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH] emacs: Compute build dependencies to fix byte compile issues\r
40 Date: Fri, 17 May 2013 16:13:31 -0400\r
41 Message-Id: <1368821611-24110-1-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.10.4\r
43 MIME-Version: 1.0\r
44 Content-Type: text/plain; charset=UTF-8\r
45 Content-Transfer-Encoding: 8bit\r
46 X-Brightmail-Tracker:\r
47  H4sIAAAAAAAAA+NgFnrNIsWRmVeSWpSXmKPExsUixCmqrVvaPy3Q4Mw7SYvrN2cyOzB6PFt1\r
48         izmAMYrLJiU1J7MstUjfLoErY8HcdWwFm1QqjjQfYGxgnCfbxcjJISFgIvHp3TdGCFtM4sK9\r
49         9WwgtpDAPkaJObMtuxi5gOyNjBILTvayQThHmCSaTm5ngaiayyixeFIhiM0moCGxbf9ysEki\r
50         AtISO+/OZu1i5OBgFlCT+NOlAhIWFiiUOLf+PDOIzSKgKjF55xWwMbwCDhKNVxezQByhKNH9\r
51         bAIbRFxQ4uTMJywQY9Ql1s8TAgkzC8hLNG+dzTyBUWAWkqpZCFWzkFQtYGRexSibklulm5uY\r
52         mVOcmqxbnJyYl5dapGusl5tZopeaUrqJERyOknw7GL8eVDrEKMDBqMTD+8F1WqAQa2JZcWXu\r
53         IUZJDiYlUV6HbqAQX1J+SmVGYnFGfFFpTmrxIUYJDmYlEd7nxUA53pTEyqrUonyYlDQHi5I4\r
54         75WUm/5CAumJJanZqakFqUUwWRkODiUJ3ug+oEbBotT01Iq0zJwShDQTByfIcB6g4aIgNbzF\r
55         BYm5xZnpEPlTjLocbV8nv2MUYsnLz0uVEud1BikSACnKKM2DmwNLI68YxYHeEuaNAKniAaYg\r
56         uEmvgJYwAS1hvTYVZElJIkJKqoExegbzzKctLEe4vqeKJdx6GVjpFBSW16X0W3T/alWOtDPR\r
57         IY+OaSxhXu9xsXSVTJbmrs1/ONMDqw/M1Ntt3nZWredbQINs2RMjTp1Jd73TnZafnSiXHGn+\r
58         Ma3x8z2TV99nqiks/xGzxCDSzvZ7+cag/0IJH2t4+sQOLLia3sEjEf688MTURYxKLMUZiYZa\r
59         zEXFiQC79NZG/gIAAA==\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Fri, 17 May 2013 20:13:50 -0000\r
73 \r
74 Previously, we simply byte compiled each Elisp source file\r
75 independently.  This is actually the wrong thing to do and can lead to\r
76 issues with macros and performance issues with substitutions because\r
77 1) when the byte compiler encounters a (require 'x) form, it will load\r
78 x.elc in preference to x.el, even if x.el is newer, and as a result\r
79 may load old macro and substitution definitions and 2) if we update a\r
80 macro or substitution definition in one file, we currently won't\r
81 re-compile other files that depend on the file containing the\r
82 definition.\r
83 \r
84 This patch addresses these problems by computing make dependency rules\r
85 from the (require 'x) forms in the Elisp source files, which we inject\r
86 into make's dependency database.\r
87 ---\r
88  emacs/Makefile.local |   12 +++++++++\r
89  emacs/make-deps.el   |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
90  2 files changed, 78 insertions(+)\r
91  create mode 100644 emacs/make-deps.el\r
92 \r
93 diff --git a/emacs/Makefile.local b/emacs/Makefile.local\r
94 index fb82247..456700a 100644\r
95 --- a/emacs/Makefile.local\r
96 +++ b/emacs/Makefile.local\r
97 @@ -22,6 +22,18 @@ emacs_images := \\r
98  \r
99  emacs_bytecode = $(emacs_sources:.el=.elc)\r
100  \r
101 +# Because of defmacro's and defsubst's, we have to account for load\r
102 +# dependencies between Elisp files when byte compiling.  Otherwise,\r
103 +# the byte compiler may load an old .elc file when processing a\r
104 +# "require" or we may fail to rebuild a .elc that depended on a macro\r
105 +# from an updated file.\r
106 +$(dir)/.eldeps: $(dir)/Makefile.local $(dir)/make-deps.el $(emacs_sources)\r
107 +       $(call quiet,EMACS) --directory emacs -batch -l make-deps.el \\r
108 +               -f batch-make-deps $(emacs_sources) > $@.tmp && \\r
109 +               (cmp -s $@.tmp $@ || mv $@.tmp $@)\r
110 +-include $(dir)/.eldeps\r
111 +CLEAN+=$(dir)/.eldeps $(dir)/.eldeps.tmp\r
112 +\r
113  %.elc: %.el $(global_deps)\r
114         $(call quiet,EMACS) --directory emacs -batch -f batch-byte-compile $<\r
115  \r
116 diff --git a/emacs/make-deps.el b/emacs/make-deps.el\r
117 new file mode 100644\r
118 index 0000000..a1cd731\r
119 --- /dev/null\r
120 +++ b/emacs/make-deps.el\r
121 @@ -0,0 +1,66 @@\r
122 +;; make-deps.el --- compute make dependencies for Elisp sources\r
123 +;;\r
124 +;; Copyright © Austin Clements\r
125 +;;\r
126 +;; This file is part of Notmuch.\r
127 +;;\r
128 +;; Notmuch is free software: you can redistribute it and/or modify it\r
129 +;; under the terms of the GNU General Public License as published by\r
130 +;; the Free Software Foundation, either version 3 of the License, or\r
131 +;; (at your option) any later version.\r
132 +;;\r
133 +;; Notmuch is distributed in the hope that it will be useful, but\r
134 +;; WITHOUT ANY WARRANTY; without even the implied warranty of\r
135 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
136 +;; General Public License for more details.\r
137 +;;\r
138 +;; You should have received a copy of the GNU General Public License\r
139 +;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.\r
140 +;;\r
141 +;; Authors: Austin Clements <aclements@csail.mit.edu>\r
142 +\r
143 +(defun batch-make-deps ()\r
144 +  "Invoke `make-deps' for each file on the command line."\r
145 +\r
146 +  (setq debug-on-error t)\r
147 +  (dolist (file command-line-args-left)\r
148 +    (let ((default-directory command-line-default-directory))\r
149 +      (find-file-literally file))\r
150 +    (make-deps command-line-default-directory))\r
151 +  (kill-emacs))\r
152 +\r
153 +(defun make-deps (&optional dir)\r
154 +  "Print make dependencies for the current buffer.\r
155 +\r
156 +This prints make dependencies to `standard-output' based on the\r
157 +top-level `require' expressions in the current buffer.  Paths in\r
158 +rules will be given relative to DIR, or `default-directory'."\r
159 +\r
160 +  (setq dir (or dir default-directory))\r
161 +  (save-excursion\r
162 +    (goto-char (point-min))\r
163 +    (condition-case nil\r
164 +       (while t\r
165 +         (let ((form (read (current-buffer))))\r
166 +           ;; Is it a (require 'x) form?\r
167 +           (when (and (listp form) (= (length form) 2)\r
168 +                      (eq (car form) 'require)\r
169 +                      (listp (cadr form)) (= (length (cadr form)) 2)\r
170 +                      (eq (car (cadr form)) 'quote)\r
171 +                      (symbolp (cadr (cadr form))))\r
172 +             ;; Find the required library\r
173 +             (let* ((name (cadr (cadr form)))\r
174 +                    (fname (locate-library (symbol-name name))))\r
175 +               ;; Is this file and the library in the same directory?\r
176 +               ;; If not, assume it's a system library and don't\r
177 +               ;; bother depending on it.\r
178 +               (when (and fname\r
179 +                          (string= (file-name-directory (buffer-file-name))\r
180 +                                   (file-name-directory fname)))\r
181 +                 ;; Print the dependency\r
182 +                 (princ (format "%s.elc: %s.elc\n"\r
183 +                                (file-name-sans-extension\r
184 +                                 (file-relative-name (buffer-file-name) dir))\r
185 +                                (file-name-sans-extension\r
186 +                                 (file-relative-name fname dir)))))))))\r
187 +      (end-of-file nil))))\r
188 -- \r
189 1.7.10.4\r
190 \r