source: tools/jenkins/setup.sh.in@ f77f648d

ast-experimental
Last change on this file since f77f648d was ac1aba4b, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Tentative change to fix jenkins setup script when RUNPATH is not found and ldd does find libcfa

  • Property mode set to 100644
File size: 5.1 KB
Line 
1# check if stdout is a terminal...
2if test -t 1; then
3
4 # see if it supports colors...
5 ncolors=$(tput colors)
6
7 if test -n "$ncolors" && test $ncolors -ge 8; then
8 bold="$(tput bold)"
9 underline="$(tput smul)"
10 standout="$(tput smso)"
11 normal="$(tput sgr0)"
12 black="$(tput setaf 0)"
13 red="$(tput setaf 1)"
14 green="$(tput setaf 2)"
15 yellow="$(tput setaf 3)"
16 blue="$(tput setaf 4)"
17 magenta="$(tput setaf 5)"
18 cyan="$(tput setaf 6)"
19 white="$(tput setaf 7)"
20 fi
21fi
22
23function error
24{
25 >&2 echo "${red}$1${normal}"
26}
27
28# helper function to get the runpath (-Wl,-rpath in gcc)
29function getrunpath()
30{
31 local elfout=$(readelf -d $1 | grep -E "RPATH|RUNPATH")
32 regex='\[/([[:alpha:][:digit:]@/_.-]+)\]'
33 if [[ $elfout =~ $regex ]]; then
34 local myRPath=${BASH_REMATCH[1]}
35 else
36 error "Could not find RUNPATH for test $2"
37 fi
38 echo "$myRPath"
39}
40
41# helper function to list the dependencies of each executable
42function getdeps()
43{
44 local deps=$(ldd $1)
45 retlcldeps=()
46 retsysdeps=()
47 while IFS= read -r line; do
48 regex1='(libcfa[[:alpha:][:digit:].]+)'
49 regex2='/([[:alpha:][:digit:]@/_.-]+)'
50 regex3='linux-vdso.so.1|linux-gate.so.1'
51 if [[ $line =~ $regex1 ]]; then
52 retlcldeps+=(${BASH_REMATCH[1]})
53 elif [[ $line =~ $regex2 ]]; then
54 retsysdeps+=(${BASH_REMATCH[1]})
55 elif [[ $line =~ $regex3 ]]; then
56 # echo "ignoring '$line}': intrinsic"
57 :
58 else
59 error "Could not find dependency '$line' for test $2"
60 fi
61 done <<< "$deps"
62}
63
64# make a symlink, with better errors
65function makelink()
66{
67 local source=$1
68 local target=$2
69 if [ ! -f $source ]; then
70 error "Source of link $source does not exist"
71 fi
72
73 if [ ! -e $target ] && [ ! -L $target ]; then
74 ln -s $source $target
75 return
76 fi
77
78 if [ ! -L $target ]; then
79 error "Cannot create link $target for $source, existing regular file"
80 else
81 want=$(readlink -f $source)
82 have=$(readlink -f $target)
83 if [ $want == $have ]; then
84 return
85 fi
86 error "Target link $(basename $target) for $source already exists and has incorrect target $have"
87 fi
88}
89
90# ========================================
91# make sure this computer is acceptable
92myarch=$(uname -m)
93if [ ! -z $arch ] && [ "$myarch" != "$arch" ]; then
94 error "Wrong architecture, is : $myarch, need: $arch"
95 exit 1
96fi
97
98myname=$(uname -n)
99if [ ! -z $name ] && [ "$myname" != "$name" ]; then
100 >&2 echo "${yellow}Unexpected machine name, is: $myname, expected: $name${normal}"
101fi
102
103# ========================================
104# make sure we use the right paths
105srcdir=$(readlink -f $(dirname "$0"))
106outdir=$(readlink -f $(pwd))
107
108rnpaths=()
109sysdeps=()
110lcldeps=()
111
112# find all the tests
113programs=($(find $srcdir/tests/crashes -name exe))
114if [ ${#programs[@]} -eq 0 ]; then
115 error "ERROR no executables found in archive"
116 exit 1
117fi
118
119# ========================================
120# for each tests
121echo "generating command files ..."
122for pgm in "${programs[@]}"
123do
124 # find the test's name
125 regex='tests/crashes/(short|full-debug|full-nodebug)/([[:alpha:][:digit:]@/_.-]+)/exe'
126 if [[ $pgm =~ $regex ]]; then
127 name=${BASH_REMATCH[2]}
128 else
129 error "Executable '$pgm' has ill-formed path"
130 fi
131
132 # get a path to the executable
133 exe=$(readlink -f "$pgm")
134
135 # check the executable exist
136 if [ ! -x $exe ]; then
137 error "Executable for '$name' does not have execute permission"
138 continue
139 fi
140
141 ldd $exe > /dev/null 2>&1
142 if [ $? -ne 0 ]; then
143 error "Executable for '$name' is not valid for this architecture"
144 continue
145 fi
146
147 # get the corresponding core file
148 core="$(dirname "$exe")/core"
149 if [ ! -f "$core" ]; then
150 error "No core found for test '$name'"
151 fi
152
153 # create the command file
154 file="${name//\//.}.com"
155 echo "$file"
156 echo "set solib-absolute-prefix $outdir" > $file
157 echo "file $exe" >> $file
158 echo "core-file $core" >> $file
159
160 # find the system dependencies
161 getdeps $exe $name
162 sysdeps+=("${retsysdeps[@]}")
163 lcldeps+=("${retlcldeps[@]}")
164
165 # find it's expected runpath
166 rnpaths+=("$(getrunpath $exe $name)")
167done <<< "$programs"
168
169echo "done"
170
171# ========================================
172# eliminate duplicates from the list of dependencies
173
174# get unique elements of array
175function getuniques()
176{
177 echo "$*" | tr ' ' '\n' | sort -u | tr '\n' ' '
178}
179
180rnpaths=($(getuniques ${rnpaths[@]}))
181sysdeps=($(getuniques ${sysdeps[@]}))
182lcldeps=($(getuniques ${lcldeps[@]}))
183
184# ========================================
185# create symlinks to cforall dependencies
186echo "setting up local dependencies ..."
187
188for rpath in "${rnpaths[@]}"
189do
190 # find the debug level
191 if [[ $rpath =~ 'nodebug' ]]; then
192 level="-nodebug"
193 elif [[ $rpath =~ 'debug' ]]; then
194 level="-debug"
195 else
196 error "Executable(s) with ill-formed rpath"
197 fi
198
199 # create the right directory
200 mkdir -p "$outdir/$rpath"
201
202 # for each dependencies create them
203 # this might create unnecessary pairs, but I don't care
204 for lib in "${lcldeps[@]}"
205 do
206 echo "$lib$level"
207 source=$(find "$srcdir" -name "$lib*" -a -path "*$level*")
208 target="$outdir/$rpath/$lib"
209 makelink $source $target
210 done
211done
212
213echo "done"
214
215# ========================================
216# create symlinks to system dependencies
217echo "setting up system dependencies ..."
218
219for dep in "${sysdeps[@]}"
220do
221 echo $dep
222 mkdir -p "$outdir/$(dirname $dep)"
223 makelink "/$dep" "$outdir/$dep"
224done
225
226echo "done"
Note: See TracBrowser for help on using the repository browser.