dependency_graph.sh
Go to the documentation of this file.
1 #!/bin/sh
2 
3 # usage: dependency_graph.sh <product> <version> <quals>
4 # will make <product>_<version>_<quals>_graph.pdf dependency tree using graphviz
5 # it sets up the dune environment and then the product and qualifier
6 # requires dot for taking the graphviz file and making a PDF graph
7 
8 function printdep {
9  if [ x`echo $curprod | grep geant4` = x ]; then
10  if [ x`echo $curprod | grep mrb` = x ]; then
11  if [ x`echo $prod | grep cetpkgsupport` = x ]; then
12  if [ x`echo $prod | grep xerces_c` = x ]; then
13  if [ x`echo $prod | grep gcc` = x ]; then
14  echo "$curprod -> $prod"
15  printprodver
16  fi
17  fi
18  fi
19  fi
20  fi
21 }
22 
23 function printprodver {
24  echo $prod [label=\"$prod\\n$prodver\"]
25  echo $curprod [label=\"$curprod\\n$curprodver\"]
26 }
27 
28 function makegraph {
29 
30 # make a temporary file containing all the ups active's of all setup products
31 
32  tempfile=`mktemp /tmp/deptreegraphviz.tmp.XXXXXX`
33  touch $tempfile
34  rm $tempfile
35  ups active | grep -v "Active ups products:" | while read iline
36  do
37  ilct=${iline/-z * /}
38  ilc=${ilct/-z */}
39  ups depend $ilc >> $tempfile
40  done
41 
42 
43 # need to read in without collapsing spaces. IFS does this but ups depend gags on that,
44 # so run ups depend and catch the output in a separate file
45 
46  IFSSAVE=$IFS
47  IFS=$'\n'
48  cat $tempfile | while read -r iline2
49  do
50  matchstr="|__"
51  if [ x`echo $iline2 | grep $matchstr` = x ]; then
52 
53 # top-level product
54 
55  prod=`echo $iline2 | cut -d ' ' -f1`
56  prodver=`echo $iline2 | cut -d ' ' -f2`
57  curprod=$prod
58  curprodver=$prodver
59  lastprod=$prod
60  lastprodver=$prodver
61  curlev=0
62  plist[$curlev]=$curprod
63  plistver[$curlev]=$curprodver
64  else
65 
66 # found a |__ -- downlevel product
67 
68  dv1=`echo $iline2 | grep -b -o $matchstr | awk 'BEGIN {FS=":"}{print $1}'`
69  dv2=$(($dv1/3))
70  depth=$(($dv2+1))
71 
72  jprod1=${iline2/*|__/}
73  prod=`echo $jprod1 | cut -d ' ' -f1`
74  prodver=`echo $jprod1 | cut -d ' ' -f2`
75  clp1=$((curlev+1))
76  if [ $depth = $clp1 ]; then
77  printdep
78  elif [ $depth -gt $clp1 ]; then
79  curprod=$lastprod
80  curprodver=$lastprodver
81  curlev=$clp1
82  plist[$curlev]=$curprod
83  plistver[$curlev]=$curprodver
84  printdep
85  else
86  curlev=$(($depth-1))
87  curprod=${plist[$curlev]}
88  curprodver=${plistver[$curlev]}
89  printdep
90  fi
91  lastprod=$prod
92  lastprodver=$prodver
93  fi
94  done # loop over lines in tempfile
95  IFS=$IFSSAVE
96  rm $tempfile
97 }
98 
99 # begin main program
100 
101 if [ "$1" == "--help" ]; then
102  echo "Usage: dependency_graph.sh <product> <version> <qualifiers> to make a file <product>_<version>.pdf showing"
103  echo "the dependency tree. This version suppresses GEANT4's dependencies as well as mrb and cetpkgsupport"
104  exit
105 fi
106 
107 export LANG=en_US
108 source /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh
109 setup $1 $2 -q $3
110 
111 TF=`mktemp /tmp/dtgv.tmp.XXXXXX`
112 touch $TF
113 rm $TF
114 
115 echo digraph G { > $TF
116 makegraph | sort | uniq >> $TF
117 echo } >> $TF
118 
119 dot -Tpdf -o $1_$2_$3_graph.pdf $TF
120 rm $TF
121