#!/bin/sh ############################################################################################ # Name : //utils/P4_FullBuild/P4_FullBuild.sh # Purpose : A script to run a full Alvarion software build, Based on perforce system # Date : 17-Mar-2003 # Argumnets : 1 - Full BranchPath, for example //Rainbow/dev/... # i.e. full name started with // and ended with / # Description : Steps: # 0. Definition of local variables, log, temp and auxilary files # 1. Verify that there is no opened files in current client by current user # 2. Get Branch name as argument # 3. Prevent write into selected //Depot/Branch/... # 4. Remove all files on this branch from the clientspec # 5. Remove tree from the filesystem # 6. Sync selected branch to the head revision # 7. Increment counter of version number (and get $VERNUM and $BUILDNUM) and submit updated .h file # 7a. Add Label name to .h file (make writable, change file) # 8. Compilation and build # 8a. Redo Sync file .h (p4 sync -f) # 9. Update product files in production depot # 10. Define and load build label # 11. Update resolved-in-build fields in jobs (external script/program) # 12. Send mail to developers # 13. Send mail to testers # 14. Restore previous settings of "p4 protect" # 15. Remove the temporary files # Requirements : # 1. SUPER user priviledges for the current user. It is necessary for # perform "p4 protect" command # 2. Version file. This file must be in the specified place and with specified name. # Currently this file is <initial_path>include/version.h # 3. Production table file ############################################################################################ # Define log file LOGFILE=//c/p4client_build/Rainbow/p4utils/FullBuild.log echo "FullBuild started at "`/usr/bin/date` echo "FullBuild started at "`/usr/bin/date` > $LOGFILE # # 0. Definition of local variables, log, temp and auxilary files # # Define temp files #TMPFILE=p4temp.$$ TMPFILE=/tmp/p4temp.$$ # Define temp protect file for the "p4 protect" command #PROTECTFILE=p4protect.$$ PROTECTFILE=/tmp/p4protect.$$ # # 1. Verify that not any opened files in current client by current user # if [ "`p4 opened 2> /dev/null`" != "" ] then echo "There are opened files in the current client." echo "You MUST submit or revert all opened files in the your current client" echo "Error: There are opened files in the current client." >> $LOGFILE exit 1 fi # # 2. Get Branch name as argument # FULLPATH=$1 echo "Branch name is "$FULLPATH echo "Branch name is "$FULLPATH >> $LOGFILE # $# is quantity of arguments # $0 is name of the file running (of this script) if [ $# -lt 1 ] then echo "You MUST select a branch in P4WIN before running script $0" echo "Example: //Rainbow/dev/..." echo "Error: Parameter required" >> $LOGFILE # 15pre. Remove the temporary files /usr/bin/rm -f /usr/tmp/*.$$ exit 1 fi # Parse $FULLPATH and getting $DEPOTNAME and $BRANCHNAME # Remove trailing ... (three dots at the end) # Rem by Michael - this command causes error #FULLPATH=`echo $FULLPATH | /usr/bin/sed 's/\.\.\.$//'` # Get $PRJNAME ( in the form Rainbow ) PRJNAME=`echo $FULLPATH | /usr/bin/awk -F/ '{print $3}'` # Check for correct $PRJNAME if [ "$PRJNAME" = "" ] then echo "You MUST select a branch in P4WIN before running script $0" echo "Example: //Rainbow/dev/..." echo "Error: Invalid DEPOTNAME" >> $LOGFILE exit 1 fi # Get $DEPOTNAME ( in the form: //Rainbow/ ) DEPOTNAME="//"$PRJNAME"/" # Get $BRANCHNAME ( in the form dev ) BRANCHNAME=`echo $FULLPATH | /usr/bin/sed 's?'$DEPOTNAME'??' | /usr/bin/sed 's?/\.\.\.??g'` # Check for correct $BRANCHNAME if [ "$BRANCHNAME" = "" ] then echo "You MUST select a branch in P4WIN before running script $0" echo "Example: //Rainbow/dev/..." echo "Error: Invalid BRANCHNAME" >> $LOGFILE exit 1 elif [ "$BRANCHNAME" != "dev" ] then if [ `echo $BRANCHNAME | /usr/bin/awk -F_ '{print NF}'` -gt 1 ] then echo "You MUST select a appropriate branch in P4WIN before running script $0" echo "Example: //Rainbow/dev/ or //Rainbow/int_2/ or //Rainbow/alpha_3.1/ or //Rainbow/rel_1.2/" echo "Error: Invalid BRANCHNAME "$BRANCHNAME >> $LOGFILE exit 1 fi FB=`echo $BRANCHNAME | /usr/bin/awk -F_ '{print $1}'` if [ "$FB" != "int" -a "$FB" != "alpha" -a "$FB" != "rel" ] then echo "You MUST select a appropriate branch in P4WIN before running script $0" echo "Example: //Rainbow/dev/ or //Rainbow/int_2/ or //Rainbow/alpha_3.1/ or //Rainbow/rel_1.2/" echo "Error: Invalid BRANCHNAME "$BRANCHNAME >> $LOGFILE exit 1 fi fi PRODDEPOTPATH="//"$PRJNAME"_products/"$BRANCHNAME"/"$PRJNAME"_products" ### PRODDEPOTPATH="//"$PRJNAME"_products" # Define the version number include file should be set by the specific configuration manager SHORTDEPOTN=`echo $DEPOTNAME | /usr/bin/sed 's?\/??g'` INCDIR=$DEPOTNAME$BRANCHNAME"/"$SHORTDEPOTN"/APPLICATION/PUB" VERFILE=$INCDIR"/ver_au.h" # Check for the file p4 files $VERFILE > /dev/null if [ "$?" != "0" ] then echo "Version Number file "$VERFILE" not found" echo "Error: Version Number "$VERFILE" file not found" >> $LOGFILE exit 1 fi # Define the product files table - source and target sides PRDTABLE=$INCDIR"/prdtable.txt" # Check for the file p4 files $PRDTABLE > /dev/null if [ "$?" != "0" ] then echo "Product files table file "$PRDTABLE" not found" echo "Error: Product files table file "$PRDTABLE" not found" >> $LOGFILE exit 1 fi # # 3. Prevent write into selected //Depot/Branch/... # echo "Set P4 protect to open-only mode" # Save initial condition of "p4 protect" p4 protect -o > $PROTECTFILE #If the previous command was successful then "$?" returns 0, else it returns 1 # 3.1. We need verify that user running this script has a "super" privileges if [ "$?" != "0" ] then echo "" echo "You must have \"SUPER\" privilege in order to run this script" echo "Exit..." echo "" rm -f $PROTECTFILE echo "Error: Unexpected error while running \"p4 protect\" command" >> $LOGFILE exit 1 fi # 3.2. Remove "write" permission and add "open" permission for $FULLPATH. CURUSER=`p4 info | grep "User name:" | awk '{print $3}'` cp $PROTECTFILE $TMPFILE echo " write user * * -"$FULLPATH >> $TMPFILE echo " open user * * "$FULLPATH >> $TMPFILE echo " super user "$CURUSER" * "$FULLPATH >> $TMPFILE /usr/bin/cat $TMPFILE | p4 protect -i # # 4. Remove all files on this branch from the clientspec # echo "Remove all files on the branch "$FULLPATH" from the clientspec" p4 sync $FULLPATH#none > /dev/null # # 5. Remove tree from the filesystem # # First we need to know the working directory LOCALWORKDIR=`p4 where "$FULLPATH"~~~ | /usr/bin/awk -F"~~~" '{print $3}'` # Convert given path from Dos to Unix-like. WORKDIR=`echo $LOCALWORKDIR | /usr/bin/sed 's?\\\?\/?g'` echo "WORKDIR = "$WORKDIR echo "Message: WORKDIR = "$WORKDIR >> $LOGFILE # WARNING! Remove the tree of BRANCHNAME from filesystem (in client spec) echo "Removing working folder "$LOCALWORKDIR" (in UNIX notation: "$WORKDIR")" WDIR=`echo $WORKDIR | /usr/bin/sed 's/\.\.\.//'` /usr/bin/rm -rf $WDIR # # 6. Sync selected branch to the head revision # echo "Copying all files to the local " p4 sync "$FULLPATH"... echo "Copying files of BuildScript to the local " p4 sync //"$PRJNAME"/p4utils/... # # 7. Increment counter of version number (and get $VERNUM and $BUILDNUM) # echo "Increment build number in the version file" p4 edit $VERFILE LOCALVERFILE=`p4 fstat $VERFILE | /usr/bin/grep "^\.\.\. clientFile " | /usr/bin/sed 's/... clientFile //' | /usr/bin/sed 's?\\\?\/?g'` ### /usr/bin/awk -F "." '{print $1 "." $2 "." $3 "." $4+1}' $LOCALVERFILE > $TMPFILE ### mv -f $TMPFILE $LOCALVERFILE FILEN=$LOCALVERFILE VERLINE=`/usr/bin/nl $FILEN | /usr/bin/grep "\#define HOST_VER_NUMBER" | /usr/bin/awk '{print $1}'` VERLINEMINUS1=`/usr/bin/expr $VERLINE - 1` VERLINEPLUS1=`/usr/bin/expr $VERLINE + 1` /usr/bin/head -$VERLINEMINUS1 $FILEN > tmp_ver_au /usr/bin/grep "\#define HOST_VER_NUMBER" $FILEN | /usr/bin/awk '{print $1 " " $2 " " $3+1}' >> tmp_ver_au /usr/bin/tail +$VERLINEPLUS1 $FILEN >> tmp_ver_au /usr/bin/mv tmp_ver_au $FILEN p4 change -o | /usr/bin/sed 's/<enter description here>/Autosubmitted Increment build number in the version file/' | p4 submit -i # 7.2. Get $VERNUMBER and $BUILDNUMBER #VERNUM=`/usr/bin/awk -F "." '{print $1 "." $2 "." $3 }' $LOCALVERFILE` #BUILDNUM=`/usr/bin/awk -F "." '{print $4 }' $LOCALVERFILE` # EXAMPLE: LOCALVERFILE=//c/p4client_build/rainbow/dev/rainbow/APPLICATION/PUB/ver_au.h MAJORNUM=`/usr/bin/cat $LOCALVERFILE | /usr/bin/grep "#define MAJOR_VERSION" | /usr/bin/awk '{print $3}'` MINORNUM=`/usr/bin/cat $LOCALVERFILE | /usr/bin/grep "#define MINOR_VERSION" | /usr/bin/awk '{print $3}'` VERNUM=$MAJORNUM"."$MINORNUM BUILDNUM=`/usr/bin/cat $LOCALVERFILE | /usr/bin/grep "#define HOST_VER_NUMBER" | /usr/bin/awk '{printf $3}'` echo "Version Number is "$VERNUM >> $LOGFILE echo "Build Number is "$BUILDNUM >> $LOGFILE # # 7a. Add Label name to .h file (make writable, change file) # # Define label name # define labelname (example: "Rainbow_dev_1.1.17_build") LABELNAME=$PRJNAME"_"$BRANCHNAME"_"$VERNUM"."$BUILDNUM"_build" FILEN=$LOCALVERFILE ## Copy .h file to temporary /usr/bin/cp $FILEN include_file_tmp.h ## Make file .h writable /usr/bin/chmod +w $FILEN LABELLINE=`/usr/bin/nl $FILEN | /usr/bin/grep "RELEASE_LABEL_NAME" | /usr/bin/awk '{print $1}'` LABELLINEMINUS1=`/usr/bin/expr $LABELLINE - 1` LABELLINEPLUS1=`/usr/bin/expr $LABELLINE + 1` /usr/bin/head -$LABELLINEMINUS1 $FILEN > tmp_label_au echo "LABELNAME="$LABELNAME >> $LOGFILE /usr/bin/grep "Not_a_release_version" $FILEN | /usr/bin/echo "char RELEASE_LABEL_NAME[100]={\""$LABELNAME"\"};" >> tmp_label_au /usr/bin/tail +$LABELLINEPLUS1 $FILEN >> tmp_label_au /usr/bin/mv tmp_label_au $FILEN # # 8. Compilation and build # # <insert your compilation here> echo "Build command will be run now. This may take few minutes." WIND_BASE=c:/\Tornado export WIND_BASE WIND_HOST_TYPE=x86-win32 export WIND_HOST_TYPE PATH=//c/tornado/host/x86-win32/bin:$PATH RUNDIR=`pwd` subst o: /D subst o: C:/\p4client_build/\"$PRJNAME"/\"$BRANCHNAME"/\rainbow subst cd //c/p4client_build/Rainbow/dev/rainbow/Workspaces/MantaEvm/MantaEvmDP_AMD/default/ make -f ../Makefile cd //c/p4client_build/Rainbow/dev/rainbow/Workspaces/MantaEvm/RainbowAU/default/ make -f ../Makefile cd $RUNDIR # Resync .h file (remove information about LabelName from .h file by copying from temp copy of .h) /usr/bin/mv include_file_tmp.h $FILEN chmod -w $FILEN # # 9. Update product files in production depot # WARNING! All filenames in the $PRDTABLE must be without blanks LOCALPRDTABLE=`p4 fstat $PRDTABLE | /usr/bin/grep "^\.\.\. clientFile " | /usr/bin/sed 's/... clientFile //' | /usr/bin/sed 's?\\\?\/?g'` for i in `/usr/bin/cat $LOCALPRDTABLE` do SRCNAME=`echo $i | /usr/bin/awk -F: '{print $1}'` TRGNAME=`echo $i | /usr/bin/awk -F: '{print $2}'` SRCFNAME="//"$PRJNAME"/"$BRANCHNAME"/"$PRJNAME"/"$SRCNAME TRGFNAME=$PRODDEPOTPATH"/"$TRGNAME SRCLNAME=`p4 where $SRCFNAME | /usr/bin/awk '{print $NF}'` # the following line is incorrect if file not exist in P4 # SRCLNAME=`p4 fstat $SRCFNAME | /usr/bin/grep "^\.\.\. clientFile " | /usr/bin/sed 's/... clientFile //' | /usr/bin/sed 's?\\\?\/?g'` if [ ! -f $SRCLNAME ] then echo "" echo $SRCLNAME" does not exist. Build is incomplete !!" echo "" # 14pre. Restore previous settings of "p4 protect" /usr/bin/cat $PROTECTFILE | p4 protect -i # 15pre. Remove the temporary files /usr/bin/rm -f $PROTECTFILE /usr/bin/rm -f $TMPFILE exit 1 fi TRGLNAME=`p4 where $TRGFNAME | /usr/bin/awk '{print $NF}'` # the following line is incorrect if file not exist in P4 # TRGLNAME=`p4 fstat $TRGFNAME | /usr/bin/grep "^\.\.\. clientFile " | /usr/bin/sed 's/... clientFile //' | /usr/bin/sed 's?\\\?\/?g'` echo "TRGLNAME="$TRGLNAME echo "TRGLNAME="$TRGLNAME >> $LOGFILE IS_IN_P4=`p4 files $TRGFNAME | /usr/bin/wc -l | /usr/bin/awk '{print $1}'` if [ "$IS_IN_P4" != "0" ] then p4 sync $TRGFNAME p4 edit $TRGFNAME /usr/bin/cp -f -r $SRCLNAME $TRGLNAME else #If folders where files TRGLNAME will be reside do not exist, then script will not copy product files #So it's necessary to create these folders #Example: c:\p4client_build\Rainbow_products\dev\Rainbow_products\AU TRG=`echo $TRGLNAME | /usr/bin/sed 's?\\\?\/?g' | /usr/bin/sed 's/://'` TRG="//"$TRG #Create Folder mkdir -p `dirname $TRG` #And now... copy /usr/bin/cp -f -r $SRCLNAME $TRGLNAME p4 add $TRGFNAME fi done p4 change -o | /usr/bin/sed 's/<enter description here>/Autosubmitted Copying production files to the products depot/' | p4 submit -i # # 10. Define and load build label # ### WARNING! labelname (example: "Rainbow_dev_1.0.0_ob_build17") was defined above in staep 7a. ### define labelname (example: "Rainbow_dev_1.0.0_ob_build17") ### LABELNAME=$PRJNAME"_"$BRANCHNAME"_"$VERNUM"_ob_build"$BUILDNUM echo "Define and load "$LABELNAME" label" echo "Define and load "$LABELNAME" label" >> $LOGFILE # delete label with same name if exists p4 label -d -f $LABELNAME # create new label p4 label -o $LABELNAME | /usr/bin/grep -v "^ //" > $TMPFILE # The label view is: //Rainbow/dev/... # //Rainbow_products/dev/... echo " //"$PRJNAME"/"$BRANCHNAME"/..." >> $TMPFILE echo " //"$PRJNAME"_products/"$BRANCHNAME"/..." >> $TMPFILE echo " //"$PRJNAME"/p4utils/..." >> $TMPFILE /usr/bin/cat $TMPFILE | p4 label -i # Fill the label with files p4 labelsync -l $LABELNAME > /dev/null # Lock the label p4 label -o $LABELNAME | /usr/bin/sed 's/Options: unlocked/Options: locked/' | p4 label -i # # 11. Update resolved-in-build fields in jobs (external script/program) # Invoke external "resolved-in-build field update" script/program here ### ./rib.sh $BUILDNUM # # 12. Send mail to developers # # From: perforce@direct-solution.com # To: p4 group <project>_developers ### TOADDRESS=$PRJNAME"_developers@direct-solution.com" TOADDRESS="igal.vainzof@alvarion.com" # Subject: <project> <branch> Build <number> is released. Please sync to label $LABELNAME. SUBJECT=$PRJNAME" "$BRANCHNAME" Build "$BUILDNUM" is released. Please sync to label "$LABELNAME MESSAGEBODY="Please pay attention, "$PRJNAME" "$BRANCHNAME" Build "$BUILDNUM" is released. Please perform Sync To Label "$LABELNAME echo "SUBJECT="$SUBJECT echo "MESSAGEBODY="$MESSAGEBODY # Case of FreeWare Sendmail application (Made in Russia) #Get mail template from Perforce p4 sync -f c:/\p4client_build/\Rainbow/\p4utils/\PerforceNotification.eml #make it writable /usr/bin/chmod +w PerforceNotification.eml #Change the content of template echo "SUBJECT="$SUBJECT echo "MESSAGEBODY="$MESSAGEBODY /usr/bin/cat Perforcenotification.eml | /usr/bin/sed 's/THIS_IS_THE_SUBJECT_TEMPLATE/'"$SUBJECT"'/' | /usr/bin/sed 's/THIS_IS_THE_MESSAGE_BODY_TEMPLATE/'"$MESSAGEBODY"'/' > PerforcenotificationTMP.eml #usr/bin/sed 's/THIS_IS_THE_MESSAGE_BODY_TEMPLATE/'"$MESSAGEBODY"'/' PerforcenotificationTMP.eml | > PerforcenotificationTMP.eml #/usr/bin/cat PerforcenotificationTMP.eml echo "Sending notification to Developers" >> $LOGFILE #Send mail ./sendmail LIGHT2 $TOADDRESS FullBuild.log # # 13. Send mail to testers # # From: perforce@direct-solution.com # To: p4 group <project>_testers ## TOADDRESS=$PRJNAME"_testers@direct-solution.com" # Subject: <project> <branch> Build <number> is released. SUBJECT=$PRJNAME" "$BRANCHNAME" Build "$BUILDNUM" is released." # Working folder of Rainbow_product #MYCLIENT=`p4 client -o | /usr/bin/grep -v "# Client:" | /usr/bin/grep Client: | /usr/bin/awk '{print $2}'` #MYPATH=`p4 client -o | /usr/bin/grep Rainbow_products | /usr/bin/awk '{print $2}'` #MYROOT=`p4 client -o | /usr/bin/grep -v "# Root:" | /usr/bin/grep Root: | /usr/bin/awk '{print $2}'` #echo "MYCLIENT="$MYCLIENT #echo "MYPATH="$MYPATH #echo "MYROOT="$MYROOT #PRDDIR=`echo $MYROOT$MYPATH | /usr/bin/sed 's/'"$MYCLIENT"'//' | /usr/bin/sed 's?///??' | /usr/bin/sed 's?/?\\\?g' | /usr/bin/sed 's/\.\.\.//'` #echo "PRDDIR="$PRDDIR MESSAGEBODY="Please copy product files from its current location to your test environment" echo "SUBJECT="$SUBJECT echo "MESSAGEBODY="$MESSAGEBODY # Case of FreeWare Sendmail application #Get mail template from Perforce p4 sync -f c:/\p4client_build/\Rainbow/\p4utils/\PerforceNotification.eml #make it writable /usr/bin/chmod +w PerforceNotification.eml #Change the content of template echo "SUBJECT="$SUBJECT echo "MESSAGEBODY="$MESSAGEBODY /usr/bin/cat Perforcenotification.eml | /usr/bin/sed 's/THIS_IS_THE_SUBJECT_TEMPLATE/'"$SUBJECT"'/' | /usr/bin/sed 's/THIS_IS_THE_MESSAGE_BODY_TEMPLATE/'"$MESSAGEBODY"'/' > PerforcenotificationTMP.eml echo "Sending notification to TESTERS" >> $LOGFILE #Send mail ./sendmail LIGHT2 $TOADDRESS FullBuild.log # # 14. Restore previous settings of "p4 protect" # /usr/bin/cat $PROTECTFILE | p4 protect -i # # 15. Remove the temporary files # /usr/bin/rm -f $PROTECTFILE /usr/bin/rm -f $TMPFILE exit 0 # *******************************************************
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 4639 | Ilya Rokhkin |
By Ilya Full build script of Alvarion |