#!/bin/bash # $./run.build.sh release 5.12.5 /media/sf_VMSHARE #setup Qt dir version if [[ "$2" = "" ]]; then QT_VER="" else QT_VER=$2 fi # Get supportscript folder if [[ ! -d "supportscript" ]] then git clone ssh://git@dvm-linux02:7999/bl/supportscript.git fi source ./supportscript/supportscript.sh #setup environment if [[ "$DEVICE_IP" = "" ]]; then device=root@192.168.10.135 DEVICE_IP=192.168.10.135 else device=root@$DEVICE_IP fi # project pro file pro_path=application pro_name=denali.pro pro_type_debug="debug" pro_type_release="release" pro_type=$pro_type_release pro_debug="CONFIG+=debug CONFIG+=qml_debug" pro_release="CONFIG+=qtquickcompiler" pro_build=$pro_release # Build specs out_path="build" setBuildVariables ${buildSpecs[@]} REMOTE_DIR=$(getRemoteCopyAddress "DEN_UI") STATUS_REPORT=$REMOTE_DIR/"StatusReport.csv" REPORT=Report # Get the build variables buildVariables=($(getUIBuildValues)) export majorVersion=${buildVariables[0]} export minorVersion=${buildVariables[1]} export buildNumber=${buildVariables[2]} # Call this function to check # if the repository has to be tagged or not tagUIRepository # gcc env gcc_qmake="/opt/Qt$QT_VER/5.12.5/gcc_64/bin/qmake" gcc_make="/usr/bin/make" gcc_out_base="gcc_64" gcc_out=$gcc_out_base"_"$pro_type gcc_spec="-spec linux-g++" # poky env poky_qmake="/opt/b2qt/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/qmake" poky_make="/opt/b2qt/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/make" poky_out_base="poky_64" poky_out=$poky_out_base"_"$pro_type poky_spec="-spec devices/linux-oe-generic-g++" # Test pass/fail flag hasTestPassed=true #build type detection and set function (debug/release) function buildType() { echo if [[ "$1" = "debug" ]]; then pro_build=$pro_debug pro_type=$pro_type_debug gcc_out=$gcc_out_base"_"$pro_type poky_out=$poky_out_base"_"$pro_type echo " ------------------------------ DEBUG BUILD" else echo " ------------------------------ RELASE BUILD" fi echo } function getManualCases() { currentDir=$(pwd) # Create a temporary folder manualCasesFolder=tempManualCases mkdir $manualCasesFolder cd $manualCasesFolder # Clone the application just for checking the manual cases git clone ssh://git@dvm-linux02:7999/ui/application.git cd application # Declare and associatvie array declare -A listOfFiles # List all the files and replace any space in the name of the files with _ # If there is any space in the name of the files, it is confused with multiple file names find . -depth -name '* *' | while IFS= read -r f ; do mv -i \ "$f" "$(dirname "$f")/$(basename "$f"|tr ' ' _)" ; done # Find all the files in the application folder (recursively) # and put it in a an array allFiles=($(find . -type f)) for i in ${allFiles[@]} do # In the files, look for the term "coco begin validated" and get its line number data=$(cat $i | awk '/coco begin validated:/ { print NR }') # If anything was found if [[ ! -z $data ]] then # Insert it in the associative array with key=filename, element=array of line numbers # i.e. allFiles[./source/guiThread.cpp]=[12 34 56 123 456] listOfFiles[$i]=${data[@]} fi done # Adding title to this section of the status report echo "File, Line Number, Function" >> $STATUS_REPORT # In the function names, there might be , so the csv file separate them. In the code, # those commas are replaced with - to prevent that echo " "," ", "NOTE: In the manual cases commas were replaced with" \ "- to ensure they will not be separated in a csv file" >> $STATUS_REPORT # Loop through the list of the files for file in ${!listOfFiles[@]} do previousLine=1 # For each file, loop through the list of the line numbers for line in ${listOfFiles[$file]} do # From previous line number to the current line number, search for "{" and get its line number in a list # This is done in a range, for instance, if the list of the lines that contain "coco begin validated" in a file # is [12, 24, 56], the scan will be from previous to the current line. previousLine starts from 1 # In the list of the line numbers that contain "{", only the last item is needed since it is closest to the current # line number. localLine=($(cat $file | awk "NR==$previousLine, NR==$line" | awk '/{/ {print NR}')) # The line numbers that are found are offset from the start line that has been provided in the awk command # Also, the screen starts from one line after so the line calculation is subtracted by 1 # So the line that contains "{" from the beginning of the file is calculated below line=$(( $previousLine + ${localLine[-1]} - 1 )) # Go to the calculated line number, look for "{", separate the "{" from the rest, print the first column, and # remove all the unseen characters manualCase=$(cat $file | awk "NR==$line" | awk '/{/' | awk -F"{" '{print $1}' | tr -cd '[:alnum:]._-') # If there was nothing in the line (i.e { ) so there is nothing else if [[ -z $manualCase ]] then # Go another line above: # void test () #{ line=$(( $line - 1 )) # Get the value of the line manualCase=$(cat $file | awk "NR==$line" | awk '{print}') fi # Some of the functions might have multiple arguments that are comma separated, # therefore, the csv file puts them into the other column. The commas in the functions # are replaced with - to prevent that # i.e void test(QString &a, bool b) -> void test(QString &a - bool b) manualCase=$(echo $manualCase | sed "s/,/ -/") # Write the values to the statu report echo $file, $line, $manualCase >> $STATUS_REPORT # Set the current line as the previous line and get ready for the next check previousLine=$line done done echo "", "", "" >> $STATUS_REPORT cd $currentDir rm -rf $manualCasesFolder } #check if the out folders already exists if [[ -e $out_path ]]; then rm -frd $out_path fi echo " ------------------------------ create the build folder" mkdir $out_path if [[ -e $pro_path ]]; then rm -frd $pro_path fi if [[ "$1" = "clean" ]]; then exit 0 fi echo " ------------------------------Setting upt the project" git clone ssh://git@dvm-linux02:7999/bl/setupscript.git ./setupscript/projectsetup.sh "ui" cd application echo " ------------------------------ run the cppcheck" cppCheckStatus=$(runCppcheck $(pwd) $REMOTE_DIR $STATUS_REPORT) if [[ $cppCheckStatus -eq 1 ]] then hasTestPassed=false fi #./cppcheck.sh ../$out_path/ #TODO remove cd .. # Open up the status report and parse for the word Faild. This is # for the unit test and integration tests that are executed at another # script. The results will be used to mark the build folder as passed or failed # NOTE: find for Failed before adding the manual cases since there might be a # function containing the name Failed in it failedCases=$(cat $STATUS_REPORT | grep "Failed") if [[ ! -z $failedCases ]] then hasTestPassed=false fi if [[ $hasTestPassed == true ]] then echo " ------------------------------ set the build type (debug/release)" buildType "$1" cd $out_path # TODO remove #echo " ------------------------------ run the cppcheck diff" #app_path=../$pro_path #diff $app_path/cppcheck.log cppcheck.log 1> cppcheck.logdiff.log 2> cppcheck.logdiff.err #diff $app_path/cppcheck.err cppcheck.err 1> cppcheck.errdiff.log 2> cppcheck.errdiff.err # TODO remove # ============================================================= echo " ------------------------------ Start building [$gcc_out]" mkdir -p $gcc_out cd $gcc_out echo " ------------------------------ run qmake" $gcc_qmake ../../$pro_path/$pro_name $gcc_spec $pro_build echo " ------------------------------ run make" build_err=../build_$gcc_out.err build_log=../build_$gcc_out.log $gcc_make -j4 1> $build_log 2> $build_err if [[ $(grep "error:" $build_err) != "" ]]; then echo "ERROR: Application Build Failed [$gcc_out]" echo "Build, Failed, $gcc_out" >> $STATUS_REPORT hasTestPassed=false exit 2 else echo "Build, Passed" >> $STATUS_REPORT fi if [[ $(grep "warning:" $build_err) != "" ]]; then echo "WARNING: Application Build Has Warnings [$gcc_out]" echo "Application build warnings:, $gcc_out" >> $STATUS_REPORT #exit 3 fi echo "" >> $STATUS_REPORT cd .. # ============================================================= echo " ------------------------------ Start building [$poky_out]" mkdir -p $poky_out cd $poky_out echo " ------------------------------ run qmake" $poky_qmake ../../$pro_path/$pro_name $poky_spec $pro_build echo " ------------------------------ run make" build_err=../build_$poky_out.err build_log=../build_$poky_out.log $poky_make -j4 1> $build_log 2> $build_err if [[ $(grep "error:" $build_err) != "" ]]; then echo "ERROR: Application Build Failed [$poky_out]" exit 2 fi if [[ $(grep "warning:" $build_err) != "" ]]; then echo "WARNING: Application Build Has Warnings [$poky_out]" #exit 3 fi # ============================================================= echo " ------------------------------ stop denali on device [$DEVICE_IP]" ssh $device 'killall denali' sleep 1 echo " ------------------------------ copy denali on device [$DEVICE_IP]" scp ./denali $device://home/root/ sync;sync;sync; sleep 1 echo " ------------------------------ start denali on device[$DEVICE_IP]" ssh -f $device '/home/root/denali' 1>/dev/null 2>/dev/null #return back to out path cd .. #return back to main folder cd .. echo " ------------------------------ copy the out file into the server" LOG=Logs echo " ------------------------------ $poky_out" mkdir -p $REMOTE_DIR/$REPORT_DIR/$LOG cp $out_path/* $REMOTE_DIR/$REPORT_DIR/$LOG mkdir -p $REMOTE_DIR/$REPORT_DIR/bin/$poky_out cp $out_path/$poky_out/denali $REMOTE_DIR/$REPORT_DIR/bin/$poky_out sync;sync;sync; echo " ------------------------------ $gcc_out" mkdir -p $REMOTE_DIR/$REPORT_DIR/$LOG cp $out_path/* $REMOTE_DIR/$REPORT_DIR/$LOG mkdir -p $REMOTE_DIR/$REPORT_DIR/bin/$gcc_out cp $out_path/$gcc_out/denali $REMOTE_DIR/$REPORT_DIR/bin/$gcc_out sync;sync;sync; fi getManualCases # Generate code reviews # Leave the sub workspace cd .. # Delete all the previous excel files rm -rf *.xlsx # If the scripts are already there, remove them if [[ -d cruciblerestapiscript ]] || [[ -d codereviewscript ]] then rm -rf cruciblerestapiscript rm -rf codereviewscript fi # Generate code review project getCodeReviewReport "UI" $REMOTE_DIR # Mark pass/fail to the build folder markRemoteFolderWithPassFail $hasTestPassed $REMOTE_DIR