Skip to content

Commit

Permalink
[helpers] add build_packages.sh
Browse files Browse the repository at this point in the history
HADK document will call this script to avoid manually executing a
huge amount of commands just to e.g. take in a change in patterns.

Also, build bug can now be fixed in this script, instead of releasing
a new HADK version.
  • Loading branch information
Alin Marin Elena authored and sledges committed Apr 27, 2015
1 parent e5d4806 commit f714c75
Show file tree
Hide file tree
Showing 2 changed files with 301 additions and 0 deletions.
85 changes: 85 additions & 0 deletions helpers/build_packages.sh
@@ -0,0 +1,85 @@
#!/bin/bash
# build_packages.sh - takes care of rebuilding droid-hal-device, -configs, and
# -version, as well as any middleware packages. All in correct sequence, so that
# any change made (e.g. to patterns) could be simply picked up just by
# re-running this script.
#
# Copyright (C) 2015 Alin Marin Elena <alin@elena.space>
# Copyright (C) 2015 Jolla Ltd.
# Contact: Simonas Leleiva <simonas.leleiva@jollamobile.com>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the <organization> nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

if [ -z $DEVICE ]; then
echo 'Error: $DEVICE is undefined. Please run hadk'
exit 1
fi
if [[ ! -d rpm/helpers && ! -d rpm/dhd ]]; then
echo $0: launch this script from the $ANDROID_ROOT directory
exit 1
fi

# utilities
. $ANDROID_ROOT/rpm/dhd/helpers/util.sh


if [ ! -d rpm/dhd ]; then
echo "rpm/dhd/ does not exist, please run migrate first."
exit 1
fi
LOCAL_REPO=$ANDROID_ROOT/droid-local-repo/$DEVICE
rm -rf $LOCAL_REPO/droid-hal-*
rm -rf $LOCAL_REPO/droid-config-*
builddhd
buildconfigs
echo "-------------------------------------------------------------------------------"

read -p 'About to perform "Build HA Middleware Packages" HADK chapter. Press Enter to continue.'
sb2 -t $VENDOR-$DEVICE-$ARCH -R -msdk-install ssu domain sales
sb2 -t $VENDOR-$DEVICE-$ARCH -R -msdk-install ssu dr sdk

sb2 -t $VENDOR-$DEVICE-$ARCH -R -msdk-install zypper ref -f
sb2 -t $VENDOR-$DEVICE-$ARCH -R -msdk-install zypper -n install droid-hal-$DEVICE-devel

rm -rf $MER_ROOT/devel/mer-hybris
mkdir -p $MER_ROOT/devel/mer-hybris
pushd $MER_ROOT/devel/mer-hybris

buildmw libhybris || die
sb2 -t $VENDOR-$DEVICE-$ARCH -R -msdk-build zypper -n rm mesa-llvmpipe
buildmw "https://github.com/nemomobile/mce-plugin-libhybris.git" || die
buildmw ngfd-plugin-droid-vibrator || die
buildmw "https://github.com/mer-hybris/pulseaudio-modules-droid.git" rpm/pulseaudio-modules-droid.spec || die
buildmw qt5-feedback-haptics-droid-vibrator || die
buildmw qt5-qpa-hwcomposer-plugin || die
buildmw "https://github.com/mer-hybris/qtscenegraph-adaptation.git" rpm/qtscenegraph-adaptation-droid.spec || die
buildmw "https://github.com/mer-packages/qtsensors.git" || die
buildmw "https://github.com/mer-packages/sensorfw.git" rpm/sensorfw-qt5-hybris.spec || die
read -p '"Build HA Middleware Packages built". Press Enter to continue.'
popd

buildversion
echo "----------------------DONE! Now proceed on creating the rootfs------------------"
216 changes: 216 additions & 0 deletions helpers/util.sh
@@ -0,0 +1,216 @@
#!/bin/bash
# util.sh - all refactored bits/functions go here
#
# Copyright (C) 2015 Alin Marin Elena <alin@elena.space>
# Copyright (C) 2015 Jolla Ltd.
# Contact: Simonas Leleiva <simonas.leleiva@jollamobile.com>
#
# All rights reserved.
#
# This script uses parts of code located at https://github.com/dmt4/sfa-mer
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the <organization> nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

source ~/.hadk.env

ARCH="${ARCH:-$ARCH}"

function minfo {
echo -e "\e[01;34m* $* \e[00m"
}

function merror {
echo -e "\e[01;31m!! $* \e[00m"
}

function die {
if [ -z "$*" ]; then
merror "command failed at `date`, dying..."
else
merror "$*"
fi
exit 1
}

function die_with_log {
if [ -f "$1" ] ; then
tail -n10 "$1"
minfo "Check `pwd`/`basename $1` for full log."
fi
shift
die $*
}

