#!/bin/bash # # Copyright (c) 2018-2019 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # # This utility builds a set of python wheels for upstream packages, # reading a source list from wheels.cfg # CFGFILE=/wheels.cfg OUTPUTDIR=/wheels FAILED_LOG="${OUTPUTDIR}/failed.lst" : ${DISPLAY_RESULT=yes} declare -i MAX_ATTEMPTS=5 : ${PYTHON=python3} if [[ "${PYTHON}" == "python2" ]] ; then CFGFILE=/wheels-py2.cfg FAILED_LOG="${OUTPUTDIR}/failed-py2.lst" fi # # Function to log the start of a build # function startlog { cat <> $FAILED_LOG continue fi pushd $basedir if [ $? -ne 0 ]; then echo "Failure running: pushd $basedir" echo $wheelname >> $FAILED_LOG continue fi git fetch $gitrepo $branch if [ $? -ne 0 ]; then echo "Failure running: git fetch $gitrepo $branch" echo $wheelname >> $FAILED_LOG continue fi git checkout FETCH_HEAD if [ $? -ne 0 ]; then echo "Failure running: git checkout FETCH_HEAD" echo $wheelname >> $FAILED_LOG continue fi if [ "$fix" == "fix_setup" ]; then fix_setup fi # Build the wheel ${PYTHON} setup.py bdist_wheel if [ -f dist/$wheelname ]; then cp dist/$wheelname $OUTPUTDIR || echo $wheelname >> $FAILED_LOG else echo $wheelname >> $FAILED_LOG echo "Could not find dist/$wheelname" echo "Searching for wheel:" find dist/ -name '*.whl' fi popd done } # # Function to download a source tarball and build a wheel. # function from_tar { sed 's/#.*//' $CFGFILE | awk -F '|' '$2 == "tar" { print $0; }' | \ while IFS='|' read wheelname stype wgetsrc basedir fix; do startlog $wheelname if [ -f $OUTPUTDIR/$wheelname ]; then echo "$wheelname already exists" continue fi tarball=$(basename $wgetsrc) if [[ $tarball =~ gz$ ]]; then taropts="-xzf" elif [[ $tarball =~ bz2$ ]]; then taropts="-xjf" else taropts="-xf" fi with_retries ${MAX_ATTEMPTS} wget $wgetsrc if [ $? -ne 0 ]; then echo $wheelname >> $FAILED_LOG continue fi local -a tar_base_opts if [[ -z "$basedir" || "$basedir" == "." ]] ; then basedir="$(echo "$tarball" | sed -r -e 's#[.]tar([.].*)?$##')" mkdir -p "$basedir" tar_basedir_opts+=("-C" "$basedir") fi tar "${tar_basedir_opts[@]}" $taropts $(basename $wgetsrc) if [ $? -ne 0 ]; then echo "Failure running: tar $taropts $(basename $wgetsrc)" echo $wheelname >> $FAILED_LOG continue fi pushd $basedir if [ $? -ne 0 ]; then echo "Failure running: pushd $basedir" echo $wheelname >> $FAILED_LOG continue fi if [ "$fix" == "fix_setup" ]; then fix_setup fi # Build the wheel ${PYTHON} setup.py bdist_wheel if [ -f dist/$wheelname ]; then cp dist/$wheelname $OUTPUTDIR || echo $wheelname >> $FAILED_LOG else echo $wheelname >> $FAILED_LOG echo "Could not find dist/$wheelname" echo "Searching for wheel:" find dist/ -name '*.whl' fi popd done } # # Function to download a source zip file and build a wheel. # function from_zip { sed 's/#.*//' $CFGFILE | awk -F '|' '$2 == "zip" { print $0; }' | \ while IFS='|' read wheelname stype wgetsrc basedir fix; do startlog $wheelname if [ -f $OUTPUTDIR/$wheelname ]; then echo "$wheelname already exists" continue fi with_retries ${MAX_ATTEMPTS} wget $wgetsrc if [ $? -ne 0 ]; then echo $wheelname >> $FAILED_LOG continue fi unzip $(basename $wgetsrc) if [ $? -ne 0 ]; then echo "Failure running: unzip $(basename $wgetsrc)" echo $wheelname >> $FAILED_LOG continue fi pushd $basedir if [ $? -ne 0 ]; then echo "Failure running: pushd $basedir" echo $wheelname >> $FAILED_LOG continue fi if [ "$fix" == "fix_setup" ]; then fix_setup fi # Build the wheel ${PYTHON} setup.py bdist_wheel if [ -f dist/$wheelname ]; then cp dist/$wheelname $OUTPUTDIR || echo $wheelname >> $FAILED_LOG else echo $wheelname >> $FAILED_LOG echo "Could not find dist/$wheelname" echo "Searching for wheel:" find dist/ -name '*.whl' fi popd done } # # Function to download an existing wheel from pypi. # function from_pypi { sed 's/#.*//' $CFGFILE | awk -F '|' '$2 == "pypi" { print $0; }' | \ while IFS='|' read wheelname stype wgetsrc; do startlog $wheelname if [ -f $OUTPUTDIR/$wheelname ]; then echo "$wheelname already exists" continue fi with_retries ${MAX_ATTEMPTS} wget $wgetsrc if [ $? -ne 0 ]; then echo $wheelname >> $FAILED_LOG continue fi cp $wheelname $OUTPUTDIR || echo $wheelname >> $FAILED_LOG done } rm -f $FAILED_LOG mkdir -p /build-wheels cd /build-wheels from_git from_tar from_zip from_pypi if [ -f "${FAILED_LOG}" ]; then if [ "${DISPLAY_RESULT}" = yes ] ; then let failures=$(cat "${FAILED_LOG}" | wc -l) cat <