diff --git a/coverage-tool/coverage-reporting/merge.sh b/coverage-tool/coverage-reporting/merge.sh index e0ec69cdcc05b88c262879f8434c5ea6360d0872..635b1f20a4c6f566858a95616bd7a0807f88e80b 100755 --- a/coverage-tool/coverage-reporting/merge.sh +++ b/coverage-tool/coverage-reporting/merge.sh @@ -12,8 +12,7 @@ # DESCRIPTION: Wrapper to merge intermediate json files and LCOV trace .info # files. #============================================================================== - -set +x +set -x ################################################################# # Function to manipulate json objects. # The json object properties can be accessed through "." separated @@ -159,8 +158,7 @@ get_file() { if [ "$_type" = '"http"' ];then fname="$where.$extension" # Same filename as folder rm $where/$fname &>/dev/null || true - wget -o error.log $_origin -O $where/$fname || ( - cat error.log && exit -1) + wget -nv $_origin -O $where/$fname || return -1 cloned_file="$(get_abs_path $where/$fname)" elif [ "$_type" = '"bundle"' ];then # Check file exists at origin, i.e. was unbundled before @@ -171,14 +169,14 @@ get_file() { elif [ "$_type" = '"file"' ];then if [[ "$_origin" = http* ]]; then echo "$_origin looks like 'http' rather than 'file' please check..." - exit -1 + return -1 fi fname="$where.$extension" # Same filename as folder cp -f $_origin $where/$fname cloned_file="$(get_abs_path $where/$fname)" else echo "Error unsupported file type:$_type.... Aborting." - exit -1 + return -1 fi if [ "$_compression" = "tar.xz" ];then cd $where @@ -188,6 +186,7 @@ get_file() { cd - fi eval "${var_name}=${cloned_file}" + return 0 } ##################################################################### @@ -207,6 +206,8 @@ get_info_json_files() { local json_string="$(cat $merge_configuration_file)" local config_json_file="" local info_file="" + + #printf "\tReading from JSON data:\n\t\t%s" $json_string # Get files array local nf=$(get_json_object "$json_string" "-files") # Init target folder @@ -218,8 +219,10 @@ get_info_json_files() { pushd $input_folder > /dev/null _file=$(get_json_object "$json_string" "files.$f") # The name of the folder is the 'id' value - folder=$(get_json_object "$_file" "*id") - echo "Getting files from project '$folder' into '$input_folder'..." + id=$(get_json_object "$_file" "*id") + tf_config=$(get_json_object "$_file" "*tf-configuration" "N/A") + folder=$id + printf "Getting files from configuration '$tf_config', build '$folder' into '$input_folder'...\n" mkdir -p $folder bundles=$(get_json_object "$_file" "bundles" None) if [ "$bundles" != "None" ];then @@ -229,10 +232,11 @@ get_info_json_files() { get_file "$(get_json_object "$bundles" "$n")" $folder done fi - # Download/copy files and save their locations - get_file "$(get_json_object "$_file" "config")" $folder config_json_file - get_file "$(get_json_object "$_file" "info")" $folder info_file - info_files+=($info_file) + # Download/copy files and save their locations only if all are found + get_file "$(get_json_object "$_file" "config")" $folder config_json_file && \ + get_file "$(get_json_object "$_file" "info")" $folder info_file && \ + info_files+=($info_file) && json_files+=($config_json_file) && \ + list_of_merged_builds+=($id) popd > /dev/null done } @@ -244,15 +248,17 @@ get_info_json_files() { # merged_json_file: Location and name for merged json scm sources # LOCAL_WORKSPACE: Local workspace folder with the source code files # generate_local: Flag to generate local lcov reports +# info_files: Array of locations and names of info files +# json_files: Array of locations and names of json files # Arguments: # 1: Location where reside json and info files # Outputs: # Merged coverage file -# Merged json file +# Merged json configuration file ################################################################ merge_files() { - local input_folder="${1:-$LCOV_FOLDER}" -# Merge info and json files +# Merge info and json configuration files + printf "\tFound report files from %d code coverage folders to be merged...\n" ${#info_files[@]} local lc=" " if [ -n "$LOCAL_WORKSPACE" ];then # Translation from info workspaces into local workspace @@ -265,8 +271,8 @@ merge_files() { # Getting the path of the merge.py must reside at the same # path as the merge.sh python3 ${DIR}/merge.py \ - $(find $input_folder -name "*.info" -exec echo "-a {}" \;) \ - $(find $input_folder -name "*.json" -exec echo "-j {}" \;) \ + ${info_files[@]/#/-a } \ + ${json_files[@]/#/-j } \ -o $merged_coverage_file \ -m $merged_json_file \ $lc @@ -284,6 +290,7 @@ merge_files() { # Lcov report files for each info file ################################################################ generate_local_reports() { + printf "\tCreating local code coverage reports...\n" for i in ${!info_files[@]}; do local info_file=${info_files[$i]} @@ -303,23 +310,10 @@ generate_local_reports() { # Prints to stdout script usage ################################################################ usage() { - clear - echo "Usage:" - echo "merge -h Display this help message." - echo "-j JSON configuration file (info and intermediate json filenames to be merged)." - echo "[-l ] Coverage reports directory. Defaults to ./Coverage" - echo "[-w ] Workspace directory for source code files." - echo "[-o ] Merged info file. Defaults to ./merged_coverage.info" - echo "[-m ] JSON merged SCM sources. Defaults to ./merged_scm.json" - echo "[-c] Flag to download/copy the source files from the JSON merged SCM into the workspace directory." - echo "[-g] Flag to generate local reports for each info/json instance." - echo "$help_message" -} - help_message=$(cat <: Metadata that can be used for print more information related to +# each project [Optional] # Example: { "files" : [ { @@ -344,7 +340,8 @@ help_message=$(cat <" - } + }, + "metadata": .... }, { "id": "", @@ -357,7 +354,8 @@ help_message=$(cat <" - } + }, + "metadata": .... }, . . @@ -366,8 +364,21 @@ help_message=$(cat < JSON configuration file (info and intermediate json filenames to be merged)." + echo "[-l ] Coverage reports directory. Defaults to ./Coverage" + echo "[-w ] Workspace directory for source code files." + echo "[-o ] Merged info file. Defaults to ./merged_coverage.info" + echo "[-m ] JSON merged SCM sources. Defaults to ./merged_scm.json" + echo "[-c] Flag to download/copy the source files from the JSON merged SCM into the workspace directory." + echo "[-g] Flag to generate local reports for each info/json instance." + echo "$help_message" +} + -clear +[ ${-/x} != ${-} ] && TRACING=true || TRACING=false LOCAL_WORKSPACE="" CLONE_SOURCES=false merge_configuration_file="" @@ -377,7 +388,11 @@ LCOV_FOLDER="./Coverage" # File name for merge coverage info merged_coverage_file="./merged_coverage.info" merged_json_file="./merged_scm.json" +# File name to pass variables to calling script +variables_file="./variables.sh" info_files=() # Array of info files +json_files=() # Array of configuration json files +list_of_merged_builds=() while getopts ":hj:o:l:w:i:cm:g" opt; do case ${opt} in h ) @@ -385,7 +400,7 @@ while getopts ":hj:o:l:w:i:cm:g" opt; do exit 0 ;; w ) - LOCAL_WORKSPACE=$(cd $OPTARG; pwd) + LOCAL_WORKSPACE=$(cd $OPTARG &>/dev/null || true; pwd) ;; c ) CLONE_SOURCES=true @@ -405,6 +420,9 @@ while getopts ":hj:o:l:w:i:cm:g" opt; do g ) generate_local=true ;; + x ) + variables_file=$OPTARG + ;; \? ) echo "Invalid option: $OPTARG" 1>&2 usage @@ -440,9 +458,14 @@ if [ $CLONE_SOURCES = true ];then clone_repos $merged_json_file fi -# Generate branch coverage report +# Generate merged coverage report +merged_status=true genhtml --branch-coverage $merged_coverage_file \ --output-directory $LCOV_FOLDER +if [ $? -ne 0 ];then + merged_status=false + echo "ERROR: Cannot merge coverage reports" +fi if [ "$generate_local" = true ];then generate_local_reports