function buildconfigs() {
cd hybris/droid-configs
mb2 -t $VENDOR-$DEVICE-$ARCH \
-s rpm/droid-config-$DEVICE.spec \
build
mv -v RPMS/*.rpm $LOCAL_REPO || die
cd ../../

createrepo $LOCAL_REPO
sb2 -t $VENDOR-$DEVICE-$ARCH -R -m sdk-install \
zypper ref
}

function builddhd() {
mb2 -t $VENDOR-$DEVICE-$ARCH -s rpm/droid-hal-$DEVICE.spec build

mv -v RPMS/*$DEVICE* $LOCAL_REPO
createrepo $LOCAL_REPO

sb2 -t $VENDOR-$DEVICE-$ARCH -R -m sdk-install \
ssu ar local-$DEVICE-hal-$1 file://$LOCAL_REPO

sb2 -t $VENDOR-$DEVICE-$ARCH -R -m sdk-install \
zypper ref
}

function buildversion() {
cd hybris/droid-hal-version-$DEVICE
mb2 -t $VENDOR-$DEVICE-$ARCH \
-s rpm/droid-hal-version-$DEVICE.spec \
build
mv -v RPMS/*.rpm $LOCAL_REPO
cd ../../
}

function yesno() {
read -r -p "${1:-} [Y/n]" REPLY
REPLY=${REPLY:-y}
case $REPLY in
[yY])
true
;;
*)
false
;;
esac
}

function buildmw {

GIT_URL="$1"
shift

[ -z "$GIT_URL" ] && die "Please give me the git URL (or directory name, if it's already installed)."


PKG="$(basename ${GIT_URL%.git})"
yesno "Build $PKG?"
if [ $? == "0" ]; then
if [ "$GIT_URL" = "$PKG" ]; then
GIT_URL=https://github.com/mer-hybris/$PKG.git
minfo "No git url specified, assuming $GIT_URL"
fi

cd "$MER_ROOT/devel/mer-hybris" || die
LOG="`pwd`/$PKG.log"
[ -f "$LOG" ] && rm "$LOG"

if [ ! -d $PKG ] ; then
minfo "Source code directory doesn't exist, clonig repository"
git clone $GIT_URL >>$LOG 2>&1|| die_with_log "$LOG" "cloning of $GIT_URL failed"
fi

pushd $PKG || die
minfo "pulling updates..."
git pull >>$LOG 2>&1|| die_with_log "$LOG" "pulling of updates failed"
git submodule update >>$LOG 2>&1|| die_with_log "$LOG" "pulling of updates failed"

SPECS="$*"
if [ -z "$SPECS" ]; then
minfo "No spec files for package building specified, building all I can find."
SPECS="rpm/*.spec"
fi

for SPEC in $SPECS ; do
minfo "Building $SPEC"
mb2 -s $SPEC -t $VENDOR-$DEVICE-$ARCH build >>$LOG 2>&1|| die_with_log "$LOG" "building of package failed"
done
minfo "Building successful, adding packages to repo"
mkdir -p "$ANDROID_ROOT/droid-local-repo/$DEVICE/$PKG" >>$LOG 2>&1|| die_with_log "$LOG"
rm -f "$ANDROID_ROOT/droid-local-repo/$DEVICE/$PKG/"*.rpm >>$LOG 2>&1|| die_with_log "$LOG"
mv RPMS/*.rpm "$ANDROID_ROOT/droid-local-repo/$DEVICE/$PKG" >>$LOG 2>&1|| die_with_log "$LOG"
createrepo "$ANDROID_ROOT/droid-local-repo/$DEVICE" >>$LOG 2>&1|| die_with_log "$LOG" "can't create repo"
sb2 -t $VENDOR-$DEVICE-$ARCH -R -msdk-install zypper ref >>$LOG 2>&1|| die_with_log "$LOG" "can't update pkg info"
minfo "Building of $PKG finished successfully"
popd
fi
echo
}
function buildmwb {

GIT_URL="$1"
shift
GIT_BRANCH="$1"
shift

[ -z "$GIT_URL" ] && die "Please give me the git URL (or directory name, if it's already installed)."


PKG="$(basename ${GIT_URL%.git})"
yesno "Build $PKG?"
if [ $? == "0" ]; then
if [ "$GIT_URL" = "$PKG" ]; then
GIT_URL=https://github.com/mer-hybris/$PKG.git
minfo "No git url specified, assuming $GIT_URL"
fi

cd "$MER_ROOT/devel/mer-hybris" || die
LOG="`pwd`/$PKG.log"
[ -f "$LOG" ] && rm "$LOG"

if [ ! -d $PKG ] ; then
minfo "Source code directory doesn't exist, clonig repository"
git clone $GIT_URL -b $GIT_BRANCH>>$LOG 2>&1|| die_with_log "$LOG" "cloning of $GIT_URL failed"
fi

pushd $PKG || die
minfo "pulling updates..."
git pull >>$LOG 2>&1|| die_with_log "$LOG" "pulling of updates failed"
git submodule update >>$LOG 2>&1|| die_with_log "$LOG" "pulling of updates failed"

SPECS="$*"
if [ -z "$SPECS" ]; then
minfo "No spec files for package building specified, building all I can find."
SPECS="rpm/*.spec"
fi

for SPEC in $SPECS ; do
minfo "Building $SPEC"
mb2 -s $SPEC -t $VENDOR-$DEVICE-$ARCH build >>$LOG 2>&1|| die_with_log "$LOG" "building of package failed"
done
minfo "Building successful, adding packages to repo"
mkdir -p "$ANDROID_ROOT/droid-local-repo/$DEVICE/$PKG" >>$LOG 2>&1|| die_with_log "$LOG"
rm -f "$ANDROID_ROOT/droid-local-repo/$DEVICE/$PKG/"*.rpm >>$LOG 2>&1|| die_with_log "$LOG"
mv RPMS/*.rpm "$ANDROID_ROOT/droid-local-repo/$DEVICE/$PKG" >>$LOG 2>&1|| die_with_log "$LOG"
createrepo "$ANDROID_ROOT/droid-local-repo/$DEVICE" >>$LOG 2>&1|| die_with_log "$LOG" "can't create repo"
sb2 -t $VENDOR-$DEVICE-$ARCH -R -msdk-install zypper ref >>$LOG 2>&1|| die_with_log "$LOG" "can't update pkg info"
minfo "Building of $PKG finished successfully"
popd
fi
echo
}

0 comments on commit f714c75

Please sign in to comment.