comparison scripts/build_project.sh @ 284:7bfb25a2e158 Doxy prerelease

Merge
author Robert Jack <robert.h.jack@gmail.com>
date Tue, 17 May 2016 15:53:24 +0100
parents 156191dffa8c
children 428f13c2cb49
comparison
equal deleted inserted replaced
269:ac8eb07afcf5 284:7bfb25a2e158
2 # 2 #
3 # This script compiles a BeagleRT project on the BeagleBone Black and 3 # This script compiles a BeagleRT project on the BeagleBone Black and
4 # optionally runs it. Pass a directory path in the first argument. 4 # optionally runs it. Pass a directory path in the first argument.
5 # The source files in this directory are copied to the board and compiled. 5 # The source files in this directory are copied to the board and compiled.
6 6
7 BBB_ADDRESS="root@192.168.7.2" 7 # set defaults unless variables are already set
8 BBB_PATH="~/BeagleRT" 8 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
9 RUN_PROJECT=1 9 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/BeagleRT/"
10 COMMAND_ARGS= 10 [ -z "$BBB_SCREEN_NAME" ] && BBB_SCREEN_NAME="BeagleRT"
11 RUN_IN_FOREGROUND=0 11 [ -z "$RUN_PROJECT" ] && RUN_PROJECT=1
12 RUN_WITHOUT_SCREEN=0 12 [ -z "$COMMAND_ARGS" ] && COMMAND_ARGS=
13 [ -z "$RUN_IN_FOREGROUND" ] && RUN_IN_FOREGROUND=1
14 [ -z "$RUN_WITHOUT_SCREEN" ] && RUN_WITHOUT_SCREEN=0
15 [ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/"
16 [ -z "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME="scriptUploadedProject"
13 17
14 function usage 18 function usage
15 { 19 {
16 THIS_SCRIPT=`basename "$0"` 20 THIS_SCRIPT=`basename "$0"`
17 echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-nfF] <directory-with-source-files>" 21 echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-nfF] <directory-with-source-files>"
24 If the argument -n is passed, the output will not be run after compiling. 28 If the argument -n is passed, the output will not be run after compiling.
25 The argument -b will change the local path on the BeagleBone where the 29 The argument -b will change the local path on the BeagleBone where the
26 BeagleRT files are found. The -c option passes command-line arguments to 30 BeagleRT files are found. The -c option passes command-line arguments to
27 the BeagleRT program; enclose the argument string in quotes. 31 the BeagleRT program; enclose the argument string in quotes.
28 32
29 The -f argument runs the project in the foreground of the current terminal, 33 By default, the project runs in the foreground of the current terminal,
30 within a screen session that can be detached later. The -F argument runs 34 within a screen session that can be detached later. The -F argument runs
31 the project in the foreground of the current terminal, without screen, so 35 the project in the foreground of the current terminal, without screen, so
32 the output can be piped to another destination." 36 the output can be piped to another destination. The -f argument runs it
37 in a screen in the background, so no output is shown."
33 } 38 }
34 39
35 OPTIND=1 40 OPTIND=1
36 41
37 while getopts "b:c:nfFh" opt; do 42 while getopts "b:c:nfFh" opt; do
38 case $opt in 43 case $opt in
39 b) BBB_PATH=$OPTARG 44 b) BBB_BELA_HOME=$OPTARG
40 ;; 45 ;;
41 c) COMMAND_ARGS=$OPTARG 46 c) COMMAND_ARGS=$OPTARG
42 ;; 47 ;;
43 f) RUN_IN_FOREGROUND=1 48 f) RUN_IN_FOREGROUND=0
44 ;; 49 ;;
45 F) RUN_WITHOUT_SCREEN=1 50 F) RUN_WITHOUT_SCREEN=1
46 ;; 51 ;;
47 n) RUN_PROJECT=0 52 n) RUN_PROJECT=0
48 ;; 53 ;;
49 h|\?) usage 54 h|\?) usage
50 exit 1 55 exit 1
74 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]" 79 # echo "Usage: $THIS_SCRIPT [directory-with-source-files]"
75 usage 80 usage
76 exit 81 exit
77 fi 82 fi
78 83
84 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME"/"
85 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
86
79 # Stop BeagleRT and clean out old source files 87 # Stop BeagleRT and clean out old source files
80 echo "Stopping BeagleRT and removing old source files..." 88 echo "Stopping running program..."
81 ssh -t -t $BBB_ADDRESS "screen -X -S BeagleRT quit &>/dev/null; pkill BeagleRT ; make sourceclean -C $BBB_PATH" 89 # sets the date, stops the running process
90 ssh $BBB_ADDRESS "date -s '`date`' > /dev/null; mkdir -p $BBB_PROJECT_FOLDER; screen -X -S '"$BBB_SCREEN_NAME"' quit &>/dev/null;"
82 91
83 #concatenate arguments to form path. 92 #concatenate arguments to form path.
84 BBB_SOURCE_PATH= #initially empty, will be filled with input arguments 93 HOST_SOURCE_PATH= #initially empty, will be filled with input arguments
85 for i in "$@" #parse input arguments 94 for i in "$@" #parse input arguments
86 do 95 do
87 if [ -d "$1" ] #check if the path is a folder 96 HOST_SOURCE_PATH+=" $1 "
88 then #if it is, include all of its files
89 BBB_SOURCE_PATH+=" ${1}/* "
90 else
91 BBB_SOURCE_PATH+=" $1 "
92 fi
93 shift 97 shift
94 # Copy new souce files to the board 98 # Copy new souce files to the board
95 done 99 done
96 100
97 # Copy new source files to the board 101 # Copy new source files to the board
98 echo "Copying new source files to BeagleBone..." 102 echo "Copying new source files to BeagleBone..."
99 scp $BBB_SOURCE_PATH "$BBB_ADDRESS:$BBB_PATH/source/" 103 if [ -z `which rsync` ];
104 then
105 #if rsync is not available, brutally clean the destination folder
106 #and copy over all the files again and recompile them
107 ssh bbb "make -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME";
108 scp $HOST_SOURCE_PATH "$BBB_NETWORK_TARGET_FOLDER"
109 else
110 #rsync --delete makes sure it removes files that are not in the origin folder
111 rsync -av --delete-after --exclude=build $HOST_SOURCE_PATH "$BBB_NETWORK_TARGET_FOLDER"
112 fi;
100 113
101 if [ $? -ne 0 ] 114 if [ $? -ne 0 ]
102 then 115 then
103 echo "Error while copying files" 116 echo "Error while copying files"
104 exit 117 exit
106 119
107 # Make new BeagleRT executable and run 120 # Make new BeagleRT executable and run
108 if [ $RUN_PROJECT -eq 0 ] 121 if [ $RUN_PROJECT -eq 0 ]
109 then 122 then
110 echo "Building project..." 123 echo "Building project..."
111 ssh $BBB_ADDRESS "make all -C $BBB_PATH" 124 ssh $BBB_ADDRESS "make all -C $BBB_BELA_HOME PROJECT=$BBB_PROJECT_NAME"
112 else 125 else
113 echo "Building and running project..." 126 echo "Building and running project..."
114 127
115 if [ $RUN_WITHOUT_SCREEN -ne 0 ] 128 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
116 then 129 then
117 ssh -t $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && ../BeagleRT $COMMAND_ARGS" 130 ssh -t $BBB_ADDRESS "cd $BBB_BELA_HOME && make all && cd source && $BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME $COMMAND_ARGS"
118 elif [ $RUN_IN_FOREGROUND -eq 0 ] 131 elif [ $RUN_IN_FOREGROUND -eq 0 ]
119 then 132 then
120 ssh $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && screen -S BeagleRT -d -m ../BeagleRT $COMMAND_ARGS" 133 ssh $BBB_ADDRESS "cd $BBB_BELA_HOME && make all PROJECT=$BBB_PROJECT_NAME && cd source && screen -S $BBB_SCREEN_NAME -d -m $BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME $COMMAND_ARGS"
121 else 134 else
122 ssh -t $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && screen -S BeagleRT ../BeagleRT $COMMAND_ARGS" 135 ssh -t $BBB_ADDRESS "cd $BBB_BELA_HOME && make all PROJECT=$BBB_PROJECT_NAME && cd source && screen -S $BBB_SCREEN_NAME $BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME $COMMAND_ARGS"
123 fi 136 fi
124 fi 137 fi