Changeset c048987


Ignore:
Timestamp:
04/16/2019 07:30:02 AM (5 years ago)
Author:
Pierre Labastie <pierre@…>
Branches:
ablfs-more, legacy, trunk
Children:
2e2ac74
Parents:
bc2f591
Message:

BLFS: fix generation of install and test instructions (ticket #1721):

  • add a gen-install.xsl stylesheet for grouping all cases
  • add a mode="installation" attribute for templates
  • rewrite sect2 template so that the right templates are applied
  • adapt other templates so that they are compatible
  • rewording of some comments (no direct relation with the ticket)
Location:
BLFS/xsl
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • BLFS/xsl/scripts.xsl

    rbc2f591 rc048987  
    1010<!-- XSLT stylesheet to create shell scripts from "linear build" BLFS books. -->
    1111
    12 <!-- Check whether the book is sysv or systemd -->
     12<!-- parameters and global variables -->
     13  <!-- Check whether the book is sysv or systemd -->
    1314  <xsl:variable name="rev">
    1415    <xsl:choose>
     
    8182</xsl:variable>
    8283
    83 <xsl:variable name="list-stat-norm"
    84               select="concat(' ', normalize-space($list-stat),' ')"/>
     84  <xsl:variable name="list-stat-norm"
     85                select="concat(' ', normalize-space($list-stat),' ')"/>
     86
     87<!-- To be able to use the single quote in tests -->
     88  <xsl:variable name="APOS">'</xsl:variable>
     89
     90<!-- end parameters and global variables -->
     91
     92<!-- include the templates for the screen children of role="install" sect2 -->
     93  <xsl:include href="gen-install.xsl"/>
     94
     95<!--=================== Begin processing ========================-->
    8596
    8697  <xsl:template match="/">
    87     <xsl:apply-templates select="//sect1"/>
     98    <xsl:apply-templates select="//sect1[@id != 'bootscripts' and
     99                                         @id != 'systemd-units']"/>
    88100  </xsl:template>
    89101
     
    92104  <xsl:template match="sect1">
    93105
    94     <xsl:if test="@id != 'bootscripts' and @id != 'systemd-units'">
    95         <!-- The file names -->
    96       <xsl:variable name="filename" select="@id"/>
    97 
    98         <!-- The build order -->
    99       <xsl:variable name="position" select="position()"/>
    100       <xsl:variable name="order">
    101         <xsl:choose>
    102           <xsl:when test="string-length($position) = 1">
    103             <xsl:text>00</xsl:text>
    104             <xsl:value-of select="$position"/>
    105           </xsl:when>
    106           <xsl:when test="string-length($position) = 2">
    107             <xsl:text>0</xsl:text>
    108             <xsl:value-of select="$position"/>
    109           </xsl:when>
    110           <xsl:otherwise>
    111             <xsl:value-of select="$position"/>
    112           </xsl:otherwise>
    113         </xsl:choose>
    114       </xsl:variable>
     106      <!-- The file names -->
     107    <xsl:variable name="filename" select="@id"/>
     108
     109      <!-- The build order -->
     110    <xsl:variable name="position" select="position()"/>
     111    <xsl:variable name="order">
     112      <xsl:choose>
     113        <xsl:when test="string-length($position) = 1">
     114          <xsl:text>00</xsl:text>
     115          <xsl:value-of select="$position"/>
     116        </xsl:when>
     117        <xsl:when test="string-length($position) = 2">
     118          <xsl:text>0</xsl:text>
     119          <xsl:value-of select="$position"/>
     120        </xsl:when>
     121        <xsl:otherwise>
     122          <xsl:value-of select="$position"/>
     123        </xsl:otherwise>
     124      </xsl:choose>
     125    </xsl:variable>
    115126
    116127      <!-- Depuration code -->
    117       <xsl:message>
    118         <xsl:text>SCRIPT is </xsl:text>
    119         <xsl:value-of select="concat($order,'-z-',$filename)"/>
    120         <xsl:text>&#xA;    FTPDIR is </xsl:text>
    121         <xsl:value-of select="$filename"/>
    122         <xsl:text>&#xA;&#xA;</xsl:text>
    123       </xsl:message>
    124 
    125         <!-- Creating the scripts -->
    126       <exsl:document href="{$order}-z-{$filename}" method="text">
    127         <xsl:text>#!/bin/bash
     128    <xsl:message>
     129      <xsl:text>SCRIPT is </xsl:text>
     130      <xsl:value-of select="concat($order,'-z-',$filename)"/>
     131      <xsl:text>&#xA;    FTPDIR is </xsl:text>
     132      <xsl:value-of select="$filename"/>
     133      <xsl:text>&#xA;&#xA;</xsl:text>
     134    </xsl:message>
     135
     136      <!-- Creating the scripts -->
     137    <exsl:document href="{$order}-z-{$filename}" method="text">
     138      <xsl:text>#!/bin/bash
    128139set -e
    129140unset MAKELEVEL
    130 
    131 </xsl:text>
    132         <xsl:choose>
    133           <!-- Package page -->
    134           <xsl:when test="sect2[@role='package']">
    135             <!-- We build in a subdirectory, whose name may be needed
    136                  if using package management (see envars.conf), so
    137                  "export" it -->
    138             <xsl:text>export JH_PKG_DIR=</xsl:text>
    139             <xsl:value-of select="$filename"/>
    140             <xsl:text>
     141<!-- the above is needed for some packages -->
     142</xsl:text>
     143      <xsl:choose>
     144        <!-- Package page -->
     145        <xsl:when test="sect2[@role='package']">
     146          <!-- We build in a subdirectory, whose name may be needed
     147               if using package management (see envars.conf), so
     148               "export" it -->
     149          <xsl:text>export JH_PKG_DIR=</xsl:text>
     150          <xsl:value-of select="$filename"/>
     151          <xsl:text>
    141152SRC_DIR=${JH_SRC_ARCHIVE}${JH_SRC_SUBDIRS:+/${JH_PKG_DIR}}
    142153BUILD_DIR=${JH_BUILD_ROOT}${JH_BUILD_SUBDIRS:+/${JH_PKG_DIR}}
     
    147158
    148159<!-- If stats are requested, include some definitions and intitializations -->
    149             <xsl:if test="contains($list-stat-norm,concat(' ',@id,' '))">
    150               <xsl:text>INFOLOG=$(pwd)/info-${JH_PKG_DIR}
     160          <xsl:if test="contains($list-stat-norm,concat(' ',@id,' '))">
     161            <xsl:text>INFOLOG=$(pwd)/info-${JH_PKG_DIR}
    151162TESTLOG=$(pwd)/test-${JH_PKG_DIR}
    152163unset MAKEFLAGS
    153164#MAKEFLAGS=-j4
    154165echo MAKEFLAGS: $MAKEFLAGS > $INFOLOG
    155 > $TESTLOG
     166: > $TESTLOG
    156167PKG_DEST=${BUILD_DIR}/dest
    157168rm -rf $PKG_DEST
    158169
    159170</xsl:text>
    160             </xsl:if>
    161             <!-- Download code and build commands -->
    162             <xsl:apply-templates select="sect2"/>
    163             <!-- Clean-up -->
    164             <xsl:text>cd $BUILD_DIR
     171          </xsl:if>
     172        <!-- Download code and build commands -->
     173          <xsl:apply-templates select="sect2"/>
     174        <!-- Clean-up -->
     175          <xsl:text>cd $BUILD_DIR
    165176[[ -n "$JH_KEEP_FILES" ]] || </xsl:text>
    166             <!-- In some case, some files in the build tree are owned
    167                  by root -->
    168             <xsl:if test="$sudo='y'">
    169               <xsl:text>sudo </xsl:text>
    170             </xsl:if>
    171             <xsl:text>rm -rf $JH_UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
    172           </xsl:when>
    173           <!-- Non-package page -->
    174           <xsl:otherwise>
    175             <xsl:apply-templates select=".//screen" mode="not-pack"/>
    176           </xsl:otherwise>
    177         </xsl:choose>
    178         <xsl:text>exit</xsl:text>
    179       </exsl:document>
    180     </xsl:if><!-- id!=bootscript or id!=systemd-units -->
     177        <!-- In some case, some files in the build tree are owned
     178             by root -->
     179          <xsl:if test="$sudo='y'">
     180            <xsl:text>sudo </xsl:text>
     181          </xsl:if>
     182          <xsl:text>rm -rf $JH_UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
     183        </xsl:when>
     184      <!-- Non-package page -->
     185        <xsl:otherwise>
     186          <xsl:apply-templates select=".//screen" mode="not-pack"/>
     187        </xsl:otherwise>
     188      </xsl:choose>
     189      <xsl:text>exit</xsl:text>
     190    </exsl:document>
    181191  </xsl:template>
    182192
     
    185195  <xsl:template match="sect2">
    186196    <xsl:choose>
     197
    187198      <xsl:when test="@role = 'package'">
    188199        <xsl:text>cd $SRC_DIR
     
    191202        <xsl:apply-templates select="bridgehead[@renderas='sect3']"/>
    192203        <xsl:text>&#xA;</xsl:text>
    193       </xsl:when>
     204      </xsl:when><!-- @role="package" -->
     205
    194206      <xsl:when test="@role = 'qt4-prefix' or @role = 'qt5-prefix'">
    195207        <xsl:apply-templates select=".//screen[./userinput]"/>
    196208      </xsl:when>
     209
    197210      <xsl:when test="@role = 'installation'">
    198211        <xsl:text>
     
    249262
    250263        <xsl:apply-templates
     264             mode="installation"
    251265             select=".//screen[not(@role = 'nodump') and ./userinput] |
    252                      .//para/command"/>
     266                     .//para/command[contains(text(),'check') or
     267                                     contains(text(),'test')]"/>
    253268        <xsl:if test="$sudo = 'y'">
    254269          <xsl:text>sudo /sbin/</xsl:text>
    255270        </xsl:if>
    256271        <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
    257       </xsl:when>
     272      </xsl:when><!-- @role="installation" -->
     273
    258274      <xsl:when test="@role = 'configuration'">
    259275        <xsl:apply-templates mode="config"
    260276             select=".//screen[not(@role = 'nodump') and ./userinput]"/>
    261       </xsl:when>
     277      </xsl:when><!-- @role="configuration" -->
     278
    262279    </xsl:choose>
    263280  </xsl:template>
     
    518535  </xsl:template>
    519536<!--======================== Commands code ==========================-->
     537<!-- Code for installation instructions is in gen-install.xsl -->
    520538
    521539  <xsl:template match="screen">
    522     <xsl:if test="child::* = userinput and not(@role = 'nodump')">
    523       <xsl:choose>
    524 <!-- First the case of installation instructions -->
    525         <xsl:when test="@role = 'root' and
    526                           ancestor::sect2[@role='installation'] and
    527                           not(contains(string(),'useradd')) and
    528                           not(contains(string(),'usermod')) and
    529                           not(contains(string(),'icon-cache')) and
    530                           not(contains(string(),'desktop-database')) and
    531                           not(contains(string(),'compile-schemas')) and
    532                           not(contains(string(),'groupadd'))">
    533           <xsl:if test="not(preceding-sibling::screen[1][@role='root'])">
    534             <xsl:if test="contains($list-stat-norm,
    535                                    concat(' ',
    536                                           ancestor::sect1/@id,
    537                                           ' '))">
    538               <xsl:call-template name="output-destdir"/>
    539             </xsl:if>
    540             <xsl:if test="$sudo = 'y'">
    541               <xsl:text>sudo -E sh &lt;&lt; ROOT_EOF&#xA;</xsl:text>
    542             </xsl:if>
    543             <xsl:if test="$wrap-install = 'y'">
    544               <xsl:text>if [ -r "$JH_PACK_INSTALL" ]; then
    545   source $JH_PACK_INSTALL
    546   export -f wrapInstall
    547   export -f packInstall
    548 fi
    549 wrapInstall '
    550 </xsl:text>
    551             </xsl:if>
     540    <xsl:choose>
     541<!-- instructions run as root (configuration mainly) -->
     542      <xsl:when test="@role = 'root'">
     543        <xsl:if test="not(preceding-sibling::screen[1][@role='root'])">
     544          <xsl:if test="$sudo = 'y'">
     545            <xsl:text>sudo -E sh &lt;&lt; ROOT_EOF&#xA;</xsl:text>
    552546          </xsl:if>
    553           <xsl:apply-templates mode="root"/>
    554           <xsl:if test="not(following-sibling::screen[1][@role='root'])">
    555             <xsl:if test="$del-la-files = 'y'">
    556               <xsl:call-template name="output-root">
    557                 <xsl:with-param name="out-string" select="$la-files-instr"/>
    558               </xsl:call-template>
    559             </xsl:if>
    560             <xsl:if test="$wrap-install = 'y'">
    561               <xsl:text>'&#xA;packInstall</xsl:text>
    562             </xsl:if>
    563             <xsl:if test="$sudo = 'y'">
    564               <xsl:text>&#xA;ROOT_EOF</xsl:text>
    565             </xsl:if>
     547        </xsl:if>
     548        <xsl:apply-templates mode="root"/>
     549        <xsl:if test="not(following-sibling::screen[1][@role='root'])">
     550          <xsl:if test="$sudo = 'y'">
     551            <xsl:text>&#xA;ROOT_EOF</xsl:text>
    566552          </xsl:if>
    567         </xsl:when>
    568 <!-- then the case of other instructions run as root (configuration mainly) -->
    569         <xsl:when test="@role = 'root'">
    570           <xsl:if test="not(preceding-sibling::screen[1][@role='root'])">
    571             <xsl:if test="$sudo = 'y'">
    572               <xsl:text>sudo -E sh &lt;&lt; ROOT_EOF&#xA;</xsl:text>
    573             </xsl:if>
    574           </xsl:if>
    575           <xsl:apply-templates mode="root"/>
    576           <xsl:if test="not(following-sibling::screen[1][@role='root'])">
    577             <xsl:if test="$sudo = 'y'">
    578               <xsl:text>&#xA;ROOT_EOF</xsl:text>
    579             </xsl:if>
    580           </xsl:if>
    581         </xsl:when>
     553        </xsl:if>
     554      </xsl:when>
    582555<!-- then all the instructions run as user -->
    583         <xsl:otherwise>
    584           <xsl:apply-templates select="userinput"/>
    585         </xsl:otherwise>
    586       </xsl:choose>
    587       <xsl:text>&#xA;</xsl:text>
    588     </xsl:if>
     556      <xsl:otherwise>
     557        <xsl:apply-templates select="userinput"/>
     558      </xsl:otherwise>
     559    </xsl:choose>
     560    <xsl:text>&#xA;</xsl:text>
    589561  </xsl:template>
    590562
     
    653625  </xsl:template>
    654626
    655   <xsl:template match="para/command">
     627  <xsl:template match="command" mode="installation">
    656628    <xsl:variable name="ns" select="normalize-space(string())"/>
    657     <xsl:if test="contains($ns,'test') or
    658                   contains($ns,'check')">
    659       <xsl:choose>
    660         <xsl:when test="contains($list-stat-norm,
    661                                  concat(' ',ancestor::sect1/@id,' '))">
     629    <xsl:variable name="first"
     630         select="not(
     631                   boolean(
     632                     preceding-sibling::command[contains(text(),'check') or
     633                                                contains(text(),'test')]))"/>
     634    <xsl:variable name="last"
     635         select="not(
     636                   boolean(
     637                     following-sibling::command[contains(text(),'check') or
     638                                                contains(text(),'test')]))"/>
     639    <xsl:choose>
     640      <xsl:when test="contains($list-stat-norm,
     641                               concat(' ',ancestor::sect1/@id,' '))">
     642        <xsl:if test="$first">
    662643          <xsl:text>
    663644echo Time after make: ${SECONDS} >> $INFOLOG
    664645echo Size after make: $(sudo du -skx --exclude home /) >> $INFOLOG
    665646echo Time before test: ${SECONDS} >> $INFOLOG
    666 </xsl:text>
    667         </xsl:when>
    668         <xsl:otherwise>
    669           <xsl:text>#</xsl:text>
    670         </xsl:otherwise>
    671       </xsl:choose>
    672       <xsl:choose>
    673         <xsl:when test="contains($ns,'make')">
    674           <xsl:value-of select="substring-before($ns,'make ')"/>
    675           <xsl:text>make </xsl:text>
    676           <xsl:if test="not(contains($ns,'-k'))">
    677             <xsl:text>-k </xsl:text>
    678           </xsl:if>
    679           <xsl:value-of select="substring-after($ns,'make ')"/>
    680         </xsl:when>
    681         <xsl:otherwise>
    682           <xsl:copy-of select="$ns"/>
    683         </xsl:otherwise>
    684       </xsl:choose>
     647
     648</xsl:text>
     649        </xsl:if>
     650      </xsl:when>
     651      <xsl:otherwise>
     652        <xsl:text>#</xsl:text>
     653      </xsl:otherwise>
     654    </xsl:choose>
     655    <xsl:choose>
     656      <xsl:when test="contains($ns,'make')">
     657        <xsl:value-of select="substring-before($ns,'make ')"/>
     658        <xsl:text>make </xsl:text>
     659        <xsl:if test="not(contains($ns,'-k'))">
     660          <xsl:text>-k </xsl:text>
     661        </xsl:if>
     662        <xsl:value-of select="substring-after($ns,'make ')"/>
     663      </xsl:when>
     664      <xsl:otherwise>
     665        <xsl:copy-of select="$ns"/>
     666      </xsl:otherwise>
     667    </xsl:choose>
     668    <xsl:if test="contains($list-stat-norm,
     669                           concat(' ',ancestor::sect1/@id,' '))">
     670      <xsl:text> &gt;&gt; $TESTLOG 2&gt;&amp;1</xsl:text>
     671    </xsl:if>
     672    <xsl:text> || true&#xA;</xsl:text>
    685673      <xsl:if test="contains($list-stat-norm,
    686                              concat(' ',ancestor::sect1/@id,' '))">
    687         <xsl:text> &gt;&gt; $TESTLOG 2&gt;&amp;1</xsl:text>
    688       </xsl:if>
    689       <xsl:text> || true&#xA;</xsl:text>
    690     </xsl:if>
     674                             concat(' ',ancestor::sect1/@id,' ')) and $last">
     675        <xsl:text>
     676echo Time after test: ${SECONDS} >> $INFOLOG
     677echo Size after test: $(sudo du -skx --exclude home /) >> $INFOLOG
     678echo Time before install: ${SECONDS} >> $INFOLOG
     679
     680</xsl:text>
     681        </xsl:if>
    691682  </xsl:template>
    692683
     
    701692  </xsl:template>
    702693
    703   <xsl:variable name="APOS">'</xsl:variable>
    704 
    705694  <xsl:template name="output-root">
    706695    <xsl:param name="out-string" select="''"/>
     
    748737          <xsl:with-param name="out-string"
    749738                          select="substring-after($out-string,'\')"/>
    750         </xsl:call-template>
    751       </xsl:when>
    752       <xsl:when test="contains($out-string,string($APOS))
    753                       and $wrap-install = 'y'
    754                       and ancestor::sect2[@role='installation']">
    755         <xsl:call-template name="output-root">
    756           <xsl:with-param name="out-string"
    757                           select="substring-before($out-string,string($APOS))"/>
    758         </xsl:call-template>
    759         <xsl:text>'\''</xsl:text>
    760         <xsl:call-template name="output-root">
    761           <xsl:with-param name="out-string"
    762                           select="substring-after($out-string,string($APOS))"/>
    763739        </xsl:call-template>
    764740      </xsl:when>
     
    830806
    831807  <xsl:template name="output-destdir">
    832 <!-- Hopefully, the current node is the first screen with role equal to root.
    833      We first output stats, since we are only called if stats are needed.
    834      then we output DESTDIR instructions,etc -->
    835     <xsl:text>
    836 echo Time after tests: ${SECONDS} >> $INFOLOG
    837 echo Size after tests: $(sudo du -skx --exclude home /) >> $INFOLOG
    838 echo Time before install: ${SECONDS} >> $INFOLOG
    839 </xsl:text>
    840808    <xsl:apply-templates
    841809       select="userinput|following-sibling::screen[@role='root']/userinput"
Note: See TracChangeset for help on using the changeset viewer.