source: BLFS/xsl/dependencies.xsl@ 7dc8595

2.4 ablfs-more legacy new_features trunk
Last change on this file since 7dc8595 was 7dc8595, checked in by Pierre Labastie <pierre@…>, 9 years ago

Automate the process of choosing action when there are circular dependencies.
This has to be tested, but hopefully, it should allow to find a coherent
build order when there are not too many circular dependencies

  • Property mode set to 100644
File size: 6.8 KB
Line 
1<?xml version="1.0"?>
2
3<!-- $Id: dependencies.xsl 24 2012-02-16 15:26:15Z labastie $ -->
4
5<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6 version="1.0">
7
8 <xsl:output method="text"/>
9
10 <xsl:param name="MTA" select="'sendmail'"/>
11 <xsl:param name="dependencies" select="2"/>
12 <xsl:param name="idofdep" select="'dbus'"/>
13
14 <xsl:key name="depnode"
15 match="package|module"
16 use="name"/>
17
18 <xsl:template match="/">
19 <xsl:apply-templates select="key('depnode',$idofdep)"/>
20 </xsl:template>
21
22 <xsl:template match="package">
23 <xsl:apply-templates select="./dependency[@status='required']">
24 <xsl:with-param name="priority" select="1"/>
25 </xsl:apply-templates>
26 <xsl:if test="$dependencies &gt; '1'">
27 <xsl:apply-templates select="./dependency[@status='recommended']">
28 <xsl:with-param name="priority" select="2"/>
29 </xsl:apply-templates>
30 <xsl:if test="$dependencies = '3'">
31 <xsl:apply-templates select="./dependency[@status='optional']">
32 <xsl:with-param name="priority" select="3"/>
33 </xsl:apply-templates>
34 </xsl:if>
35 </xsl:if>
36 </xsl:template>
37
38 <xsl:template match="module">
39 <xsl:apply-templates select="./dependency[@status='required']">
40 <xsl:with-param name="priority" select="1"/>
41 </xsl:apply-templates>
42 <xsl:if test="$dependencies &gt; '1'">
43 <xsl:apply-templates select="./dependency[@status='recommended']">
44 <xsl:with-param name="priority" select="2"/>
45 </xsl:apply-templates>
46 <xsl:if test="$dependencies = '3'">
47 <xsl:apply-templates select="./dependency[@status='optional']">
48 <xsl:with-param name="priority" select="3"/>
49 </xsl:apply-templates>
50 </xsl:if>
51 </xsl:if>
52 </xsl:template>
53
54 <xsl:template match="dependency">
55 <xsl:param name="priority"/>
56 <xsl:variable name="depname">
57 <xsl:choose>
58 <xsl:when test="@name='xorg-env'"/>
59 <xsl:when test="@name='x-window-system'">xinit</xsl:when>
60 <xsl:when test="@name='xorg7'">xinit</xsl:when>
61 <xsl:when test="@name='server-mail'">
62 <xsl:value-of select="$MTA"/>
63 </xsl:when>
64 <xsl:otherwise>
65 <xsl:value-of select="@name"/>
66 </xsl:otherwise>
67 </xsl:choose>
68 </xsl:variable>
69 <xsl:variable name="install_it">
70 <xsl:choose>
71 <xsl:when test="@type='link'">
72<!-- No way to track versions: install ! -->
73 1
74 </xsl:when>
75 <xsl:otherwise>
76 <xsl:call-template name="compare-versions">
77 <xsl:with-param name="version" select="key('depnode',$depname)/version"/>
78 <xsl:with-param name="inst-version" select="key('depnode',$depname)/inst-version"/>
79 </xsl:call-template>
80 </xsl:otherwise>
81 </xsl:choose>
82 </xsl:variable>
83 <xsl:apply-templates select="dependency">
84 <xsl:with-param name="priority" select="1"/>
85 </xsl:apply-templates>
86 <xsl:if test="number($install_it)">
87 <xsl:value-of select="$priority"/>
88 <xsl:text> </xsl:text>
89 <xsl:value-of select="$depname"/>
90 <xsl:text>&#xA;</xsl:text>
91 </xsl:if>
92 </xsl:template>
93
94<!-- lexicographic Comparison of strings. There is no way to directly
95 compare strings in XPath. So find the position of the character
96 in the following string. On the other hand, for numeric form style
97 xx.yy.zz, we have to compare xx and x'x', which is not always
98 lexicographic: think of 2.2 vs 2.10 -->
99
100 <xsl:variable name="char-table" select="' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
101 <xsl:variable name= "dot-table" select="'.....................................................'"/>
102
103 <xsl:template name="compare-versions">
104<!-- returns non-zero if version is greater than inst-version -->
105 <xsl:param name="version"/>
106 <xsl:param name="inst-version"/>
107<!-- first make all separators (-_) into dots -->
108 <xsl:variable name="mod-ver" select="translate($version,'-_','..')"/>
109 <xsl:variable name="mod-inst-ver" select="translate($inst-version,'-_','..')"/>
110<!-- Then let us find the position of the first chars in char-table (0 if numeric or dot) -->
111 <xsl:variable name="pos-ver" select="string-length(substring-before($char-table,substring($version,1,1)))"/>
112 <xsl:variable name="pos-inst-ver" select="string-length(substring-before($char-table,substring($inst-version,1,1)))"/>
113 <xsl:choose>
114 <xsl:when test="string-length($inst-version)=0">
115 <xsl:value-of select="string-length($version)"/>
116 </xsl:when>
117 <xsl:when test="string-length($version)=0">
118 0
119 </xsl:when>
120 <xsl:when test="$pos-ver != 0">
121 <xsl:choose>
122 <xsl:when test="$pos-ver = $pos-inst-ver">
123 <xsl:call-template name="compare-versions">
124 <xsl:with-param name="version" select="substring($version,2)"/>
125 <xsl:with-param name="inst-version" select="substring($inst-version,2)"/>
126 </xsl:call-template>
127 </xsl:when>
128 <xsl:otherwise>
129 <xsl:copy-of select="number($pos-ver &gt; $pos-inst-ver)"/>
130 </xsl:otherwise>
131 </xsl:choose>
132 </xsl:when>
133 <xsl:when test="substring($mod-ver,1,1)='.'">
134 <xsl:choose>
135 <xsl:when test="substring($mod-inst-ver,1,1)='.'">
136 <xsl:call-template name="compare-versions">
137 <xsl:with-param name="version" select="substring($version,2)"/>
138 <xsl:with-param name="inst-version" select="substring($inst-version,2)"/>
139 </xsl:call-template>
140 </xsl:when>
141 <xsl:otherwise>
142 0
143 </xsl:otherwise>
144 </xsl:choose>
145 </xsl:when>
146 <xsl:otherwise>
147 <xsl:choose>
148 <xsl:when test="$pos-inst-ver &gt; 0 or substring($mod-inst-ver,1,1)='.'">
149<!-- do not know what to do: do not install -->
150 0
151 </xsl:when>
152 <xsl:otherwise>
153 <xsl:variable name="tok" select="substring-before(concat(translate($mod-ver,$char-table,$dot-table),'.'),'.')"/>
154 <xsl:variable name="inst-tok" select="substring-before(concat(translate($mod-inst-ver,$char-table,$dot-table),'.'),'.')"/>
155 <xsl:choose>
156 <xsl:when test="number($tok)=number($inst-tok)">
157 <xsl:call-template name="compare-versions">
158 <xsl:with-param name="version" select="substring($version,string-length($tok)+1)"/>
159 <xsl:with-param name="inst-version" select="substring($inst-version,string-length($inst-tok)+1)"/>
160 </xsl:call-template>
161 </xsl:when>
162 <xsl:otherwise>
163 <xsl:copy-of select="number(number($tok) &gt; number($inst-tok))"/>
164 </xsl:otherwise>
165 </xsl:choose>
166 </xsl:otherwise>
167 </xsl:choose>
168 </xsl:otherwise>
169 </xsl:choose>
170 </xsl:template>
171
172</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.