Changeset e4b1293 for BLFS


Ignore:
Timestamp:
11/03/2015 05:17:15 PM (9 years ago)
Author:
Pierre Labastie <pierre@…>
Branches:
2.4, ablfs-more, legacy, new_features, trunk
Children:
7f9fa78
Parents:
2ce3688
Message:

Improve (?) comments in func_dependencies

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BLFS/libs/func_dependencies

    r2ce3688 re4b1293  
    44#
    55
     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:
    626# A string of spaces for indenting:
    727declare -a spaceSTR="                                                                   "
     
    1333# no problem: we just prune the tree at dependency_n.
    1434# 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
    1637# above shall contain (parent dependency_0 dependency_n)
    1738
     
    2344                (recursive function)
    2445    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
    2747    externals:  vars: BLFS_XML
    2848                      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
    3354    on error:   nothing
    3455    on success: nothing
     
    4768
    4869{
    49 # BEWARE : the order of options matters : read -a -u6 rootlink hangs forever
    50 # (actually, the doc says -a array -u fd)
    5170# We use fd number 6 for input from DepFile, because we need 0 for user input
    5271read -u6 -a rootlink
    5372depth=${#rootlink[*]}
    5473dep_level=$DEP_LEVEL
     74# For now, process only optional deps for the root packages.
    5575if (( $DEP_LEVEL > 2 )) && (( $depth > 1 )); then dep_level=2; fi
    5676srootlink="${rootlink[*]} "
     
    7191# Do not use "${rootlink[*]}" =~ "${otherlink[*]}": case rootlink=(1 11)
    7292# and otherlink=(1 1)
    73     if [[ ${srootlink#"${otherlink[*]} "} != ${srootlink} ]]; then # circular dep
     93    if [[ ${srootlink#"${otherlink[*]} "} != ${srootlink} ]]; then # cir. dep
    7494# First look for the other parent of this dependency.
    7595# The parent has the same link without the last entry.
     
    85105      echo -en "\nCirc: $depth${spaceSTR:0:$depth}${BOLD}${id_of_dep}${OFF} is a dependency \
    86106of ${BOLD}${DepFile%.dep}${OFF}"
    87 # If idofdep is the parent of DepFile, we can exchange them if required
    88 #      if grep -q ${DepFile%.dep} ${id_of_dep}.dep; then
    89107# we propose exchange always
    90         echo -en "\nCirc: $depth${spaceSTR:0:$depth}Do you want to build ${id_of_dep} first? yes/no (no):"
    91         read ANSWER
    92         if [ x$ANSWER = "xyes" ] ; then  # exchange:
     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:
    93111# 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
    102117    else # not circular: prune
    103118      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.
    107126  flag=true
    108127  while [ $flag = true ]; do
     
    113132        ../xsl/dependencies.xsl ../packages.xml
    114133
    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
    117136      generate_dependency_tree ${id_of_dep}.dep
    118137# Test return value, in case we exchange dependencies
     
    121140         ;;
    122141       1) # We are backing up to parent
    123          if [[ ${exchange_triplet} == ${DepFile%.dep} ]]
     142         if [[ ${exchange_triplet} == ${DepFile%.dep} ]] # we are the parent
    124143           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.
    125146# Just doing a sed -i "s@${id_of_dep}@${exchange_triplet[2]}@" $DepFile
    126147# is not good if $DepFile contains several times the same line
     
    129150           sed -i "${lineno}s@${id_of_dep}@${exchange_triplet[2]}@" $DepFile
    130151           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
    133154# echo backing up to ${exchange_triplet} at ${DepFile%.dep}
    134155           return 1
     
    136157         ;;
    137158      esac
    138     else
     159    else # id_of_dep has no dependencies, just record the link in a file
     160         # and print
    139161      echo "${rootlink[*]} $count" > ${id_of_dep}.dep
     162      echo -en "\nLeaf: $(($depth+1))${spaceSTR:0:$(($depth+1))}${CYAN}${id_of_dep}${OFF}"
    140163    fi
    141164  done
     
    146169# the same line. Normally, all those lines but one
    147170# would be flagged to be removed (or all of them if
    148 # the dependency appeared before). a simple sed /$line/d
     171# the dependency appeared before). A simple sed /$line/d
    149172# destroys all the lines. We should instead remove
    150173# only one for each appearance of it in lines_to_remove.
    151 # so first get the number of first line and then delete
     174# so first get the position of last line and then delete
    152175# that line
    153176for line in $lines_to_remove
Note: See TracChangeset for help on using the changeset viewer.