From 532bc4ed1bc3ba322c5892bb079b2d2e11580176 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Thu, 27 May 2010 21:24:26 +0000 Subject: [PATCH] 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 [SVN r62280] --- src/util/print.jam | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/util/print.jam b/src/util/print.jam index 464381b5c..9db214ed0 100644 --- a/src/util/print.jam +++ b/src/util/print.jam @@ -12,6 +12,9 @@ import modules ; 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 @@ rule text ( 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 @@ actions quietly text-action } +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 ;