annotate scripts/build_project.sh @ 369:75689b7cd57b prerelease

Updated rsync command and command-line options
author Giulio Moro <giuliomoro@yahoo.it>
date Thu, 09 Jun 2016 02:48:58 +0100
parents 276a8517da13
children 137a87b745d2
rev   line source
andrewm@58 1 #!/bin/bash
andrewm@58 2 #
andrewm@58 3 # This script compiles a BeagleRT project on the BeagleBone Black and
andrewm@58 4 # optionally runs it. Pass a directory path in the first argument.
andrewm@58 5 # The source files in this directory are copied to the board and compiled.
andrewm@58 6
giuliomoro@262 7 # set defaults unless variables are already set
giuliomoro@262 8 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
giuliomoro@266 9 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/BeagleRT/"
giuliomoro@266 10 [ -z "$BBB_SCREEN_NAME" ] && BBB_SCREEN_NAME="BeagleRT"
giuliomoro@262 11 [ -z "$RUN_PROJECT" ] && RUN_PROJECT=1
giuliomoro@262 12 [ -z "$COMMAND_ARGS" ] && COMMAND_ARGS=
giuliomoro@262 13 [ -z "$RUN_IN_FOREGROUND" ] && RUN_IN_FOREGROUND=1
giuliomoro@262 14 [ -z "$RUN_WITHOUT_SCREEN" ] && RUN_WITHOUT_SCREEN=0
giuliomoro@264 15 [ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/"
giuliomoro@277 16 [ -z "$BBB_DEFAULT_PROJECT_NAME" ] && BBB_DEFAULT_PROJECT_NAME="scriptUploadedProject"
giuliomoro@277 17 [ -z "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME=$BBB_DEFAULT_PROJECT_NAME
andrewm@58 18
andrewm@58 19 function usage
andrewm@58 20 {
andrewm@58 21 THIS_SCRIPT=`basename "$0"`
giuliomoro@369 22 echo "Usage: $THIS_SCRIPT [-c command-line-args] [-nbfF] <directory-with-source-files>"
andrewm@58 23 echo "
andrewm@58 24 This script copies a directory of source files to the BeagleBone, compiles
andrewm@58 25 and runs it. The BeagleRT core files should have first been copied over
andrewm@58 26 using the setup_board.sh script supplied with BeagleRT.
andrewm@58 27
andrewm@58 28 The source directory should contain at least one .c, .cpp or .S file.
andrewm@58 29 If the argument -n is passed, the output will not be run after compiling.
giuliomoro@369 30 The -c option passes command-line arguments to
andrewm@90 31 the BeagleRT program; enclose the argument string in quotes.
andrewm@90 32
giuliomoro@263 33 By default, the project runs in the foreground of the current terminal,
giuliomoro@369 34 within a screen session that can be detached later. The -f argument runs
giuliomoro@263 35 the project in the foreground of the current terminal, without screen, so
giuliomoro@369 36 the output can be piped to another destination. The -b argument runs it
giuliomoro@263 37 in a screen in the background, so no output is shown."
andrewm@58 38 }
andrewm@58 39
andrewm@58 40 OPTIND=1
andrewm@58 41
giuliomoro@369 42 while getopts "bc:nfFhp:" opt; do
andrewm@58 43 case $opt in
andrewm@60 44 c) COMMAND_ARGS=$OPTARG
andrewm@60 45 ;;
giuliomoro@369 46 b) RUN_IN_FOREGROUND=0
giuliomoro@277 47 ;;
giuliomoro@369 48 f) RUN_WITHOUT_SCREEN=1
giuliomoro@277 49 ;;
andrewm@58 50 n) RUN_PROJECT=0
andrewm@58 51 ;;
giuliomoro@277 52 p) BBB_PROJECT_NAME=$OPTARG
giuliomoro@277 53 ;;
andrewm@58 54 h|\?) usage
andrewm@58 55 exit 1
andrewm@58 56 esac
andrewm@58 57 done
andrewm@58 58
andrewm@58 59 shift $((OPTIND-1))
andrewm@58 60
andrewm@58 61 # Check that we have a directory containing at least one source file
andrewm@58 62 # as an argument
giuliomoro@64 63
andrewm@58 64 if [ -z "$1" ]
andrewm@58 65 then
andrewm@58 66 usage
andrewm@58 67 exit
andrewm@58 68 fi
andrewm@58 69
giuliomoro@64 70 FIND_STRING="find $* -maxdepth 10000 -type f "
giuliomoro@64 71
giuliomoro@64 72 C_FILES=$($FIND_STRING -name "*.c")
giuliomoro@64 73 CPP_FILES=$($FIND_STRING -name "*.cpp")
giuliomoro@64 74 ASM_FILES=$($FIND_STRING -name "*.S")
andrewm@58 75
andrewm@58 76 if [[ -z $C_FILES ]] && [[ -z $CPP_FILES ]] && [[ -z $ASM_FILES ]]
andrewm@58 77 then
andrewm@58 78 echo "Please provide a directory containing .c, .cpp or .S files."
andrewm@58 79 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]"
andrewm@58 80 usage
andrewm@58 81 exit
andrewm@58 82 fi
andrewm@58 83
giuliomoro@275 84 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
giuliomoro@266 85 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
giuliomoro@266 86
giuliomoro@369 87 echo "Stopping running process..."
giuliomoro@369 88 # sets the date and stop running process
giuliomoro@369 89 ssh $BBB_ADDRESS "date -s '`date`' > /dev/null; mkdir -p $BBB_PROJECT_FOLDER; make -C $BBB_BELA_HOME stop"
giuliomoro@64 90
giuliomoro@64 91 #concatenate arguments to form path.
giuliomoro@264 92 HOST_SOURCE_PATH= #initially empty, will be filled with input arguments
giuliomoro@64 93 for i in "$@" #parse input arguments
giuliomoro@64 94 do
giuliomoro@275 95 HOST_SOURCE_PATH+=" $1"
giuliomoro@64 96 shift
giuliomoro@64 97 # Copy new souce files to the board
giuliomoro@64 98 done
andrewm@58 99
andrewm@58 100 # Copy new source files to the board
andrewm@58 101 echo "Copying new source files to BeagleBone..."
giuliomoro@264 102 if [ -z `which rsync` ];
giuliomoro@264 103 then
giuliomoro@264 104 #if rsync is not available, brutally clean the destination folder
giuliomoro@264 105 #and copy over all the files again and recompile them
giuliomoro@266 106 ssh bbb "make -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME";
giuliomoro@266 107 scp $HOST_SOURCE_PATH "$BBB_NETWORK_TARGET_FOLDER"
giuliomoro@264 108 else
giuliomoro@369 109 #rsync
giuliomoro@369 110 # --delete makes sure it removes files that are not in the origin folder
giuliomoro@369 111 # -c evaluates changes using md5 checksum instead of file date, so we don't care about time skews
giuliomoro@369 112 # --no-t makes sure file timestamps are not preserved, so that the Makefile will not think that targets are up to date when replacing files on the BBB
giuliomoro@369 113 # with older files from the host. This will solve 99% of the issues with Makefile thinking a target is up to date when it is not.
giuliomoro@369 114 rsync -avc --no-t --delete-after --exclude=build $HOST_SOURCE_PATH"/" "$BBB_NETWORK_TARGET_FOLDER/" #trailing slashes used here make sure rsync does not create another folder inside the target folder
giuliomoro@264 115 fi;
giuliomoro@64 116
giuliomoro@64 117 if [ $? -ne 0 ]
giuliomoro@64 118 then
giuliomoro@64 119 echo "Error while copying files"
giuliomoro@64 120 exit
giuliomoro@64 121 fi
andrewm@58 122
andrewm@58 123 # Make new BeagleRT executable and run
giuliomoro@323 124 MAKE_COMMAND="make -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'"
andrewm@58 125 if [ $RUN_PROJECT -eq 0 ]
andrewm@58 126 then
andrewm@58 127 echo "Building project..."
giuliomoro@323 128 ssh $BBB_ADDRESS "$MAKE_COMMAND"
andrewm@58 129 else
andrewm@58 130 echo "Building and running project..."
andrewm@90 131
andrewm@90 132 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
andrewm@90 133 then
giuliomoro@330 134 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
andrewm@90 135 elif [ $RUN_IN_FOREGROUND -eq 0 ]
andrewm@90 136 then
giuliomoro@323 137 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
andrewm@90 138 else
giuliomoro@323 139 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
andrewm@90 140 fi
giuliomoro@249 141 fi