2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # stefan.k.berg@ericsson.com
5 # jonas.bjurel@ericsson.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
12 ############################################################################
13 # BEGIN of usage description
18 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
19 `basename $0`: Builds the Fuel@OPNFV stack
21 usage: `basename $0` [-s spec-file] [-c cache-URI] [-l log-file] [-f flags]
25 -s spec-file (NOTE! DEPRECATED!)
26 define the build-spec file, default ../build/config.mk. The script only
27 verifies that the spec-file exists.
29 specifies the base URI to a build cache to be used/updated, supported
30 methods are http://, ftp:// and file://
32 specifies the output log-file (stdout and stderr), if not specified
33 logs are output to console as normal
35 version tag to be applied to the build result
37 alternative remote access method script/program. curl is default.
40 s: Do nothing, succeed
43 P: Clear the local cache before building. This flag is only
44 valid if the "-c cache-URI" options has been specified and
45 and the method in the cache-URI is file:// (local cache).
47 -h help, prints this help text
49 output-directory, specifies the directory for the output artifacts
50 (.iso file). If no output-directory is specified, the current path
51 when calling the script is used.
56 build.sh builds the opnfv .iso artifact.
57 To reduce build time it uses build caches on a local or remote location. A
58 cache is rebuilt and uploaded if either of the below conditions are met:
59 1) The P(opulate) flag is set and the -c cache-base-URI is provided and set
60 to the method file:// , if -c is
61 not provided the cache will stay local.
62 2) If a cache is invalidated by the make system - the exact logic is encoded
63 in the cache.mk of the different parts of the build.
64 3) A valid cache does not exist on the specified -c cache-base-URI.
66 A cache has a blob (binary data) and a meta file in the format of:
70 Logging is by default to console, but can be directed elsewhere with the -l
71 option in which case both stdout and stderr is redirected to that destination.
73 Built in unit testing of components is enabled by adding the t(est) flag.
77 - 1-99 Unspecified build error
78 - 100-199 Build system internal error (not build it self)
79 - 101 Build system instance busy
83 build -c http://opnfv.org/artifactory/fuel/cache \
84 -d ~/jenkins/genesis/fuel/ci/output -f ti
86 NOTE: At current the build scope is set to the git root of the repository, -d
87 destination locations outside that scope will not work!
91 # END of usage description
92 ############################################################################
94 ############################################################################
95 # BEGIN of function error_exit
103 # END of function error_exit
104 ############################################################################
107 ############################################################################
108 # BEGIN of shorthand variables for internal use
110 SCRIPT_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
111 BUILD_BASE=$(readlink -e ${SCRIPT_DIR}/../build/)
112 RESULT_DIR="${BUILD_BASE}/release"
113 BUILD_SPEC="${BUILD_BASE}/config.mk"
114 LOCAL_CACHE_ARCH_NAME="${LOCAL_CACHE_ARCH_NAME:-fuel-cache}"
117 # END of variables to customize
118 ############################################################################
120 ############################################################################
121 # BEGIN of script assigned default variables
123 export CACHEBASE="file://$HOME/cache"
124 export CACHETRANSPORT="curl --silent"
129 # END of script assigned variables
130 ############################################################################
133 echo "CI build parameters:"
134 echo "SCRIPT_DIR = $SCRIPT_DIR"
135 echo "BUILD_BASE = $BUILD_BASE"
136 echo "RESULT_DIR = $RESULT_DIR"
137 echo "BUILD_SPEC = $BUILD_SPEC"
138 echo "LOCAL_CACHE_ARCH_NAME = $LOCAL_CACHE_ARCH_NAME"
139 echo "CLEAR_CACHE = $CLEAR_CACHE"
140 echo "DEBUG = $DEBUG"
141 echo "OUTPUT_DIR = $OUTPUT_DIR"
142 echo "BUILD_LOG = $BUILD_LOG"
143 echo "MAKE_ARGS = $MAKE_ARGS"
144 echo "CACHEBASE = $CACHEBASE"
145 echo "CACHETRANSPORT = $CACHETRANSPORT"
148 if [ "$CLEAR_CACHE" -eq 1 ]; then
149 echo $CACHEBASE | grep -q '^file://' $CACHE_BASE
150 if [ $? -ne 0 ]; then
151 error_exit "Can't clear a non-local cache!"
153 CACHEDIR=$(echo $CACHEBASE | sed 's;file://;;')
154 echo "Clearing local cache at $CACHEDIR..."
159 echo make ${MAKE_ARGS} cache
162 if make ${MAKE_ARGS} cache; then
163 echo "Copying build result into $OUTPUT_DIR"
164 sort ${BUILD_BASE}/gitinfo*.txt > ${OUTPUT_DIR}/gitinfo.txt
165 cp ${RESULT_DIR}/*.iso ${OUTPUT_DIR}
166 cp ${RESULT_DIR}/*.iso.txt ${OUTPUT_DIR}
168 error_exit "Build failed"
172 ############################################################################
175 while getopts "s:c:l:v:f:r:f:h" OPTION
180 if [ ! -f ${BUILD_SPEC} ]; then
181 echo "spec file does not exist: $BUILD_SPEC - exiting ...."
186 # This value is used by cache.sh
187 export CACHEBASE=${OPTARG}
190 BUILD_LOG=$(readlink -f ${OPTARG})
193 MAKE_ARGS+="REVSTATE=${OPTARG}"
196 # This value is used by cache.sh
197 export CACHETRANSPORT=${OPTARG}
205 BUILD_FLAGS=${OPTARG}
206 for ((i=0; i<${#BUILD_FLAGS};i++)); do
207 case ${BUILD_FLAGS:$i:1} in
225 error_exit "${BUILD_FLAGS:$i:1} is not a valid build flag - exiting ...."
232 echo "${OPTION} is not a valid argument"
239 # Get output directory
243 # No directory on command line
247 # Directory on command line
248 OUTPUT_DIR=$(readlink -f $1)
251 error_exit "Too many arguments"
254 mkdir -p $OUTPUT_DIR || error_exit "Could not access output directory $OUTPUT_DIR"
257 if [ -n "${BUILD_LOG}" ]; then
258 touch ${BUILD_LOG} || error_exit "Could not write to log file ${BUILD_LOG}"
259 build 2>&1 | tee ${BUILD_LOG}
269 ############################################################################