[PATCH] Record dependencies during build instead of before
authorAustin Clements <amdragon@MIT.EDU>
Sun, 8 Apr 2012 04:01:50 +0000 (00:01 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:46:09 +0000 (09:46 -0800)
10/183b357e5826d2aec9f62141a1a06fa684a4f5 [new file with mode: 0644]

diff --git a/10/183b357e5826d2aec9f62141a1a06fa684a4f5 b/10/183b357e5826d2aec9f62141a1a06fa684a4f5
new file mode 100644 (file)
index 0000000..ed7fad1
--- /dev/null
@@ -0,0 +1,136 @@
+Return-Path: <amthrax@drake.mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 19C69431FAF\r
+       for <notmuch@notmuchmail.org>; Sat,  7 Apr 2012 21:01:59 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id XZmwpt6JB6VA for <notmuch@notmuchmail.org>;\r
+       Sat,  7 Apr 2012 21:01:58 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
+       [18.9.25.13])\r
+       by olra.theworths.org (Postfix) with ESMTP id 6B0BE431FAE\r
+       for <notmuch@notmuchmail.org>; Sat,  7 Apr 2012 21:01:58 -0700 (PDT)\r
+X-AuditID: 1209190d-b7fbf6d0000008ba-06-4f810db57211\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id C3.21.02234.5BD018F4; Sun,  8 Apr 2012 00:01:57 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q3841ueP019597; \r
+       Sun, 8 Apr 2012 00:01:56 -0400\r
+Received: from drake.mit.edu\r
+       (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [209.6.116.242]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3841run018608\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sun, 8 Apr 2012 00:01:56 -0400 (EDT)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amthrax@drake.mit.edu>)\r
+       id 1SGjK4-0006PU-PN; Sun, 08 Apr 2012 00:01:52 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] Record dependencies during build instead of before\r
+Date: Sun,  8 Apr 2012 00:01:50 -0400\r
+Message-Id: <1333857710-24511-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.9.1\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFprJIsWRmVeSWpSXmKPExsUixG6noruVt9HfYO5PHovrN2cyOzB6PFt1\r
+       izmAMYrLJiU1J7MstUjfLoErY/GHT4wFu8UqXixsYm5gnCzUxcjBISFgIjFlXlAXIyeQKSZx\r
+       4d56ti5GLg4hgX2MEuuvL2OEcNYzSnRNPsIM4dxjkljRfhKqbD6jRP+Pmawg/WwCGhLb9i9n\r
+       BLFFBKQldt6dzQqygllATeJPlwqIKSzgLDHjNg9IBYuAqsT/w1fYQWxeAQeJLT3PWCGuUJB4\r
+       tu440wRG3gWMDKsYZVNyq3RzEzNzilOTdYuTE/PyUot0jfRyM0v0UlNKNzGCQoBTkncH47uD\r
+       SocYBTgYlXh4H+5o8BdiTSwrrsw9xCjJwaQkymvE3egvxJeUn1KZkVicEV9UmpNafIhRgoNZ\r
+       SYT3/mGgct6UxMqq1KJ8mJQ0B4uSOK+q1js/IYH0xJLU7NTUgtQimKwMB4eSBK8UMNSFBItS\r
+       01Mr0jJzShDSTBycIMN5gIbzg9TwFhck5hZnpkPkTzEqSonzvucBSgiAJDJK8+B6YTH6ilEc\r
+       6BVh3jcgVTzA+IbrfgU0mAlocM2repDBJYkIKakGRglplo06D9Sfxfd7CSeV7bZrKlKZc9vg\r
+       +Z6tSS65hwt90tffvljwrfZL42kWeT8DTc8Qvs3vDXe6d7pbJPmwM67ZrbZCdNO/fRZn1399\r
+       /iDh+OYfxyNjFepWyq1f8z544+G5KmH5t41Ei9hvHha+rXlDR/ob4waVBXwt67yb91Rz5fxX\r
+       3xOjqsRSnJFoqMVcVJwIAHwCWW6sAgAA\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 08 Apr 2012 04:01:59 -0000\r
+\r
+Previously, the makefile created dependency files in a separate, first\r
+pass.  In particular, include-ing the dependency files would cause\r
+make to attempt to rebuild those files using the dependency-generation\r
+rules in the makefile.  Unfortunately, this approach required obtuse\r
+rules and silently delayed the start of the build process (by quite a\r
+bit on a clean tree without any dependency files).  Worse, this\r
+required the dependency files to themselves depend on all of the\r
+headers the source file depended on, which meant that, if a header\r
+file was removed, the depedency file could not be updated because of a\r
+missing dependency (!), which would cause make to silently fail.\r
+\r
+This patch eliminates the dependency generation rules and instead\r
+generates dependency files as a side-effect of the regular build rule.\r
+On the first build, we don't need to know the dependencies beforehand;\r
+the object file doesn't exist, so it will be built anyway.  On\r
+subsequent builds, if a header file is updated, the dependency rules\r
+generated by the previous build will force a rebuild.  If a source\r
+file is updated, the dependency rules may be stale, but it doesn't\r
+matter because the updated source file will force a rebuild.\r
+\r
+In the final case above, the stale dependency rules may refer to a\r
+header file that no longer exists but is also no longer needed.  In\r
+order to prevent this from breaking the build, we also pass gcc the\r
+-MP option, which generates phony targets for every depended-on header\r
+file, so make won't complain if it can't find them during a later\r
+build.\r
+---\r
+The description is way more complicated than the patch.\r
+\r
+ Makefile.local |   18 ++++--------------\r
+ 1 files changed, 4 insertions(+), 14 deletions(-)\r
+\r
+diff --git a/Makefile.local b/Makefile.local\r
+index 1131dea..525eda0 100644\r
+--- a/Makefile.local\r
++++ b/Makefile.local\r
+@@ -256,23 +256,12 @@ endif\r
+ quiet ?= $($(shell echo $1 | sed -e s'/ .*//'))\r
+ \r
+ %.o: %.cc $(global_deps)\r
++      @mkdir -p .deps/$(@D)\r
++      $(call quiet,CXX $(CXXFLAGS)) -c $(FINAL_CXXFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d\r
+-      $(call quiet,CXX $(CXXFLAGS)) -c $(FINAL_CXXFLAGS) $< -o $@\r
+ \r
+ %.o: %.c $(global_deps)\r
++      @mkdir -p .deps/$(@D)\r
++      $(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@ -MD -MP -MF .deps/$*.d\r
+-      $(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@\r
+-\r
+-.deps/%.d: %.c $(global_deps)\r
+-      @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \\r
+-      $(CC) -M $(CPPFLAGS) $(FINAL_CFLAGS) $< > $@.$$$$ 2>/dev/null ; \\r
+-      sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \\r
+-      rm -f $@.$$$$\r
+-\r
+-.deps/%.d: %.cc $(global_deps)\r
+-      @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \\r
+-      $(CXX) -M $(CPPFLAGS) $(FINAL_CXXFLAGS) $< > $@.$$$$ 2>/dev/null ; \\r
+-      sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \\r
+-      rm -f $@.$$$$\r
+ \r
+ .PHONY : clean\r
+ clean:\r
+-- \r
+1.7.9.1\r
+\r