Skip to content

Commit fc5b671

Browse files
authored
Merge pull request #550 from analogdevicesinc/python-setup-fixes
Python setup fixes
2 parents 21ed20f + e7a7656 commit fc5b671

File tree

8 files changed

+341
-90
lines changed

8 files changed

+341
-90
lines changed

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,18 @@ matrix:
9595
- TRIGGER_NEXT_BUILD=true
9696

9797
addons:
98-
artifacts: true
9998
ssh_known_hosts:
10099
secure: "q0dQ9MrhnOCo031McxSdQIqw4N6tEyAZLq7mdbWkAJcXOh/CX58NjFvcdSfamleDUYRmg7KpCZPPgnbx2JtqVvWJv8aNnr67CE1GIjRP1Fxh2WaKS+VK+I6rro7GwCO2C9d+uffCt63LfZKqddF1T7vMI2IgHcu9irc5LCuw6Wo="
101100

102101
before_install:
103-
- if [[ "$ARCH" == "arm" ]] ; then ./CI/travis/setup_qemu_for_arm.sh ${OS_VERSION} ; fi
102+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
103+
if [[ "$ARCH" == "arm" ]] ; then
104+
./CI/travis/setup_qemu_for_arm.sh ${OS_VERSION} ;
105+
else
106+
./CI/travis/before_install_linux "$OS_TYPE" ;
107+
fi
108+
fi
104109
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./CI/travis/before_install_darwin ; fi
105-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./CI/travis/before_install_linux "$OS_TYPE" ; fi
106110
- if [[ -n "$COVERITY_SCAN_PROJECT_NAME" ]] ; then echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca- ; fi
107111
- if [ -n "$COVERITY_SCAN_PROJECT_NAME" -a "$TRAVIS_EVENT_TYPE" == "cron" ] ; then curl -s 'https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh' | bash || true ; fi
108112

CI/travis/before_install_linux

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,36 @@
33
. CI/travis/lib.sh
44

55
install_sphinx() {
6-
if ! command_exists pip3 ; then
7-
pip install sphinx
8-
pip install sphinx-rtd-theme
9-
else
10-
pip3 install sphinx
11-
pip3 install sphinx-rtd-theme
6+
if command_exists python ; then
7+
python --version
8+
command -v python
9+
python -m pip install -U pip
10+
python -m pip install -U setuptools
11+
python -m pip install sphinx
12+
python -m pip install sphinx-rtd-theme
1213
fi
14+
}
1315

16+
install_pyenv() {
17+
if ! command_exists pyenv ; then
18+
echo installing pyenv
19+
git clone git://github.com/yyuu/pyenv.git $HOME/.pyenv
20+
export PATH="$HOME/.pyenv/bin:$PATH"
21+
export PYENV_ROOT="$HOME/.pyenv"
22+
fi
1423
}
1524

