blob: 8c3f699393c840749e1b76a7866e38e5389cd794 [file] [log] [blame]
E. Scott Danielsd4f18ba2019-06-17 15:08:17 -04001#!/usr/bin/env ksh
2# :vim ts=4 sw=4 noet:
3#==================================================================================
4# Copyright (c) 2019 Nokia
5# Copyright (c) 2018-2019 AT&T Intellectual Property.
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#==================================================================================
19#
20
21# Mnemonic: ci_build.ksh
22# Abstract: Script builds RMr, exececutes the unit and application based
23# tests, then generates packages. The packages are left in /tmp
24# unless -t target-dir is given on the command line. A YAML file
25# is created which can be used to find all of the packages which
26# were deposited in the target directory. In an environment which
27# is also capable of generating RPM ppackages, there should be
28# four packages: a run-time and development package for both
29# debian (.deb) and rh (rpm) based systems.
30#
31# The intent of this script is for it to be executed as a part
32# of a docker image build process such that the resulting image
33# contains the RMr packages, and a YAML file which provides the
34# paths to the package(s) in the image. Docker tools can then
35# be used to extract the packages and push them to some external
36# repository.
37#
38# Assumptions:
39# We assume that this scirpt is executed at the 'root' of the
40# RMr repo (i.e. the directory which has a subdirectory ci).
41#
42# Date: 14 June 2019
43# --------------------------------------------------------------------------------
44
E. Scott Daniels95359302019-07-30 12:37:48 -040045# stash a set of packages for a particular flavour ($1). Records what was kept
46# in a yaml file for an external process to grab, and in a simple publication
47# list for our internal publish script to gobble up.
E. Scott Danielsd4f18ba2019-06-17 15:08:17 -040048#
49function stash_pkgs {
E. Scott Daniels95359302019-07-30 12:37:48 -040050 mkdir -p $target_dir/exported
51
E. Scott Danielsd4f18ba2019-06-17 15:08:17 -040052 for pkg in deb rpm
53 do
54 ls .build/*.$pkg 2>/dev/null | while read f
55 do
E. Scott Daniels95359302019-07-30 12:37:48 -040056 cp $f $target_dir/exported/${f##*/}
57 echo " - $target_dir/exported/${f##*/}" >>$yaml_file
E. Scott Danielsd4f18ba2019-06-17 15:08:17 -040058 done
59
60 done
61}
62
63# ---------------------------------------------------------------------------
64
65target_dir="/tmp"
66verbose=0
67
68while [[ $1 == -* ]]
69do
70 case $1 in
71 -t) target_dir=$2; shift;;
72 -v) verbose=1;;
73
74 *) echo "$1 is not recognised"
75 echo ""
76 echo "usage: $0 [-t target-dir]"
E. Scott Daniels95359302019-07-30 12:37:48 -040077 echo " target dir defaults to /tmp and is where packages and lists are placed."
E. Scott Danielsd4f18ba2019-06-17 15:08:17 -040078 exit 1
79 ;;
80 esac
81
82 shift
83done
84
85if [[ ! -d $target_dir ]]
86then
E. Scott Daniels95359302019-07-30 12:37:48 -040087 if ! -mkdir -p $target_dir
88 then
89 echo "[FAIL] cannot find or create target directory: $target_dir"
90 exit 1
91 fi
E. Scott Danielsd4f18ba2019-06-17 15:08:17 -040092fi
93
94if [[ ! -d ./ci ]] # verify we are in the root of the RMr repo filesystem, abort if not
95then
96 echo "[FAIL] current working directory does not seem right; should be RMr repo root: $PWD"
97 exit 1
98fi
99
100set -e # fail unconditionally on first issue
101yaml_file=$target_dir/build_packages.yml
102rm -f $yaml_file
103
104mkdir -p .build
105(
106 cd .build
107 rm -f *.deb *.rpm # these shouldn't be there, but take no chances
108 cmake .. -DBUILD_DOC=1 -DDEV_PKG=1 # set up dev config for unit test (requires dev stuff)
109 make package
110)
111(
112 cd test # execute tests
113 ksh unit_test.ksh # unit tests first
114 cd app_test
115 ksh run_all.ksh # application based tests if units pass
116)
117
E. Scott Danielsf6f4f122019-06-18 16:02:17 -0400118printf "---\nfiles:\n" >$yaml_file # initialise the yaml file
E. Scott Danielsd4f18ba2019-06-17 15:08:17 -0400119
120stash_pkgs development # testing good, stash dev packages built above
121
122(
123 cd .build # now build the run-time packages
124 rm -f *.deb *.rpm # reconfig should delete these, but take no chances
125 cmake .. # configure run-time build
126 make package
127)
128stash_pkgs runtime # move packages to target and record in yaml file
129
130echo "..." >>$yaml_file # terminate yaml file
131
132set +e
133if (( verbose ))
134then
135 echo "generated yaml file:"
136 cat $yaml_file
137 echo ""
138 echo "------"
139 ls -al $target_dir/*.deb $target_dir/*.rpm
140fi
141
142exit 0