2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-14 00:32:11 +00:00

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]
This commit is contained in:
Steven Watanabe
2010-05-27 21:24:26 +00:00
parent 4e9d28a099
commit 532bc4ed1b

View File

@@ -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 ;