2 ##############################################################################
3 # Copyright (c) 2016 Dan Radez (Red Hat) and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
16 $0 Builds the Apex OPNFV Deployment Toolchain
18 usage: $0 [ -c cache_dir ] -r release_name [ --iso | --rpms ]
21 -c cache destination - directory of cached files, defaults to ./cache
22 -r release name/version of the build result
23 --iso build the iso (implies RPMs too)
26 -h help, prints this help text
29 build -c file:///tmp/cache -r dev123
33 BUILD_BASE=$(readlink -e ../build/)
36 CACHE_NAME="apex-cache"
39 REQUIRED_PKGS="rpm-build python-docutils"
42 while [ "${1:0:1}" = "-" ]
59 echo "Building opnfv-apex RPMs and ISO"
64 echo "Buiding opnfv-apex RPMs"
69 echo "Skipping Python Tests"
74 echo "Enable debug output"
87 make $MAKE_ARGS -C ${BUILD_BASE} $1
92 # Install build dependencies
93 for pkg in $REQUIRED_PKGS; do
94 if ! rpm -q $pkg > /dev/null; then
95 if ! sudo yum -y install $pkg > /dev/null; then
96 echo "Required package $pkg missing and installation failed."
102 if [ -n "$RELEASE" ]; then MAKE_ARGS+="RELEASE=$RELEASE "; fi
105 if [ -n "$CACHE_DEST" ]; then
106 echo "Retrieving Cache"
107 if [ -f $CACHE_DEST/${CACHE_NAME}.tgz ]; then
108 echo "Cache found at ${CACHE_DEST}/${CACHE_NAME}.tgz"
109 rm -rf $BUILD_BASE/$CACHE_DIR
110 echo "Unpacking Cache to $BUILD_BASE"
111 tar -xvzf $CACHE_DEST/${CACHE_NAME}.tgz -C ${BUILD_BASE}
112 echo "Cache contents after unpack:"
113 ls -l $BUILD_BASE/$CACHE_DIR
114 elif [ ! -d $BUILD_BASE/$CACHE_DIR ]; then
115 mkdir $BUILD_BASE/$CACHE_DIR
119 # Conditionally execute RPM build checks if the specs change and target is not rpm or iso
120 if [[ "$MAKE_TARGETS" == "images" ]]; then
121 commit_file_list=$(git show --pretty="format:" --name-only)
122 if [[ $commit_file_list == *build/Makefile* ]]; then
123 # Makefile forces all rpms to be checked
124 MAKE_TARGETS+=" rpms-check"
126 # Spec files are selective
127 if [[ $commit_file_list == *build/opnfv-apex-undercloud.spec* ]]; then
128 MAKE_TARGETS+=" undercloud-rpm-check"
130 if [[ $commit_file_list == *build/opnfv-apex-common.spec* ]]; then
131 MAKE_TARGETS+=" common-rpm-check"
133 if [[ $commit_file_list == *build/opnfv-apex.spec* ]]; then
134 MAKE_TARGETS+=" opendaylight-rpm-check"
136 if [[ $commit_file_list == *build/opnfv-apex-onos.spec* ]]; then
137 MAKE_TARGETS+=" onos-rpm-check"
139 if [[ $commit_file_list == *build/opnfv-apex-opendaylight-sfc.spec* ]]; then
140 MAKE_TARGETS+=" opendaylight-sfc-rpm-check"
145 # Make sure python is installed
146 if ! rpm -q python34-devel > /dev/null; then
147 sudo yum install -y epel-release
148 if ! sudo yum install -y python34-devel; then
149 echo "Failed to install python34-devel package..."
154 if [ "$PYTHON_TESTS" == "TRUE" ]; then
155 # Make sure coverage is installed
156 if ! python3 -c "import coverage" &> /dev/null; then sudo easy_install-3.4 coverage; fi
158 run_make python-tests
159 pushd ../tests/ > /dev/null
160 percent=$(coverage3 report --include '*lib/python/*' -m | grep TOTAL | tr -s ' ' | awk '{ print $4 }' | cut -d % -f 1)
161 if [[ percent -lt 80 ]]; then
162 echo "Python Coverage: $percent"
163 echo "WARNING: Does not meet 80% requirement"
168 # Execute make against targets
169 for t in $MAKE_TARGETS; do
173 echo "Build Complete"
176 if [ -n "$CACHE_DEST" ]; then
177 echo "Building Cache"
178 if [ ! -d $CACHE_DEST ]; then mkdir -p $CACHE_DEST; fi
179 tar --atime-preserve --dereference -C $BUILD_BASE -caf $BUILD_BASE/${CACHE_NAME}.tgz $CACHE_DIR -C ${CACHE_DEST}/
180 if [ -f "${CACHE_DEST}/${CACHE_NAME}.tgz" ]; then
181 echo "Cache Build Complete"
183 echo "WARN: Cache file did not build correctly"