25+
install_python() {
26+
echo "### installing python"
27+
command -v pyenv
28+
add_python_path
29+
pyenv install --list | grep "^[[:space:]]*[0-9]"
30+
pyenv install 3.6.3
31+
pyenv global 3.6.3
32+
add_python_path
33+
}
34+
35+
1636
handle_centos() {
1737
# needed for man2html and a few other popular tools
1838
yum search epel-release
@@ -24,25 +44,40 @@ handle_centos() {
2444
yum -y install cmake libxml2-devel libusb1-devel libaio-devel \
2545
bzip2 gzip rpm rpm-build redhat-lsb-core
2646

27-
# CENTOS 6 doesn't include python 3, it's too old.
28-
if is_centos_at_least_ver "7" ; then
29-
yum -y install python3-pip
47+
# needed for building python with pyenv
48+
yum install -y gcc gcc-c++ make git patch openssl-devel zlib-devel readline-devel sqlite-devel bzip2-devel
49+
50+
# CentOS 6 & 7 don't work with doc, or the latest python.
51+
# install_pyenv
52+
# install_python
53+
54+
if [ "$(get_version | head -c 1)" = "7" ] ; then
55+
# install Cmake3, and make it the default
56+
yum -y install cmake3
57+
alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake 10 \
58+
--slave /usr/local/bin/ctest ctest /usr/bin/ctest \
59+
--slave /usr/local/bin/cpack cpack /usr/bin/cpack \
60+
--slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake \
61+
--family cmake
62+
alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake3 20 \
63+
--slave /usr/local/bin/ctest ctest /usr/bin/ctest3 \
64+
--slave /usr/local/bin/cpack cpack /usr/bin/cpack3 \
65+
--slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake3 \
66+
--family cmake
3067
fi
3168

3269
if is_centos_at_least_ver "8" ; then
3370
# On CentOS 8, avahi-devel & doxygen are in this repo; enable it
71+
yum -y install yum-utils
3472
yum config-manager --set-enabled PowerTools
73+
# On CentOS 6 & 7, have issues building or packaging doc
74+
yum -y install python3 doxygen man2html
75+
install_sphinx
3576
else
3677
# On CentOS 8, cdk-devel (Curses Development Kit) does not exist yet
3778
yum -y install ncurses-devel cdk-devel
3879
fi
3980

40-
# CENTOS 6 will has issues with sphinx
41-
if is_centos_at_least_ver "7" ; then
42-
yum -y install doxygen man2html
43-
install_sphinx
44-
fi
45-
4681
yum -y install avahi-devel
4782
}
4883

@@ -56,15 +91,25 @@ handle_ubuntu_docker() {
5691

5792
handle_default() {
5893
sudo apt-get -qq update
94+
sudo apt-get install -y apt-utils
5995
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y cmake graphviz \
6096
libaio-dev libavahi-client-dev \
6197
libavahi-common-dev libusb-1.0-0-dev libxml2-dev rpm tar \
62-
bzip2 gzip flex bison git lsb-release python3-pip libncurses5-dev libcdk5-dev
98+
bzip2 gzip flex bison git lsb-release libncurses5-dev libcdk5-dev
99+
100+
# Most of these should be here, but are needed for building python by pyenv
101+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential \
102+
libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev \
103+
wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev \
104+
libffi-dev liblzma-dev python-openssl git
63105

64-
if [ -n "${GH_DOC_TOKEN}" ] ; then
106+
if ! is_arm ; then
107+
install_pyenv
108+
install_python
65109
sudo apt-get install -y doxygen man2html
66110
install_sphinx
67111
fi
112+
68113
if [ `sudo apt-cache search libserialport-dev | wc -l` -gt 0 ] ; then
69114
sudo apt-get install -y libserialport-dev
70115
fi

CI/travis/deploy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_DEB} ${TARGET_DEB} .deb
77
upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_RPM} ${TARGET_RPM} .rpm
88
upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_TGZ} ${TARGET_TGZ} .tar.gz
99
upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_PKG} ${TARGET_PKG} .pkg
10-
10+
remove_old_pkgs libiio

CI/travis/lib.sh

Lines changed: 177 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,48 @@ echo_red() { printf "\033[1;31m$*\033[m\n"; }
2727
echo_green() { printf "\033[1;32m$*\033[m\n"; }
2828
echo_blue() { printf "\033[1;34m$*\033[m\n"; }
2929

