File indexing completed on 2024-11-24 05:05:59
0001 #!/bin/bash 0002 0003 # Variables 0004 bold=$(tput bold) 0005 normal=$(tput sgr0) 0006 scriptpath="$( cd "$(dirname "$0")" || exit; pwd -P )" 0007 projectpath=${scriptpath}/../.. 0008 buildfolder=${projectpath}/build/lvt 0009 externaldepsfolder=${buildfolder}/externaldeps 0010 outdir=/tmp 0011 scriptname=$(basename "$0") 0012 verboseoutput="/tmp/compile_output.txt" 0013 echopid=0 0014 help=false 0015 0016 terminate() { 0017 if ((echopid != 0)); then 0018 kill ${echopid} 0019 fi 0020 } 0021 0022 trap "terminate" SIGINT 0023 0024 # Functions 0025 echob() { 0026 echo "${bold}${1}${normal}" 0027 } 0028 0029 printfb() { 0030 printf "%s%s%s" "${bold}" "${1}" "${normal}" 0031 } 0032 0033 error() { 0034 echo -e "ERROR: $*" >&2 0035 exit 1 0036 } 0037 0038 usage() { 0039 echo "USAGE: ${scriptname} --no-deploy, --debug, --outdir DIR, --help" 0040 } 0041 0042 checktool() { 0043 name="" 0044 errormsg="" 0045 if (( $# > 1 )); then 0046 name=$2 0047 if (( $# >= 3 )); then 0048 errormsg=$3 0049 fi 0050 else 0051 name=( "${1}" ) 0052 fi 0053 0054 # shellcheck disable=SC2128 0055 printfb "${name}: " 0056 eval "$1" >> $verboseoutput 2>&1 0057 0058 # shellcheck disable=SC2181 0059 [ $? == 0 ] || { 0060 echob "✖" 0061 cat $verboseoutput 0062 error "${name[0]} is not available. ${errormsg}" 0063 } 0064 echob "✔" 0065 } 0066 0067 runstep() { 0068 runstep_name=$1 0069 okmessage=$2 0070 errormsg=$3 0071 printfb "${okmessage}: " 0072 0073 # This prints a '.' while the command is evaluated 0074 sh -c "while sleep 1; do printf '.'; done;" & 0075 echopid=$! 0076 eval "$1" >>$verboseoutput 2>&1 0077 returncode=$? 0078 kill $echopid 0079 echopid=0 0080 [ $returncode == 0 ] || { 0081 echob "✖" 0082 cat $verboseoutput 0083 error "${runstep_name} failed. ${errormsg}" 0084 } 0085 echob "✔" 0086 } 0087 0088 # Check for args 0089 while [ "$1" != "" ] 0090 do 0091 case $1 in 0092 --outdir) 0093 shift 0094 outdir="$1" 0095 shift ;; 0096 0097 --buildfolder) 0098 shift 0099 buildfolder="$1" 0100 shift ;; 0101 0102 --externaldepsfolder) 0103 shift 0104 externaldepsfolder="$1" 0105 shift ;; 0106 0107 --help|-h) 0108 help=true 0109 shift ;; 0110 0111 *) 0112 error "Unknow argument: $1" 0113 ;; 0114 esac 0115 done 0116 0117 if $help; then 0118 usage 0119 exit 1 0120 fi 0121 0122 linuxclideployfiles=( 0123 "${buildfolder}/lvtclp/create_codebase_db" 0124 "${buildfolder}/lvtprj/create_prj_from_db" 0125 "${buildfolder}/lvtclp/lvtclp_merge_databases" 0126 "${buildfolder}/lvtclp/liblvtclp.so" 0127 "${buildfolder}/lvtmdb/liblvtmdb.so" 0128 "${buildfolder}/lvtprj/liblvtprj.so" 0129 "${buildfolder}/lvtshr/liblvtshr.so" 0130 "${buildfolder}/lvtplg/liblvtplg.so" 0131 ) 0132 0133 unameout="$(uname -s)" 0134 case "$unameout" in 0135 Linux*) machine="Linux 🐧";; 0136 *) machine="UNKNOWN:${unameout}" 0137 esac 0138 0139 if [[ $machine != *"Linux"* ]]; then 0140 error "Machine not compatible: ${machine}" 0141 fi; 0142 0143 echo "" 0144 echob "Start to deploy project.." 0145 0146 deployclifolder="${outdir}/cli" 0147 mkdir -p "${deployclifolder}" 0148 for i in "${linuxclideployfiles[@]}"; do 0149 runstep "cp ${i} ${deployclifolder}" "Move file to deploy CLI folder ""${i}" "Failed to deploy file for CLI: ""${i}" 0150 done 0151 runstep "cp ""${externaldepsfolder}/*"" ${deployclifolder}" "Move external dependency files to deploy CLI folder" "Failed to move external dependency files to deploy CLI folder" 0152 tar -czvf codevis-cli.tar.gz -C "${deployclifolder}" . 0153 runstep "mv codevis-cli.tar.gz ${outdir}/codevis-cli.tar.gz" "Move CLI artifact to ${outdir}" "Faile to move CLI artifact to ${outdir}" 0154 0155 echo "#############################################" 0156 echo "## ONLY DISTRIBUTE IMAGES BUILT VIA DOCKER ##" 0157 echo "#############################################"