$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r62280 - trunk/tools/build/v2/util
From: steven_at_[hidden]
Date: 2010-05-27 17:24:26
Author: steven_watanabe
Date: 2010-05-27 17:24:26 EDT (Thu, 27 May 2010)
New Revision: 62280
URL: http://svn.boost.org/trac/boost/changeset/62280
Log:
Hack to update print targets when their contents change.  This should fix the ancient bug whereby boostbook_catalog.xml doesn't get updated when user-config-jam is changed
Text files modified: 
   trunk/tools/build/v2/util/print.jam |    74 ++++++++++++++++++++++++++++++++++++++++
   1 files changed, 74 insertions(+), 0 deletions(-)
Modified: trunk/tools/build/v2/util/print.jam
==============================================================================
--- trunk/tools/build/v2/util/print.jam	(original)
+++ trunk/tools/build/v2/util/print.jam	2010-05-27 17:24:26 EDT (Thu, 27 May 2010)
@@ -12,6 +12,9 @@
 import numbers ;
 import string ;
 import regex ;
+import "class" ;
+import scanner ;
+import path ;
 
 # The current output target. Defaults to console.
 output-target = console ;
@@ -341,6 +344,11 @@
         text-content on $(output-target) = ;
         
         text-action $(output-target) ;
+
+        if $(overwrite) && $(output-target) != console
+        {
+            check-for-update $(output-target) ;
+        }
     }
     $(output-target).text-$(prefix-body-suffix) += $(strings) ;
     text-content on $(output-target) =
@@ -394,6 +402,72 @@
 }
 
 
+rule get-scanner ( )
+{
+    if ! $(.scanner)
+    {
+        .scanner = [ class.new print-scanner ] ;
+    }
+    return $(.scanner) ;
+}
+
+
+# The following code to update print targets when their contents
+# change is a horrible hack.  It basically creates a target which
+# binds to this file (print.jam) and installs a scanner on it
+# which reads the target and compares its contents to the new
+# contents that we're writing.
+#
+rule check-for-update ( target )
+{
+    local scanner = [ get-scanner ] ;
+    local file = [ path.native [ modules.binding $(__name__) ] ] ;
+    local g = [ MATCH <(.*)> : $(target:G) ] ;
+    local dependency-target = $(__file__:G=$(g)-$(target:G=)-$(scanner)) ;
+    DEPENDS $(target) : $(dependency-target) ;
+    SEARCH on $(dependency-target) = $(file:D) ;
+    ISFILE $(dependency-target) ;
+    NOUPDATE $(dependency-target) ;
+    base on $(dependency-target) = $(target) ;
+    scanner.install $(scanner) : $(dependency-target) none ;
+    return $(dependency-target) ;
+}
+
+
+class print-scanner : scanner
+{
+    import path ;
+    import os ;
+
+    rule pattern ( )
+    {
+        return "(One match...)" ;
+    }
+
+    rule process ( target : matches * : binding )
+    {
+        local base = [ on $(target) return $(base) ] ;
+        local nl = [ on $(base) return $(nl) ] ;
+        local text-content = [ on $(base) return $(text-content) ] ;
+        local dir = [ path.make [ on $(base) return $(LOCATE) ] ] ;
+        local file = [ path.native [ path.join $(dir) $(base:G=) ] ] ;
+        local actual-content ;
+        if [ os.name ] = NT
+        {
+            actual-content = [ SHELL "type \"$(file)\" 2>nul" ] ;
+        }
+        else
+        {
+            actual-content = [ SHELL "cat \"$(file)\" 2>/dev/null" ] ;
+        }
+        if $(text-content:J=$(nl)) != $(actual-content)
+        {
+            ALWAYS $(base) ;
+        }
+    }
+}
+
+
 rule __test__ ( )
 {
     import assert ;