30+
backtrace() {
31+
# shell backtraces only work on bash
32+
if [ ! -z "${BASH}" ] ; then
33+
local i=
34+
i=${#FUNCNAME[@]}
35+
((--i))
36+
37+
while (( i >= 0 ))
38+
do
39+
echo "${BASH_SOURCE[$i]}:${BASH_LINENO[$i]}.${FUNCNAME[$i]}()"
40+
i=$((i - 1))
41+
done
42+
fi
43+
}
44+
45+
add_python_path() {
46+
echo "adding Python to the path"
47+
if [ -d "$HOME/.pyenv/bin" -a "$(echo "$PATH" | grep .pyenv/bin | wc -c)" -eq "0" ] ; then
48+
echo "adding $HOME/.pyenv/bin to path"
49+
export PATH="$HOME/.pyenv/bin:$PATH"
50+
fi
51+
if [ -z "${PYENV_SHELL}" ] ; then
52+
echo init pyenv
53+
eval "$(pyenv init -)"
54+
fi
55+
if [ -d /opt/pyenv/versions/3.6.3/bin -a "$(echo "$PATH" | grep opt/pyenv/versions | wc -c)" -eq "0" ] ; then
56+
echo adding python on opt to PATH
57+
export PATH="/opt/pyenv/versions/3.6.3/bin:$PATH"
58+
fi
59+
if [ -d /root/.pyenv/versions/3.6.3/bin -a "$(echo "$PATH" | grep root/.pyenv/versions | wc -c)" -eq "0" ] ; then
60+
echo adding python on root/.pyenv to PATH
61+
export PATH="/root/.pyenv/versions/3.6.3/bin:$PATH"
62+
fi
63+
if ! command_exists python ; then
64+
echo No python on path
65+
echo "$PATH"
66+
else
67+
python --version
68+
command -v python
69+
fi
70+
}
71+
3072
get_script_path() {
3173
local script="$1"
3274

@@ -180,14 +222,30 @@ brew_install_if_not_exists() {
180222
}
181223

182224
sftp_cmd_pipe() {
183-
sftp "${EXTRA_SSH}" "${SSHUSER}@${SSHHOST}"
225+
sftp -o "StrictHostKeyChecking no" "${EXTRA_SSH}" "${SSHUSER}@${SSHHOST}"
226+
}
227+
228+
sftp_run_cmds() {
229+
local x=5
230+
while [ "${x}" -gt "0" ] ; do
231+
sftp -o "StrictHostKeyChecking no" "${EXTRA_SSH}" "${SSHUSER}@${SSHHOST}" 0< "$1" && break;
232+
echo_red "failed to ssh, trying again"
233+
x=$((x - 1))
234+
sleep 10
235+
done
236+
if [ "${x}" -eq "0" ] ; then
237+
echo_red "failed to upload files"
238+
return 1;
239+
fi
240+
return 0
184241
}
185242

186243
sftp_rm_artifact() {
187244
local artifact="$1"
188245
sftp_cmd_pipe <<-EOF
189246
cd ${DEPLOY_TO}
190247
rm ${artifact}
248+
bye
191249
EOF
192250
}
193251

@@ -196,16 +254,26 @@ sftp_upload() {
196254
local TO="$2"
197255
local LATE="$3"
198256

199-
sftp_cmd_pipe <<-EOF
200-
cd ${DEPLOY_TO}
257+
if [ -n "${LATE}" ] ; then
258+
sftp_cmd_pipe <<-EOF
259+
cd ${DEPLOY_TO}
201260
202-
put ${FROM} ${TO}
203-
ls -l ${TO}
261+
put ${FROM} ${TO}
262+
ls -l ${TO}
204263
205-
symlink ${TO} ${LATE}
206-
ls -l ${LATE}
207-
bye
208-
EOF
264+
symlink ${TO} ${LATE}
265+
ls -l ${LATE}
266+
bye
267+
EOF
268+
else
269+
sftp_cmd_pipe <<-EOF
270+
cd ${DEPLOY_TO}
271+
272+
put ${FROM} ${TO}
273+
ls -l ${TO}
274+
bye
275+
EOF
276+
fi
209277
}
210278

211279
upload_file_to_swdownloads() {
@@ -245,26 +313,106 @@ upload_file_to_swdownloads() {
245313
echo and "${branch}_${LIBNAME}${LDIST}${EXT}"
246314
ssh -V
247315

248-
for rmf in ${TO} ${LATE} ; do
249-
sftp_rm_artifact "${rmf}" || \
250-
echo_blue "Could not delete ${rmf}"
251-
done
316+
local tmpfl=$(mktemp)
317+
echo "cd ${DEPLOY_TO}" > "${tmpfl}"
318+
echo "rm ${TO}" >> "${tmpfl}"
319+
echo "rm ${LATE}" >> "${tmpfl}"
320+
echo "put ${FROM} ${TO}" >> "${tmpfl}"
321+
echo "symlink ${TO} ${LATE}" >> "${tmpfl}"
322+
echo "ls -l ${TO}" >> "${tmpfl}"
323+
echo "ls -l ${LATE}" >> "${tmpfl}"
324+
echo "bye" >> "${tmpfl}"
252325

253-
sftp_upload "${FROM}" "${TO}" "${LATE}" || {
254-
echo_red "Failed to upload artifact from '${FROM}', to '${TO}', symlink '${LATE}'"
255-
return 1
256-
}
326+
sftp_run_cmds "${tmpfl}"
327+
rm "${tmpfl}"
328+
329+
return 0
330+
}
257331

332+
remove_old_pkgs() {
258333
# limit things to a few files, so things don't grow forever
259-
if [ "${EXT}" = ".deb" ] ; then
260-
for files in $(ssh "${EXTRA_SSH}" "${SSHUSER}@${SSHHOST}" \
334+
# we only do this on one build so simultaneous builds don't clobber each other
335+
if [ -z "${GH_DOC_TOKEN}" ] ; then
336+
return 0
337+
fi
338+
339+
if [ -z "${TRAVIS_BUILD_DIR}" ] ; then
340+
echo "TRAVIS_BUILD_DIR not set"
341+
return 0
342+
fi
343+
344+
if [ ! -d "${TRAVIS_BUILD_DIR}/.git" ] ; then
345+
echo "No ${TRAVIS_BUILD_DIR}/.git to operate git on"
346+
return 0
347+
fi
348+
349+
local LIBNAME=$1
350+
local old=
351+
352+
echo "Remove old packages from ${LIBNAME}"
353+
354+
if [ -n "$TRAVIS_PULL_REQUEST_BRANCH" ] ; then
355+
local branch="$TRAVIS_PULL_REQUEST_BRANCH"
356+
else
357+
local branch="$TRAVIS_BRANCH"
358+
fi
359+
360+
local GLOB=${DEPLOY_TO}/${branch}_${LIBNAME}-*
361+
362+
# putting everything into a file, and connecting once decreases the chances
363+
# for ssh issues, connections happen once, not every single file
364+
local tmpfl=$(mktemp)
365+
echo "cd ${DEPLOY_TO}" > "${tmpfl}"
366+
for files in $(ssh -o "StrictHostKeyChecking no" "${EXTRA_SSH}" "${SSHUSER}@${SSHHOST}" \
261367
"ls -lt ${GLOB}" | tail -n +100 | awk '{print $NF}')
262-
do
263-
ssh "${EXTRA_SSH}" "${SSHUSER}@${SSHHOST}" \
264-
"rm ${DEPLOY_TO}/${files}" || \
265-
return 1
266-
done
368+
do
369+
echo "rm ${files}" >> "${tmpfl}"
370+
done
371+
echo "bye" >> "${tmpfl}"
372+
# if it is only cd & bye, skip it
373+
if [ "$(wc -l "${tmpfl}" | awk '{print $1}')" -gt "2" ] ; then
374+
sftp_run_cmds "${tmpfl}"
267375
fi
376+
rm "${tmpfl}"
377+
# provide an index so people can find files.
378+
ssh -o "StrictHostKeyChecking no" "${EXTRA_SSH}" "${SSHUSER}@${SSHHOST}" \
379+
"ls -lt ${DEPLOY_TO}" | grep "${LIBNAME}" > "${LIBNAME}_index.html"
380+
echo "ls captured"
381+
382+
echo "cd ${DEPLOY_TO}" > "${tmpfl}"
383+
# prune old / removed branches, leave things are are tags/branches
384+
for old in $(sed 's/-> .*$//' libiio_index.html | \
385+
awk '{print $NF}' | grep -v master | sort | \
386+
sed "s/_libiio-0.[0-9][0-9].g[a-z0-9]*-/ %% /" | \
387+
grep "%%" | awk '{print $1}' | sort -u)
388+
do
389+
if [ "$(git --git-dir "${TRAVIS_BUILD_DIR}/.git" ls-remote --heads origin "${old}" | wc -l)" -ne "0" ] ; then
390+
echo "${old} is a branch"
391+
else
392+
if [ "$(git --git-dir "${TRAVIS_BUILD_DIR}/.git" ls-remote --tags origin "${old}" | wc -l)" -ne "0" ] ; then
393+
echo "${old} is a tag"
394+
else
395+
echo "${old} can be removed"
396+
echo "rm ${old}_${LIBNAME}-*" >> "${tmpfl}"
397+
echo "rm ${old}_latest_${LIBNAME}-*" >> "${tmpfl}"
398+
echo "rm ${old}_lastest_${LIBNAME}-*" >> "${tmpfl}"
399+
fi
400+
fi
401+
done
402+
# cap things at 15, so we don't exceed the time
403+
sed -i 16q "${tmpfl}"
404+
echo "bye" >> "${tmpfl}"
405+
# if it is only cd & bye, skip it
406+
if [ "$(wc -l "${tmpfl}" | awk '{print $1}')" -gt "2" ] ; then
407+
sftp_run_cmds "${tmpfl}"
408+
fi
409+
rm "${tmpfl}"
410+
411+
#Now that we removed things, do it again
412+
rm "${LIBNAME}_index.html"
413+
ssh -o "StrictHostKeyChecking no" "${EXTRA_SSH}" "${SSHUSER}@${SSHHOST}" \
414+
"ls -lt ${DEPLOY_TO}" | grep "${LIBNAME}" > "${LIBNAME}_index.html"
415+
sftp_upload "${LIBNAME}_index.html" "${LIBNAME}_index.html"
268416

269417
return 0
270418
}
@@ -347,6 +495,11 @@ is_centos_at_least_ver() {
347495
version_ge "$(get_version)" "$1"
348496
}
349497

498+
is_arm() {
499+
[ "$(dpkg --print-architecture)" = "armhf" ] || return 1
500+
test "$(dpkg --print-architecture)" = "armhf"
501+
}
502+
350503
print_github_api_rate_limits() {
351504
# See https://developer.github.com/v3/rate_limit/
352505
# Note: Accessing this endpoint does not count against your REST API rate limit.

0 commit comments

Comments
 (0)