aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/README.md28
-rwxr-xr-xscripts/checkout_layer_hash.sh112
2 files changed, 118 insertions, 22 deletions
diff --git a/scripts/README.md b/scripts/README.md
new file mode 100644
index 0000000..c461c36
--- /dev/null
+++ b/scripts/README.md
@@ -0,0 +1,28 @@
+# Scripts
+
+## checkout_layer_hash.sh
+
+A build helper for meta-ivi.
+
+This script extract the revision information for dependent layers (poky
+and meta-openembedded) from the README of meta-ivi so that automated builds
+are possible.
+
+Usage:
+
+Run in meta-ivi repository root (meta-ivi, not meta-ivi/meta-ivi).
+The script assumes you have cloned poky and meta-openembedded inside
+meta-ivi root which is normally not the case in a full system build -
+then meta-ivi is in parallel with all other layers, but when building
+the baseline only, we assume the build happens inside of meta-ivi dir.
+
+
+Example:
+$ cd meta-ivi
+ (the first one)
+$ checkout_layer_hash.sh poky
+$ checkout_layer_hash.sh meta-openembedded
+
+## Other scripts
+
+* See README.md in project root
diff --git a/scripts/checkout_layer_hash.sh b/scripts/checkout_layer_hash.sh
index a00dda4..93299d8 100755
--- a/scripts/checkout_layer_hash.sh
+++ b/scripts/checkout_layer_hash.sh
@@ -1,38 +1,106 @@
#!/bin/sh
-# (C) 2015-12-12 Gunnar Andersson
-# (C) 2016-10-25 Yong-iL Joh
+# (C) Gunnar Andersson 2015-12-12
# License: MPLv2
+# This fetches information about layer dependencies
+# as documented in meta-ivi README.
+# revision, branch name, or sub layer name can be extracted
+
+README=README.md
+DEBUG=false
+
+
fail() {
- echo "FAILED."
+ echo "*** FAILED ***"
[ -n "$1" ] && echo "Message: " $@
exit 1
}
-# Store the location of these scripts
-_DIR=$(dirname "$0")
-META_IVI=$(readlink -f $_DIR/..)
-MYDIR=$(readlink -f $_DIR)
+sanity_check_num_lines() {
+ what=$1 ; min=$2 ; max=$3
+
+ numlines="$(wc -l)" # < Reads from stdin
+
+ if [ $numlines -lt $min ] ; then
+ fail "Sanity check: It looks like section $what has $numlines lines, and that is not enough. Please check what is wrong."
+ fi
+
+ if [ $numlines -gt $max ] ; then
+ fail "Sanity check: It looks like section $what has $numlines lines, and that is more than expected. Please check what is wrong."
+ fi
+}
+
+[ -f ./$README ] || fail "Cannot find README.md. (Current directory is $PWD)"
+
+get_layer_info() {
+ layer=$1
+ what=$2
-layer=$1
-[ -z "$layer" ] && fail "No layer name given"
+ # Example README format:
+ #
+ #Layer Dependencies
+ #------------------
+ #
+ #URI: git://git.yoctoproject.org/poky
+ #> branch: fido
+ #> revision: eb4a134a60e3ac26a48379675ad6346a44010339
+ #
+ #URI: git://git.openembedded.org/meta-openembedded
+ #> layer: meta-oe
+ #> branch: fido
+ #> revision: 5b0305d9efa4b5692cd942586fb7aa92dba42d59
+
+ # Extract relevant section of the README
+ dependency_section=$( <$README \
+ sed -n '/Layer Dependencies/,/known to work/p' |\
+ egrep 'URI:|branch:|layer:|revision:')
+
+ # Debug printouts...
+ $DEBUG && echo "OK, found the following layer info in dependency section:"
+ $DEBUG && cat <<EOT
+ $dependency_section
+EOT
+
+ cat <<EOT | sanity_check_num_lines "Layer Dependencies Section" 6 20
+ $dependency_section
+EOT
+
+ # Get only this layer's information
+ layer_info=$(
+ cat <<EOT | sed -n "/URI:.*$layer/,/URI:/p" | sed 's/> //' | head -4
+ $dependency_section
+EOT
+ )
+
+ # Get value for item "what" (what = revision, branch, ...)
+ value=$(
+ cat <<EOT | grep "$what" | awk '{print $2}'
+ $layer_info
+EOT
+ )
+
+ # Check again - now only one line expected...
+ cat <<EOT | sanity_check_num_lines "$what information for $layer" 1 1
+ $value
+EOT
+
+ # OK, this should be it
+ echo $value
+
+}
+
+checkoutlayer=$1
+[ -z "$checkoutlayer" ] && { echo "Usage: $0 <layername, e.g. poky>" ; exit 1 ; }
# Extract revision from README in meta-ivi
-cd "$META_IVI" || fail "Can't cd to meta-ivi directory"
-revision=$($MYDIR/get_layer_info_from_README.sh $layer revision)
-uri=$($MYDIR/get_layer_info_from_README.sh $layer URI)
+revision=$(get_layer_info $checkoutlayer revision)
# Fail if we could not fetch revision
[ -z "$revision" ] && fail "Revision extracted from README was empty"
-# Checkout the right revision in this layer
-if [ ! -d "$META_IVI/../$layer/.git" ]; then
- if [ -e "$META_IVI/../$layer" ]; then
- rm -rf "$META_IVI/../$layer"
- else
- cd "$META_IVI/.."
- git clone $uri
- fi
-fi
-cd "$META_IVI/../$layer" || fail "Can't cd to layer directory ($layer)"
+# Checkout the right revision in this layer. We expect the layer, e.g.
+# poky to be found inside the root of meta-ivi, that is the $PWD when
+# this script is run. (Not true on full system builds, but typically
+# when building baseline only)
+cd ../"$checkoutlayer" || fail "Can't cd to layer directory ($checkoutlayer)"
git checkout $revision