source: BLFS/xsl/process-install.xsl@ 8fc6a47

ablfs-more legacy trunk
Last change on this file since 8fc6a47 was 8fc6a47, checked in by Pierre Labastie <pierre@…>, 5 years ago

BLFS/xsl: refactor the generation of installation instructions, owing to
the new remap="test/doc" attributes

  • Property mode set to 100644
File size: 21.2 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2
3<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 version="1.0">
5
6<!-- $Id: gen-install.xsl 4107 2019-06-15 15:26:23Z pierre $ -->
7
8 <xsl:template name="process-install">
9 <xsl:param name="instruction-tree"/>
10 <xsl:param name="want-stats"/>
11 <xsl:param name="root-seen"/>
12 <xsl:param name="install-seen"/>
13 <xsl:param name="test-seen"/>
14 <xsl:param name="doc-seen"/>
15
16<!-- Isolate the current instruction -->
17 <xsl:variable name="current-instr" select="$instruction-tree[1]"/>
18
19 <xsl:choose>
20<!-- First, if we have an empty tree, close everything and exit -->
21 <xsl:when test="not($current-instr)">
22 <xsl:if test="$install-seen">
23 <xsl:call-template name="end-install"/>
24 </xsl:if>
25 <xsl:if test="$root-seen">
26 <xsl:call-template name="end-root"/>
27 </xsl:if>
28 <xsl:if test="$doc-seen and not($root-seen)">
29 <xsl:call-template name="end-doc">
30 <xsl:with-param name="want-stats" select="$want-stats"/>
31 </xsl:call-template>
32 </xsl:if>
33 <xsl:if test="$test-seen">
34 <xsl:call-template name="end-test">
35 <xsl:with-param name="want-stats" select="$want-stats"/>
36 </xsl:call-template>
37 </xsl:if>
38 </xsl:when><!-- empty tree -->
39 <xsl:when test="$current-instr[@role='root' and @remap='test']">
40 <xsl:if test="$install-seen">
41 <xsl:call-template name="end-install"/>
42 </xsl:if>
43 <xsl:if test="$root-seen">
44 <xsl:call-template name="end-root"/>
45 </xsl:if>
46 <xsl:if test="$doc-seen and not($root-seen)">
47 <xsl:call-template name="end-doc">
48 <xsl:with-param name="want-stats" select="$want-stats"/>
49 </xsl:call-template>
50 </xsl:if>
51 <xsl:if test="not($test-seen)">
52 <xsl:call-template name="begin-test">
53 <xsl:with-param name="want-stats" select="$want-stats"/>
54 </xsl:call-template>
55 </xsl:if>
56 <xsl:call-template name="begin-root"/>
57 <xsl:choose>
58 <xsl:when test="$want-stats">
59 <xsl:apply-templates select="$current-instr" mode="root"/>
60 </xsl:when>
61 <xsl:otherwise>
62 <xsl:apply-templates select="$current-instr"
63 mode="root-comment-out"/>
64 </xsl:otherwise>
65 </xsl:choose>
66 <xsl:call-template name="process-install">
67 <xsl:with-param
68 name="instruction-tree"
69 select="$instruction-tree[position()>1]"/>
70 <xsl:with-param name="want-stats" select="$want-stats"/>
71 <xsl:with-param name="root-seen" select="boolean(1)"/>
72 <xsl:with-param name="install-seen" select="boolean(0)"/>
73 <xsl:with-param name="test-seen" select="boolean(1)"/>
74 <xsl:with-param name="doc-seen" select="boolean(0)"/>
75 </xsl:call-template>
76 </xsl:when><!-- role="root" and remap="test" -->
77 <xsl:when test="$current-instr[@role='root' and @remap='doc']">
78 <xsl:if test="$test-seen">
79 <xsl:call-template name="end-test">
80 <xsl:with-param name="want-stats" select="$want-stats"/>
81 </xsl:call-template>
82 </xsl:if>
83 <xsl:if test="$doc-seen and not($root-seen)">
84 <xsl:call-template name="end-doc">
85 <xsl:with-param name="want-stats" select="$want-stats"/>
86 </xsl:call-template>
87 </xsl:if>
88 <xsl:if test="not($root-seen)">
89 <xsl:call-template name="begin-root"/>
90 </xsl:if>
91 <xsl:if test="not($install-seen)">
92 <xsl:call-template name="begin-install"/>
93 </xsl:if>
94 <xsl:apply-templates select="$current-instr"
95 mode="install-comment-out"/>
96<!-- The above template ends with a commented line, so that if end-install
97 adds a closing single quote, it will not be seen. Add a CR to prevent
98 that -->
99 <xsl:text>
100</xsl:text>
101 <xsl:call-template name="process-install">
102 <xsl:with-param
103 name="instruction-tree"
104 select="$instruction-tree[position()>1]"/>
105 <xsl:with-param name="want-stats" select="$want-stats"/>
106 <xsl:with-param name="root-seen" select="boolean(1)"/>
107 <xsl:with-param name="install-seen" select="boolean(1)"/>
108 <xsl:with-param name="test-seen" select="boolean(0)"/>
109 <xsl:with-param name="doc-seen" select="boolean(1)"/>
110 </xsl:call-template>
111 </xsl:when><!--role="root" and remap="doc" -->
112 <xsl:when test="$current-instr[@role='root']">
113 <xsl:choose>
114 <xsl:when test="contains(string($current-instr),'useradd') or
115 contains(string($current-instr),'groupadd') or
116 contains(string($current-instr),'usermod') or
117 contains(string($current-instr),'icon-cache') or
118 contains(string($current-instr),'desktop-database') or
119 contains(string($current-instr),'compile-schemas') or
120 contains(string($current-instr),'query-loaders') or
121 contains(string($current-instr),'pam.d') or
122 contains(string($current-instr),'query-immodules')">
123 <xsl:if test="$install-seen">
124 <xsl:call-template name="end-install"/>
125 </xsl:if>
126 <xsl:if test="$test-seen">
127 <xsl:call-template name="end-test">
128 <xsl:with-param name="want-stats" select="$want-stats"/>
129 </xsl:call-template>
130 </xsl:if>
131 <xsl:if test="$doc-seen and not($root-seen)">
132 <xsl:call-template name="end-doc">
133 <xsl:with-param name="want-stats" select="$want-stats"/>
134 </xsl:call-template>
135 </xsl:if>
136 <xsl:if test="not($root-seen)">
137 <xsl:call-template name="begin-root"/>
138 </xsl:if>
139 <xsl:apply-templates select="$current-instr" mode="root"/>
140 <xsl:call-template name="process-install">
141 <xsl:with-param
142 name="instruction-tree"
143 select="$instruction-tree[position()>1]"/>
144 <xsl:with-param name="want-stats" select="$want-stats"/>
145 <xsl:with-param name="root-seen" select="boolean(1)"/>
146 <xsl:with-param name="install-seen" select="boolean(0)"/>
147 <xsl:with-param name="test-seen" select="boolean(0)"/>
148 <xsl:with-param name="doc-seen" select="boolean(0)"/>
149 </xsl:call-template>
150 </xsl:when><!-- end config as root -->
151 <xsl:otherwise><!-- we have a true install instruction -->
152 <xsl:if test="$test-seen">
153 <xsl:call-template name="end-test">
154 <xsl:with-param name="want-stats" select="$want-stats"/>
155 </xsl:call-template>
156 </xsl:if>
157 <xsl:if test="$doc-seen and not($root-seen)">
158 <xsl:call-template name="end-doc">
159 <xsl:with-param name="want-stats" select="$want-stats"/>
160 </xsl:call-template>
161 </xsl:if>
162 <xsl:if test="$want-stats and not($install-seen)">
163 <xsl:if test="$root-seen">
164 <xsl:call-template name="end-root"/>
165 </xsl:if>
166 <xsl:text>
167echo Time before install: ${SECONDS} >> $INFOLOG</xsl:text>
168 <xsl:apply-templates
169 select="$instruction-tree[@role='root']/userinput"
170 mode="destdir"/>
171 <xsl:text>
172
173echo Time after install: ${SECONDS} >> $INFOLOG
174echo Size after install: $(sudo du -skx --exclude home /) >> $INFOLOG
175</xsl:text>
176 <xsl:if test="$root-seen">
177 <xsl:call-template name="begin-root"/>
178 </xsl:if>
179 </xsl:if>
180 <xsl:if test="not($root-seen)">
181 <xsl:call-template name="begin-root"/>
182 </xsl:if>
183 <xsl:if test="not($install-seen)">
184 <xsl:call-template name="begin-install"/>
185 </xsl:if>
186 <xsl:apply-templates select="$current-instr" mode="install"/>
187 <xsl:call-template name="process-install">
188 <xsl:with-param
189 name="instruction-tree"
190 select="$instruction-tree[position()>1]"/>
191 <xsl:with-param name="want-stats" select="$want-stats"/>
192 <xsl:with-param name="root-seen" select="boolean(1)"/>
193 <xsl:with-param name="install-seen" select="boolean(1)"/>
194 <xsl:with-param name="test-seen" select="boolean(0)"/>
195 <xsl:with-param name="doc-seen" select="boolean(0)"/>
196 </xsl:call-template>
197 </xsl:otherwise><!-- end true install instruction -->
198 </xsl:choose>
199 </xsl:when><!-- role="root" and no remap -->
200 <xsl:when test="$current-instr[@remap='test'] or
201 $current-instr/self::command">
202 <xsl:if test="$install-seen">
203 <xsl:call-template name="end-install"/>
204 </xsl:if>
205 <xsl:if test="$root-seen">
206 <xsl:call-template name="end-root"/>
207 </xsl:if>
208 <xsl:if test="$doc-seen and not($root-seen)">
209 <xsl:call-template name="end-doc">
210 <xsl:with-param name="want-stats" select="$want-stats"/>
211 </xsl:call-template>
212 </xsl:if>
213 <xsl:if test="not($test-seen)">
214 <xsl:if test="not($doc-seen)">
215 <xsl:call-template name="end-make">
216 <xsl:with-param name="want-stats" select="$want-stats"/>
217 </xsl:call-template>
218 </xsl:if>
219 <xsl:call-template name="begin-test">
220 <xsl:with-param name="want-stats" select="$want-stats"/>
221 </xsl:call-template>
222 </xsl:if>
223 <xsl:choose>
224 <xsl:when test="$want-stats">
225 <xsl:apply-templates select="$current-instr"/>
226 </xsl:when>
227 <xsl:otherwise>
228 <xsl:apply-templates select="$current-instr" mode="comment-out"/>
229 </xsl:otherwise>
230 </xsl:choose>
231 <xsl:call-template name="process-install">
232 <xsl:with-param
233 name="instruction-tree"
234 select="$instruction-tree[position()>1]"/>
235 <xsl:with-param name="want-stats" select="$want-stats"/>
236 <xsl:with-param name="root-seen" select="boolean(0)"/>
237 <xsl:with-param name="install-seen" select="boolean(0)"/>
238 <xsl:with-param name="test-seen" select="boolean(1)"/>
239 <xsl:with-param name="doc-seen" select="boolean(0)"/>
240 </xsl:call-template>
241 </xsl:when><!-- no role, remap=test -->
242 <xsl:when test="$current-instr[@remap='doc']">
243 <xsl:if test="$install-seen">
244 <xsl:call-template name="end-install"/>
245 </xsl:if>
246 <xsl:if test="$root-seen">
247 <xsl:call-template name="end-root"/>
248 </xsl:if>
249 <xsl:if test="$test-seen">
250 <xsl:call-template name="end-test">
251 <xsl:with-param name="want-stats" select="$want-stats"/>
252 </xsl:call-template>
253 </xsl:if>
254 <xsl:if test="not($doc-seen) or $root-seen">
255 <xsl:if test="not($test-seen) and not($root-seen)">
256 <xsl:call-template name="end-make">
257 <xsl:with-param name="want-stats" select="$want-stats"/>
258 </xsl:call-template>
259 </xsl:if>
260 <xsl:call-template name="begin-doc">
261 <xsl:with-param name="want-stats" select="$want-stats"/>
262 </xsl:call-template>
263 </xsl:if>
264 <xsl:choose>
265 <xsl:when test="$want-stats">
266 <xsl:apply-templates select="$current-instr"/>
267 </xsl:when>
268 <xsl:otherwise>
269 <xsl:apply-templates select="$current-instr" mode="comment-out"/>
270 </xsl:otherwise>
271 </xsl:choose>
272 <xsl:call-template name="process-install">
273 <xsl:with-param
274 name="instruction-tree"
275 select="$instruction-tree[position()>1]"/>
276 <xsl:with-param name="want-stats" select="$want-stats"/>
277 <xsl:with-param name="root-seen" select="boolean(0)"/>
278 <xsl:with-param name="install-seen" select="boolean(0)"/>
279 <xsl:with-param name="test-seen" select="boolean(0)"/>
280 <xsl:with-param name="doc-seen" select="boolean(1)"/>
281 </xsl:call-template>
282 </xsl:when><!-- no role, remap="doc" -->
283 <xsl:otherwise><!-- no role no remap -->
284 <xsl:if test="$install-seen">
285 <xsl:call-template name="end-install"/>
286 </xsl:if>
287 <xsl:if test="$root-seen">
288 <xsl:call-template name="end-root"/>
289 </xsl:if>
290 <xsl:if test="$doc-seen and not($root-seen)">
291 <xsl:call-template name="end-doc">
292 <xsl:with-param name="want-stats" select="$want-stats"/>
293 </xsl:call-template>
294 </xsl:if>
295 <xsl:if test="$test-seen">
296 <xsl:call-template name="end-test">
297 <xsl:with-param name="want-stats" select="$want-stats"/>
298 </xsl:call-template>
299 </xsl:if>
300 <xsl:apply-templates select="$current-instr"/>
301 <xsl:call-template name="process-install">
302 <xsl:with-param
303 name="instruction-tree"
304 select="$instruction-tree[position()>1]"/>
305 <xsl:with-param name="want-stats" select="$want-stats"/>
306 <xsl:with-param name="root-seen" select="boolean(0)"/>
307 <xsl:with-param name="install-seen" select="boolean(0)"/>
308 <xsl:with-param name="test-seen" select="boolean(0)"/>
309 <xsl:with-param name="doc-seen" select="boolean(0)"/>
310 </xsl:call-template>
311 </xsl:otherwise><!-- no role, no remap -->
312 </xsl:choose>
313 </xsl:template>
314
315 <xsl:template match="userinput" mode="install-comment-out">
316 <xsl:text>
317</xsl:text>
318 <xsl:call-template name="output-comment-out">
319 <xsl:with-param name="out-string" select="string()"/>
320 <xsl:with-param name="process" select="'install'"/>
321 </xsl:call-template>
322 </xsl:template>
323
324 <xsl:template match="userinput|command" mode="root-comment-out">
325 <xsl:text>
326</xsl:text>
327 <xsl:call-template name="output-comment-out">
328 <xsl:with-param name="out-string" select="string()"/>
329 <xsl:with-param name="process" select="'root'"/>
330 </xsl:call-template>
331 </xsl:template>
332
333 <xsl:template match="userinput|command" mode="comment-out">
334 <xsl:text>
335</xsl:text>
336 <xsl:call-template name="output-comment-out">
337 <xsl:with-param name="out-string" select="string()"/>
338 <xsl:with-param name="process" select="'none'"/>
339 </xsl:call-template>
340 </xsl:template>
341
342 <xsl:template match="userinput" mode="install">
343 <xsl:text>
344</xsl:text>
345 <xsl:call-template name="output-install">
346 <xsl:with-param name="out-string" select="string()"/>
347 </xsl:call-template>
348 </xsl:template>
349
350 <xsl:template name="output-comment-out">
351<!-- Output instructions with each line commented out. The "process"
352 parameter is:
353 none: only output commented-out and remove ampersand
354 root: output commented out and remove ampersand,
355 with escaping of \, $, and `
356 install: same + escape ' -->
357 <xsl:param name="out-string"/>
358 <xsl:param name="process"/>
359 <xsl:choose>
360 <xsl:when test="contains($out-string,'&#xA;')">
361 <xsl:choose>
362 <xsl:when test="$process='install'">
363 <xsl:call-template name="output-install">
364 <xsl:with-param
365 name="out-string"
366 select="concat('# ',
367 substring-before($out-string,'&#xA;')
368 )"/>
369 </xsl:call-template>
370 </xsl:when>
371 <xsl:when test="$process='root'">
372 <xsl:call-template name="output-root">
373 <xsl:with-param
374 name="out-string"
375 select="concat('# ',
376 substring-before($out-string,'&#xA;')
377 )"/>
378 </xsl:call-template>
379 </xsl:when>
380 <xsl:otherwise>
381 <xsl:call-template name="remove-ampersand">
382 <xsl:with-param
383 name="out-string"
384 select="concat('# ',
385 substring-before($out-string,'&#xA;')
386 )"/>
387 </xsl:call-template>
388 </xsl:otherwise>
389 </xsl:choose>
390 <xsl:text>
391</xsl:text>
392 <xsl:call-template name="output-comment-out">
393 <xsl:with-param
394 name="out-string"
395 select="substring-after($out-string,'&#xA;')"/>
396 <xsl:with-param name="process" select="$process"/>
397 </xsl:call-template>
398 </xsl:when>
399 <xsl:otherwise>
400 <xsl:choose>
401 <xsl:when test="$process='install'">
402 <xsl:call-template name="output-install">
403 <xsl:with-param name="out-string"
404 select="concat('# ',$out-string)"/>
405 </xsl:call-template>
406 </xsl:when>
407 <xsl:when test="$process='root'">
408 <xsl:call-template name="output-root">
409 <xsl:with-param name="out-string"
410 select="concat('# ',$out-string)"/>
411 </xsl:call-template>
412 </xsl:when>
413 <xsl:otherwise>
414 <xsl:call-template name="remove-ampersand">
415 <xsl:with-param name="out-string"
416 select="concat('# ',$out-string)"/>
417 </xsl:call-template>
418 </xsl:otherwise>
419 </xsl:choose>
420 </xsl:otherwise>
421 </xsl:choose>
422 </xsl:template>
423
424 <xsl:template name="end-make">
425 <xsl:param name="want-stats"/>
426 <xsl:if test="$want-stats">
427 <xsl:text>
428
429echo Time after make: ${SECONDS} >> $INFOLOG
430echo Size after make: $(sudo du -skx --exclude home /) >> $INFOLOG</xsl:text>
431 </xsl:if>
432 </xsl:template>
433
434 <xsl:template name="begin-doc">
435 <xsl:param name="want-stats"/>
436 <xsl:if test="$want-stats">
437 <xsl:text>
438echo Time before doc: ${SECONDS} >> $INFOLOG
439</xsl:text>
440 </xsl:if>
441 </xsl:template>
442
443 <xsl:template name="begin-test">
444 <xsl:param name="want-stats"/>
445 <xsl:if test="$want-stats">
446 <xsl:text>
447echo Time before test: ${SECONDS} >> $INFOLOG
448</xsl:text>
449 </xsl:if>
450 </xsl:template>
451
452 <xsl:template name="begin-root">
453 <xsl:if test="$sudo='y'">
454 <xsl:text>
455sudo -E sh &lt;&lt; ROOT_EOF</xsl:text>
456 </xsl:if>
457 </xsl:template>
458
459 <xsl:template name="begin-install">
460 <xsl:if test="$wrap-install = 'y'">
461 <xsl:text>
462if [ -r "$JH_PACK_INSTALL" ]; then
463 source $JH_PACK_INSTALL
464 export -f wrapInstall
465 export -f packInstall
466fi
467wrapInstall '</xsl:text>
468 </xsl:if>
469 </xsl:template>
470
471 <xsl:template name="end-doc">
472 <xsl:param name="want-stats"/>
473 <xsl:if test="$want-stats">
474 <xsl:text>
475
476echo Time after doc: ${SECONDS} >> $INFOLOG
477echo Size after doc: $(sudo du -skx --exclude home /) >> $INFOLOG</xsl:text>
478 </xsl:if>
479 </xsl:template>
480
481 <xsl:template name="end-test">
482 <xsl:param name="want-stats"/>
483 <xsl:if test="$want-stats">
484 <xsl:text>
485
486echo Time after test: ${SECONDS} >> $INFOLOG
487echo Size after test: $(sudo du -skx --exclude home /) >> $INFOLOG</xsl:text>
488 </xsl:if>
489 </xsl:template>
490
491 <xsl:template name="end-root">
492 <xsl:if test="$sudo='y'">
493 <xsl:text>
494ROOT_EOF</xsl:text>
495 </xsl:if>
496 </xsl:template>
497
498 <xsl:template name="end-install">
499 <xsl:if test="$del-la-files = 'y'">
500 <xsl:call-template name="output-root">
501 <xsl:with-param name="out-string" select="$la-files-instr"/>
502 </xsl:call-template>
503 </xsl:if>
504 <xsl:if test="$wrap-install = 'y'">
505 <xsl:text>'&#xA;packInstall</xsl:text>
506 </xsl:if>
507 </xsl:template>
508
509 <xsl:template name="output-install">
510 <xsl:param name="out-string" select="''"/>
511 <xsl:choose>
512 <xsl:when test="starts-with($out-string, 'make ') or
513 contains($out-string,' make ') or
514 contains($out-string,'&#xA;make')">
515 <xsl:call-template name="output-install">
516 <xsl:with-param
517 name="out-string"
518 select="substring-before($out-string,'make ')"/>
519 </xsl:call-template>
520 <xsl:text>make -j1 </xsl:text>
521 <xsl:call-template name="output-install">
522 <xsl:with-param
523 name="out-string"
524 select="substring-after($out-string,'make ')"/>
525 </xsl:call-template>
526 </xsl:when>
527 <xsl:when test="contains($out-string,string($APOS))
528 and $wrap-install = 'y'">
529 <xsl:call-template name="output-root">
530 <xsl:with-param
531 name="out-string"
532 select="substring-before($out-string,string($APOS))"/>
533 </xsl:call-template>
534 <xsl:text>'\''</xsl:text>
535 <xsl:call-template name="output-install">
536 <xsl:with-param name="out-string"
537 select="substring-after($out-string,string($APOS))"/>
538 </xsl:call-template>
539 </xsl:when>
540 <xsl:otherwise>
541 <xsl:call-template name="output-root">
542 <xsl:with-param name="out-string" select="$out-string"/>
543 </xsl:call-template>
544 </xsl:otherwise>
545 </xsl:choose>
546 </xsl:template>
547
548</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.