]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/tools/xsltproc.jam
update sources to v12.2.3
[ceph.git] / ceph / src / boost / tools / build / src / tools / xsltproc.jam
1 # Copyright (C) 2003 Doug Gregor. Permission to copy, use, modify, sell and
2 # distribute this software is granted provided this copyright notice appears in
3 # all copies. This software is provided "as is" without express or implied
4 # warranty, and with no claim as to its suitability for any purpose.
5
6 # This module defines rules to apply an XSLT stylesheet to an XML file using the
7 # xsltproc driver, part of libxslt.
8
9 import common ;
10 import feature ;
11 import modules ;
12 import os ;
13 import path ;
14 import regex ;
15 import sequence ;
16
17
18 feature.feature xsl:param : : free ;
19 feature.feature xsl:path : : free ;
20 feature.feature catalog : : free ;
21
22
23 # Initialize xsltproc support. The parameters are:
24 # xsltproc: The xsltproc executable
25 #
26 rule init ( xsltproc ? )
27 {
28 if $(xsltproc)
29 {
30 modify-config ;
31 .xsltproc = $(xsltproc) ;
32 check-xsltproc ;
33 }
34 }
35
36
37 rule freeze-config ( )
38 {
39 if ! $(.config-frozen)
40 {
41 .config-frozen = true ;
42 .xsltproc ?= [ modules.peek : XSLTPROC ] ;
43 .xsltproc ?= xsltproc ;
44 check-xsltproc ;
45 .is-cygwin = [ .is-cygwin $(.xsltproc) ] ;
46 }
47 }
48
49
50 rule modify-config ( )
51 {
52 if $(.config-frozen)
53 {
54 import errors ;
55 errors.user-error
56 "xsltproc: Cannot change xsltproc command after it has been used." ;
57 }
58 }
59
60
61 rule check-xsltproc ( )
62 {
63 if $(.xsltproc)
64 {
65 local status = [ SHELL "\"$(.xsltproc)\" -V" : no-output : exit-status ]
66 ;
67 if $(status[2]) != 0
68 {
69 import errors ;
70 errors.user-error "xsltproc: Could not run \"$(.xsltproc)\" -V." ;
71 }
72 }
73 }
74
75 rule name ( )
76 {
77 freeze-config ;
78 return $(.xsltproc) ;
79 }
80
81 # Returns a non-empty string if a cygwin xsltproc binary was specified.
82 #
83 rule is-cygwin ( )
84 {
85 freeze-config ;
86 return $(.is-cygwin) ;
87 }
88
89
90 rule .is-cygwin ( xsltproc )
91 {
92 if [ os.on-windows ]
93 {
94 local file = [ path.make [ modules.binding $(__name__) ] ] ;
95 local dir = [ path.native [ path.join [ path.parent $(file) ] xsltproc ]
96 ] ;
97 if [ os.name ] = CYGWIN
98 {
99 dir = $(dir:W) ;
100 }
101 local command =
102 "\"$(xsltproc)\" \"$(dir)\\test.xsl\" \"$(dir)\\test.xml\" 2>&1" ;
103 local status = [ SHELL $(command) : no-output : exit-status ] ;
104 if $(status[2]) != "0"
105 {
106 return true ;
107 }
108 }
109 }
110
111
112 rule compute-xslt-flags ( target : properties * )
113 {
114 # Raw flags.
115 local flags = [ feature.get-values <flags> : $(properties) ] ;
116
117 # Translate <xsl:param> into command line flags.
118 for local param in [ feature.get-values <xsl:param> : $(properties) ]
119 {
120 local namevalue = [ regex.split $(param) "=" ] ;
121 flags += --stringparam $(namevalue[1]) \"$(namevalue[2])\" ;
122 }
123
124 # Translate <xsl:path>.
125 for local path in [ feature.get-values <xsl:path> : $(properties) ]
126 {
127 flags += --path \"$(path:G=)\" ;
128 }
129
130 # Take care of implicit dependencies.
131 local other-deps ;
132 for local dep in [ feature.get-values <implicit-dependency> : $(properties)
133 ]
134 {
135 other-deps += [ $(dep:G=).creating-subvariant ] ;
136 }
137
138 local implicit-target-directories ;
139 for local dep in [ sequence.unique $(other-deps) ]
140 {
141 implicit-target-directories += [ $(dep).all-target-directories ] ;
142 }
143
144 for local dir in $(implicit-target-directories)
145 {
146 flags += --path \"$(dir:T)\" ;
147 }
148
149 return $(flags) ;
150 }
151
152
153 local rule .xsltproc ( target : source stylesheet : properties * : dirname ? :
154 action )
155 {
156 freeze-config ;
157 STYLESHEET on $(target) = $(stylesheet) ;
158 FLAGS on $(target) += [ compute-xslt-flags $(target) : $(properties) ] ;
159 NAME on $(target) = $(.xsltproc) ;
160
161 for local catalog in [ feature.get-values <catalog> : $(properties) ]
162 {
163 CATALOG = [ common.variable-setting-command XML_CATALOG_FILES :
164 $(catalog:T) ] ;
165 }
166
167 if [ os.on-windows ] && ! [ is-cygwin ]
168 {
169 action = $(action).windows ;
170 }
171
172 $(action) $(target) : $(source) ;
173 }
174
175
176 rule xslt ( target : source stylesheet : properties * )
177 {
178 return [ .xsltproc $(target) : $(source) $(stylesheet) : $(properties) : :
179 xslt-xsltproc ] ;
180 }
181
182
183 rule xslt-dir ( target : source stylesheet : properties * : dirname )
184 {
185 return [ .xsltproc $(target) : $(source) $(stylesheet) : $(properties) :
186 $(dirname) : xslt-xsltproc-dir ] ;
187 }
188
189 actions xslt-xsltproc.windows
190 {
191 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<)" "$(STYLESHEET:W)" "$(>:W)"
192 }
193
194
195 actions xslt-xsltproc bind STYLESHEET
196 {
197 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<)" "$(STYLESHEET:T)" "$(>:T)"
198 }
199
200
201 actions xslt-xsltproc-dir.windows bind STYLESHEET
202 {
203 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<:D)/" "$(STYLESHEET:W)" "$(>:W)"
204 }
205
206
207 actions xslt-xsltproc-dir bind STYLESHEET
208 {
209 $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<:D)/" "$(STYLESHEET:T)" "$(>:T)"
210 }