-
Notifications
You must be signed in to change notification settings - Fork 5
/
functions.sh
executable file
·199 lines (173 loc) · 5.06 KB
/
functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
UNAME=$(tr [A-Z] [a-z] <<< "$(uname)")
export SCRIPTS_DIR="$( cd "$( echo "${BASH_SOURCE[0]%/*}/" )"; pwd )"
function get_default_compiler()
{
# Detect the platform (similar to $OSTYPE)
OS="`uname`"
case $OS in
'Linux')
echo "gcc"
;;
'FreeBSD')
echo "gcc"
;;
'WindowsNT')
echo "msvcpp"
;;
'Darwin')
echo "apple_clang"
;;
'SunOS')
echo "gcc"
;;
'AIX')
echo "xlc"
;;
*)
echo "UNKNOWN"
;;
esac
}
############################################################################
# Get the build spec
#
# Syntax: get_extra_build_spec <compiler> <compute_engine> <optimization spec>
# e.g. get_extra_build_spec "gcc" "cpu" "all"
############################################################################
function get_extra_build_spec()
{
local compiler=$1
local compute_engine=$2
local optim_spec=$3
local build_spec="${compiler}-${compute_engine}-${optim_spec}"
echo $build_spec
}
############################################################################
# Remove duplicates and things that don't exist
#
# Syntax: cleanup_path PATHNAME
############################################################################
cleanup_path()
{
pathName=$1
eval pathContents=\"\$$pathName\"
newPath=$(echo -n $pathContents | awk -v RS=: '!($0 in a) {a[$0]; printf("%s%s", length(a) > 1 ? ":" : "", $0)}')
eval "$pathName=$newPath"
}
############################################################################
# Exports Conan recipes from a given directory
#
# Syntax: conan_export <Conan channel> <Base Directory> <List of packages>
############################################################################
function do_conan_export()
{
conan_channel=$1
base_dir=$2
libs_to_build=$3
ret=""
myName=$(basename $0)
for i in ${libs_to_build}
do
dir="${base_dir}/${i}"
if [[ ! -d "${dir}" ]]
then
dir="${base_dir}/conan-${i}"
fi
if [[ -d ${dir} ]]
then
dirBase="$(basename -- ${dir})"
echo "Exporting recipe for package $dirBase"
conan export ${dir} ${conan_channel}
fi
done
return 0
}
######################################################################################
# Wraps the git binary in a shell script that ensures that it uses the shared libraries
# it was built with Wraps the git binary in a shell script that ensures that it uses the shared libraries
# it was built with.
######################################################################################
function git()
{
unset git &> /dev/null
unalias git &> /dev/null
unset -f git &> /dev/null
gitRealPath=$(command -v git.exe)
declare -A git_libs
for i in `ldd ${gitRealPath} | grep so | sed -e '/^[^\t]/ d' | sed -e 's/\t//' | sed -e 's/.*=..//' | sed -e 's/ (0.*)//' | sort | uniq`
do
lib_dir=$(dirname $i)
echo $lib_dir
if [[ $lib_dir == /* ]]
then
git_libs["$lib_dir"]="$lib_dir"
fi
done
lib_path=""
for x in "${!git_libs[@]}"
do
printf "[%s]=%s\n" "$x" "${git_libs[$x]}"
if [[ ${lib_path} == "" ]]
then
lib_path=$x
else
lib_path="$lib_path:$x"
fi
done
cmd="LD_LIBRARY_PATH=${lib_path};DYLD_LIBRARY_PATH=${lib_path} ${gitRealPath} $@"
echo "Running git with adjusted LIBRARY paths variables as $cmd"
eval ${cmd}
}
######################################################################################
# Installs a given set of Conan recipes
#
# Syntax: do_conan_install <conanfile> <Conan channel> <build type> <compiler> <compute engine> \
# <optimization spec> <Conan profile> <Conan install folder>
######################################################################################
function do_conan_install()
{
conanfile_txt=$1
conan_channel=$2
build_type=$3
compiler=$4
compute_engine=$5
optim_spec=$6
profile_file=$7
install_folder=$8
if ! [[ "$optim_spec" =~ ^(all|safe|none)$ ]]
then
echo "Error: unknown optimisation level '$optim_spec'"
return 1
fi
if ! [[ "$compute_engine" =~ ^(cpu|cuda_10)$ ]]
then
echo "Error: unknown compute engine type '$compute_engine'"
return 1
fi
if [ "x$compiler" = "x" ]
then
echo "Error: no compiler specified"
return 1
fi
echo "Using profile '$profile_file' for building"
if [ ! -f "$profile_file" ]
then
echo "Error: profile file $profile_file does not exist"
return 1
fi
if [ ! -f "$conanfile_txt" ]
then
echo "Error: conanfile $conanfile_txt does not exist"
return 1
fi
extra_build_spec=$(get_extra_build_spec $compiler $compute_engine $optim_spec)
install_folder=${CONAN_USER_HOME}/CMakeModules/${extra_build_spec}
conan_build_options="--settings build_type=${build_type}"
conan_profile_options="--profile=${profile_file}"
conan_install_options="--install-folder=${install_folder}"
echo "Installing all conan components using confile ${conanfile_txt}"
conan install ${conan_profile_options} ${conan_install_options} ${conan_build_options} ${conan_build_cpp_options} --build outdated ${conanfile_txt}
ret=$?
echo "Conan install returned ${ret}"
return ${ret}
}