diff mbox

[fsl-community-bsp-base] setup-environment: provide a MACHINE menu

Message ID 1395862407-29020-1-git-send-email-trevor.woerner@linaro.org
State New
Headers show

Commit Message

Trevor Woerner March 26, 2014, 7:33 p.m. UTC
If the user hasn't specified a MACHINE in the environment, and the specified
build directory doesn't contain conf/local.conf and conf/bblayers.conf, then
provide the user with a list of machines and have them choose one by number.

Signed-off-by: Trevor Woerner <trevor.woerner@linaro.org>
---
 setup-environment | 45 ++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 5 deletions(-)

I would very much have liked to have been able to use "select", but (alas) it
is a bash-ism.

Comments

Daiane.Angolini@freescale.com March 27, 2014, 1:28 p.m. UTC | #1
> -----Original Message-----
> From: meta-freescale-bounces@yoctoproject.org [mailto:meta-freescale-
> bounces@yoctoproject.org] On Behalf Of Trevor Woerner
> Sent: Wednesday, March 26, 2014 4:33 PM
> To: meta-freescale@yoctoproject.org
> Cc: Otavio Salvador; patches@linaro.org
> Subject: [meta-freescale] [PATCH][fsl-community-bsp-base] setup-
> environment: provide a MACHINE menu
> 
> If the user hasn't specified a MACHINE in the environment, and the
> specified build directory doesn't contain conf/local.conf and
> conf/bblayers.conf, then provide the user with a list of machines and have
> them choose one by number.
> 
> Signed-off-by: Trevor Woerner <trevor.woerner@linaro.org>

Hi Trevor, I´m still deciding if I like or dislike your patch =P

It´s queued in my test list and I should let you know what I think after I had tested it

It will take some time, but "you are not alone, i´m here with you, lalalala" OK?

Daiane
Otavio Salvador March 27, 2014, 5:53 p.m. UTC | #2
Hello Trevor,

On Wed, Mar 26, 2014 at 4:33 PM, Trevor Woerner
<trevor.woerner@linaro.org> wrote:
> If the user hasn't specified a MACHINE in the environment, and the specified
> build directory doesn't contain conf/local.conf and conf/bblayers.conf, then
> provide the user with a list of machines and have them choose one by number.
>
> Signed-off-by: Trevor Woerner <trevor.woerner@linaro.org>

Conceptually I like the idea. My current concern is about using
numbers to choose the machine.

The numbers are not going to be consistent during time (the number 20
today may point, in future to a different board). Maybe you could
offer a prompt for user to type the board name?
diff mbox

Patch

diff --git a/setup-environment b/setup-environment
index 861d854..fc42cc4 100644
--- a/setup-environment
+++ b/setup-environment
@@ -29,13 +29,16 @@  usage()
     echo -e "\nUsage: source $PROGNAME <build-dir>
     <build-dir>: required option; specifies build directory location
 
-By default the script will setup MACHINE to be imx6qsabresd.
+Either specify the MACHINE in the environment, or choose
+one from the list provided when the script is run.
 
 Supported machines: `ls sources/*/conf/machine/*.conf \
 | sed s/\.conf//g | sed -r 's/^.+\///' | xargs echo`
 
 To build for a machine listed above, run this script as:
-MACHINE=<machine> source $PROGNAME <build-dir>
+    MACHINE=<machine> source $PROGNAME <build-dir>
+or don't specify the MACHINE and the script will prompt
+you for one with a list.
 
 The script sets PARALLEL_MAKE & BB_NUMBER_THREADS to $NCPU
 "
@@ -43,7 +46,8 @@  The script sets PARALLEL_MAKE & BB_NUMBER_THREADS to $NCPU
 
 clean_up()
 {
-   unset EULA LIST_MACHINES VALID_MACHINE
+   unset EULA LIST_MACHINES VALID_MACHINE MACHINELIST MACHINECNT EXISTINGCONFIG
+   unset _i _opt
    unset NCPU CWD TEMPLATES SHORTOPTS LONGOPTS ARGS PROGNAME
 }
 
@@ -79,10 +83,41 @@  if [ "$(whoami)" = "root" ]; then
     echo "ERROR: do not use the BSP as root. Exiting..."
 fi
 
-if [ -z "$MACHINE" ]; then
-    MACHINE='imx6qsabresd'
+EXISTINGCONFIG=
+if [ -f $1/conf/local.conf ] && [ -f $1/conf/bblayers.conf ]; then
+    EXISTINGCONFIG="yes"
 fi
 
+MACHINELIST=`ls -1 */*/conf/machine/*conf 2> /dev/null | cut -d'/' -f5 | cut -d'.' -f1 | sort -n | uniq`
+MACHINECNT=`echo $MACHINELIST | wc -w`
+machine_menu()
+{
+    _i=1
+    while [ $_i -le $MACHINECNT ]; do
+        echo -n "$_i) "
+        echo $MACHINELIST | cut -d' ' -f$_i
+        _i=`expr $_i + 1`
+    done
+}
+_opt=
+if [ -z "$MACHINE" ] && [ -z "$EXISTINGCONFIG" ]; then
+    while [ -z "$_opt" ]; do
+        machine_menu
+        echo -n "Please choose a MACHINE: "
+        read _opt
+        if echo $_opt | grep -qE "^[0-9]+$"; then
+            if [ $_opt -gt 0 ] && [ $_opt -le $MACHINECNT ]; then
+                MACHINE=`echo $MACHINELIST | cut -d' ' -f$_opt`
+                break
+            fi
+        fi
+        echo "invalid input: \"$_opt\""
+        echo ""
+        _opt=
+    done
+fi
+unset _opt _i EXISTINGCONFIG MACHINELIST MACHINECNT
+
 # Check the machine type specified
 LIST_MACHINES=`ls -1 $CWD/sources/*/conf/machine`
 VALID_MACHINE=`echo -e "$LIST_MACHINES" | grep ${MACHINE}.conf$ | wc -l`