#!/bin/bash # $./run.build.sh release 5.12.5 /media/sf_VMSHARE #setup Qt dir version if [[ "$2" = "" ]]; then QT_VER="5.15.10" POKY_VER="3.1.18" else QT_VER=$2 POKY_VER=$3 fi REMOTE_REPO_BASE_ADDRESS="ssh://git@devapps.diality.us:7999/" # If the support scripts repository does not exist, clone it if [[ ! -d "supportscript" ]] then git clone "$REMOTE_REPO_BASE_ADDRESS"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" # TODO uncomment once Qt bug was fixed. Keyboard layout fails to load pro_build=$pro_release # Build specs PROJECT_NAME_INDEX=0 PROJECT_CHECKOUT_INDEX=8 COMMON_CHECKOUT_INDEX=9 BUILD_ONLY_FLAG_INDEX=10 DEVELOP_BRANCH_NAME="develop" REPORT=Report out_path="build" isBuildLocal=false # Test pass/fail flag hasTestPassed=true # shellcheck disable=SC2068 setBuildVariables ${buildSpecs[@]} # Retrieve the status report REMOTE_DIR=$(getRemoteCopyAddress "DEN_UI" ${buildSpecs[$PROJECT_CHECKOUT_INDEX]}) fileName=$(find $REMOTE_DIR -maxdepth 1 -name \*"Build_Report"\*.csv) STATUS_REPORT=$fileName # Get the build variables buildVariables=($(getUIBuildValues)) export majorVersion=${buildVariables[0]} export minorVersion=${buildVariables[1]} export microVersion=${buildVariables[2]} export buildNumber=${buildVariables[3]} # gcc env gcc_qmake="/opt/Qt$QT_VER/$QT_VER/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/$POKY_VER/sysroots/x86_64-pokysdk-linux/usr/bin/qmake" poky_make="/opt/b2qt/$POKY_VER/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++" #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 " ------------------------------ RELEASE BUILD" fi echo } function getManualCases() { # If this is a build only, there is no need to get the manual cases if [[ ${buildSpecs[$BUILD_ONLY_FLAG_INDEX]} == true ]] then return 0 fi currentDir=$(pwd) # Create a temporary folder manualCasesFolder=tempManualCases mkdir $manualCasesFolder cd $manualCasesFolder # Clone the application just for checking the manual cases git clone "$REMOTE_REPO_BASE_ADDRESS"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 up the project" git clone "$REMOTE_REPO_BASE_ADDRESS"bl/setupscript.git ./setupscript/projectsetup.sh "${buildSpecs[$PROJECT_NAME_INDEX]}" "${buildSpecs[$PROJECT_CHECKOUT_INDEX]}" \ "${buildSpecs[$COMMON_CHECKOUT_INDEX]}" cd application cppCheckStatus=$(runCppcheck $(pwd) $REMOTE_DIR $STATUS_REPORT) if [[ $cppCheckStatus -eq 1 ]] then hasTestPassed=false fi cd .. currentDir=$(pwd) scripts/build/alarmMapping common/common/ application/sources/model/hd/alarm/ cd application # For good measures add email and user name all the time git config --global user.email "dnavaei@diality.com" git config --global user.name "Dara Navaei" git add sources/model/hd/alarm/MAlarmMapping.cpp git commit -m "Bamboo Commit: Updated MAlarmMapping.cpp" git push origin cd $currentDir cp scripts/build/AlarmMapping.csv "$REMOTE_DIR" cd scripts/build rm -rf Alarms.xlsx cp -r /media/Denali06Alarms/Alarms.xlsx "$(pwd)" git commit -avm "Bamboo Commit: Copied Alarms table from Alarms folder" git push echo "Current Dir $(pwd)" python3 ./alarmMapping.py Alarms.xlsx ../../ui.config/Alarms/Alarms.conf cd $currentDir/ui.config git commit -avm "Bamboo Commit: Updated Alarms.conf" git push cd "$currentDir" echo "Current Dir $(pwd)" #cd .. #cd application # Open up the status report and parse for the word Failed. 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 test has passed or if develop branch is being built, compile. The develop branch does not have to # necessarily pass all the tests to be compiled if [[ $hasTestPassed == true ]] || [[ ${buildSpecs[$PROJECT_CHECKOUT_INDEX]} == $DEVELOP_BRANCH_NAME ]] then echo " ------------------------------ set the build type (debug/release)" buildType "$1" cd $out_path # ============================================================= 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 # Check for errors if [[ $(grep "error:" $build_err) != "" ]] then echo "ERROR: Application Build Failed [$gcc_out]" echo "Build GCC v9.3.0, Failed, $gcc_out" >> "$STATUS_REPORT" hasTestPassed=false else # Build passed so tag the build tagUIRepository "${buildSpecs[$PROJECT_CHECKOUT_INDEX]}" "${buildSpecs[$COMMON_CHECKOUT_INDEX]}" "$STATUS_REPORT" echo "Build GCC v9.3.0, Passed" >> "$STATUS_REPORT" # Add the sha256sum build now sha256sum -b --tag denali >> denali fi # Check for warnings if [[ $(grep "warning:" $build_err) != "" ]] then echo "WARNING: Application Build Has Warnings [$gcc_out]" echo "Application build warnings:, $gcc_out" >> $STATUS_REPORT fi 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]" echo "Build Poky v9.3.0, Failed, $poky_out" >> $STATUS_REPORT hasTestPassed=false else echo "Build Poky v9.3.0, Passed" >> $STATUS_REPORT # Add the shasum256 sha256sum -b --tag denali >> denali fi if [[ $(grep "warning:" $build_err) != "" ]] then echo "WARNING: Application Build Has Warnings [$poky_out]" echo "Application build warnings:, $poky_out" >> $STATUS_REPORT fi echo "" >> $STATUS_REPORT # ============================================================= #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 .. ./scripts/build/create_update_folder.sh "$REMOTE_DIR" "${buildSpecs[$PROJECT_CHECKOUT_INDEX]}" # Copy the build logs the remote address regardless of the build results LOG="Build_Logs" mkdir -p $REMOTE_DIR/$REPORT_DIR/$LOG cp $out_path/* $REMOTE_DIR/$REPORT_DIR/$LOG mkdir -p $REMOTE_DIR/$REPORT_DIR/$LOG cp $out_path/* $REMOTE_DIR/$REPORT_DIR/$LOG # Check if the builds passed. If they did, copy the build folder. if [[ $hasTestPassed == true ]] then echo " ------------------------------ copy the out file into the server" echo " ------------------------------ $poky_out" 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/bin/$gcc_out cp $out_path/$gcc_out/denali $REMOTE_DIR/$REPORT_DIR/bin/$gcc_out sync;sync;sync; fi fi # To report what cases have been tested manually #getManualCases # Generate code reviews # Leave the sub workspace cd .. if [[ ! -d "reportscripts" ]] then rm -rf "reportscripts" fi git clone "$REMOTE_REPO_BASE_ADDRESS"bl/reportscripts.git # If this is a build only build, it is informal and it does not need code review report if [[ ${buildSpecs[$BUILD_ONLY_FLAG_INDEX]} == false ]] then # Generate code review project getCodeReviewReport "$(pwd)" "UI" "${buildSpecs[$PROJECT_CHECKOUT_INDEX]}" "${buildSpecs[$COMMON_CHECKOUT_INDEX]}" \ "$REMOTE_DIR" fi # Get the diff report getCodeDiffReport "$(pwd)" "UI" "${buildSpecs[$PROJECT_CHECKOUT_INDEX]}" "$REMOTE_DIR" # Get the release notes getReleaseNotesFromTheLastBuild "UI" "$(pwd)" "${buildSpecs[$PROJECT_CHECKOUT_INDEX]}" "$REMOTE_DIR" getCommitHashes "" "" "" "" "" "" "1" # Mark pass/fail to the build folder markRemoteFolderWithPassFail $hasTestPassed "$REMOTE_DIR" "UI"