Changeset e4b1293
- Timestamp:
- 11/03/2015 05:17:15 PM (9 years ago)
- Branches:
- 2.4, ablfs-more, legacy, new_features, trunk
- Children:
- 7f9fa78
- Parents:
- 2ce3688
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BLFS/libs/func_dependencies
r2ce3688 re4b1293 4 4 # 5 5 6 #---------------------------------------------------------------------------# 7 # This is a set of (recursive) functions for manipulating a dependency # 8 # tree. Everything would be "simple" without circular dependencies. We # 9 # would just have to build the tree using the packages.xml file, and to # 10 # a function for browsing it. But we need to be able to detect circular # 11 # dependencies and to possibly change the tree depending on the user # 12 # decision. This is why we keep with each node a record of the path from # 13 # the root to the node, which we call *link*. # 14 # Layout of the tree: # 15 # Each node is a file <nodeName>.dep, which contains the names of the # 16 # child nodes, one per line, except the first line is the *link*: # 17 # the link is a series of numbers (n1 n2 ... nN), describing the path from # 18 # the root to <nodeName>: n1 is the position of the first node of the path # 19 # in root.dep, n2 is the position of the second node of the path in # 20 # <node1>.dep and so on. The link is not needed for normal tree operations # 21 # (building a subtree or browsing the tree), but it allows to # 22 # check whether a dependency is circular, and to find its parent. # 23 #---------------------------------------------------------------------------# 24 25 # Global variables: 6 26 # A string of spaces for indenting: 7 27 declare -a spaceSTR=" " … … 13 33 # no problem: we just prune the tree at dependency_n. 14 34 # If we want to build first dependency_0, we need to 15 # put dependency_n as a dependency of parent. The triplet 35 # put dependency_n as a dependency of parent and build 36 # the subtree from there. In this case, the triplet 16 37 # above shall contain (parent dependency_0 dependency_n) 17 38 … … 23 44 (recursive function) 24 45 input vars: $1 : file with a list of targets 25 the first line of the file is an array 26 of links 46 the first line of the file is the link 27 47 externals: vars: BLFS_XML 28 48 DEP_LEVEL 29 modifies: vars: none 30 returns: nothing 31 output: files: for each pkg with dependencies in $1, 32 a file pkg.dep and its dependencies 49 modifies: vars: exchange_triplet cointains the triplet when return is 1 50 returns: 0 if the tree has been successfully created 51 1 if we are backing up to the parent of a circular dep 52 output: files: for each <pkg> with dependencies in $1, 53 a file <pkg>.dep and its dependencies 33 54 on error: nothing 34 55 on success: nothing … … 47 68 48 69 { 49 # BEWARE : the order of options matters : read -a -u6 rootlink hangs forever50 # (actually, the doc says -a array -u fd)51 70 # We use fd number 6 for input from DepFile, because we need 0 for user input 52 71 read -u6 -a rootlink 53 72 depth=${#rootlink[*]} 54 73 dep_level=$DEP_LEVEL 74 # For now, process only optional deps for the root packages. 55 75 if (( $DEP_LEVEL > 2 )) && (( $depth > 1 )); then dep_level=2; fi 56 76 srootlink="${rootlink[*]} " … … 71 91 # Do not use "${rootlink[*]}" =~ "${otherlink[*]}": case rootlink=(1 11) 72 92 # and otherlink=(1 1) 73 if [[ ${srootlink#"${otherlink[*]} "} != ${srootlink} ]]; then # cir culardep93 if [[ ${srootlink#"${otherlink[*]} "} != ${srootlink} ]]; then # cir. dep 74 94 # First look for the other parent of this dependency. 75 95 # The parent has the same link without the last entry. … … 85 105 echo -en "\nCirc: $depth${spaceSTR:0:$depth}${BOLD}${id_of_dep}${OFF} is a dependency \ 86 106 of ${BOLD}${DepFile%.dep}${OFF}" 87 # If idofdep is the parent of DepFile, we can exchange them if required88 # if grep -q ${DepFile%.dep} ${id_of_dep}.dep; then89 107 # we propose exchange always 90 91 92 108 echo -en "\nCirc: $depth${spaceSTR:0:$depth}Do you want to build ${id_of_dep} first? yes/no (no):" 109 read ANSWER 110 if [ x$ANSWER = "xyes" ] ; then # exchange: 93 111 # set triplet and return 1 94 exchange_triplet=($parent $id_of_dep ${DepFile%.dep}) 95 return 1 96 else # no exchange: prune 97 lines_to_remove="$lines_to_remove $id_of_dep" 98 fi 99 # else 100 # lines_to_remove="$lines_to_remove $id_of_dep" 101 # fi 112 exchange_triplet=($parent $id_of_dep ${DepFile%.dep}) 113 return 1 114 else # no exchange: prune 115 lines_to_remove="$lines_to_remove $id_of_dep" 116 fi 102 117 else # not circular: prune 103 118 lines_to_remove="$lines_to_remove $id_of_dep" 104 fi 105 continue 106 fi 119 fi # circular or not 120 continue # this dependency has already been seen, and the associated 121 # subtree computed. We are done 122 fi # Has this entry already been seen? 123 # So, this entry has not already been seen. Let's build the corresponding 124 # subtree. Since decisions about circular deps can lead us to start again 125 # dependencies, we restart until the flag is false. 107 126 flag=true 108 127 while [ $flag = true ]; do … … 113 132 ../xsl/dependencies.xsl ../packages.xml 114 133 115 if [[ -f ${id_of_dep}.dep ]]; then 116 sed -i "1i${rootlink[*]} $count" ${id_of_dep}.dep 134 if [[ -f ${id_of_dep}.dep ]]; then # this dependency has dependencies 135 sed -i "1i${rootlink[*]} $count" ${id_of_dep}.dep # add the link 117 136 generate_dependency_tree ${id_of_dep}.dep 118 137 # Test return value, in case we exchange dependencies … … 121 140 ;; 122 141 1) # We are backing up to parent 123 if [[ ${exchange_triplet} == ${DepFile%.dep} ]] 142 if [[ ${exchange_triplet} == ${DepFile%.dep} ]] # we are the parent 124 143 then tree_erase ${id_of_dep}.dep 144 # We want that our direct dep be ${exchange_triplet[2]} and that id_of_dep 145 # be pulled in as an indirect dep, so exchange. 125 146 # Just doing a sed -i "s@${id_of_dep}@${exchange_triplet[2]}@" $DepFile 126 147 # is not good if $DepFile contains several times the same line … … 129 150 sed -i "${lineno}s@${id_of_dep}@${exchange_triplet[2]}@" $DepFile 130 151 id_of_dep=${exchange_triplet[2]} 131 flag=true 132 else 152 flag=true # we have to regenerate the tree for the new dependency 153 else # we are not the parent. let's just back up one step 133 154 # echo backing up to ${exchange_triplet} at ${DepFile%.dep} 134 155 return 1 … … 136 157 ;; 137 158 esac 138 else 159 else # id_of_dep has no dependencies, just record the link in a file 160 # and print 139 161 echo "${rootlink[*]} $count" > ${id_of_dep}.dep 162 echo -en "\nLeaf: $(($depth+1))${spaceSTR:0:$(($depth+1))}${CYAN}${id_of_dep}${OFF}" 140 163 fi 141 164 done … … 146 169 # the same line. Normally, all those lines but one 147 170 # would be flagged to be removed (or all of them if 148 # the dependency appeared before). asimple sed /$line/d171 # the dependency appeared before). A simple sed /$line/d 149 172 # destroys all the lines. We should instead remove 150 173 # only one for each appearance of it in lines_to_remove. 151 # so first get the number of first line and then delete174 # so first get the position of last line and then delete 152 175 # that line 153 176 for line in $lines_to_remove
Note:
See TracChangeset
for help on using the changeset viewer.