Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | ############################################################################## |
Saul Romero | 7438b3d | 2024-08-20 16:12:40 +0100 | [diff] [blame] | 4 | # Copyright (c) 2020-2025, ARM Limited and Contributors. All rights reserved. |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 5 | # |
| 6 | # SPDX-License-Identifier: GPL-2.0-only |
| 7 | ############################################################################## |
| 8 | |
| 9 | #============================================================================== |
| 10 | # FILE: merge.sh |
| 11 | # |
| 12 | # DESCRIPTION: Wrapper to merge intermediate json files and LCOV trace .info |
| 13 | # files. |
| 14 | #============================================================================== |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 15 | set -x |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 16 | ################################################################# |
| 17 | # Function to manipulate json objects. |
| 18 | # The json object properties can be accessed through "." separated |
| 19 | # property names. There are special characters that define a function |
| 20 | # over a given property value: |
| 21 | # If the qualifier list starts with '-' then is asking for the len of the |
| 22 | # json array defined by the qualifiers. |
| 23 | # If the qualifier list starts with '*' then the resulting json value |
| 24 | # is returned without double quotes at the end and the beginning. |
| 25 | # If some property name starts with "?" then is requesting if that |
| 26 | # property exists within the json object. |
| 27 | # Globals: |
| 28 | # None |
| 29 | # Arguments: |
| 30 | # 1-Json string that describes the json object |
| 31 | # 2-String of '.' separated qualifiers to access properties |
| 32 | # within the json object |
| 33 | # 3- Optional default value for a sought property value |
| 34 | # Outputs: |
| 35 | # None |
| 36 | ################################################################ |
| 37 | get_json_object() { |
| 38 | export _json_string="$1" |
| 39 | export _qualifiers="$2" |
| 40 | export _default="$3" |
| 41 | python3 - << EOT |
| 42 | import os |
| 43 | import json |
| 44 | import sys |
| 45 | |
| 46 | _json_string = os.getenv("_json_string", "") |
| 47 | _qualifiers = os.getenv("_qualifiers", "") |
| 48 | _default = os.getenv("_default", "") |
| 49 | try: |
| 50 | data = json.loads(_json_string) |
| 51 | except Exception as ex: |
| 52 | print("Error decoding json string:{}".format(ex)) |
| 53 | sys.exit(-1) |
| 54 | ptr = data |
| 55 | if _qualifiers[0] in ['-', '*']: |
| 56 | cmd = _qualifiers[0] |
| 57 | _qualifiers = _qualifiers[1:] |
| 58 | else: |
| 59 | cmd = "" |
| 60 | for _name in _qualifiers.split("."): |
| 61 | if _name in ptr: |
| 62 | ptr = ptr[_name] |
| 63 | elif _name.isdigit() and int(_name) < len(ptr): |
| 64 | ptr = ptr[int(_name)] |
| 65 | elif _name.startswith("?"): |
| 66 | print(_name[1:] in ptr) |
| 67 | sys.exit(0) |
| 68 | elif _default: |
| 69 | print(_default) |
| 70 | sys.exit(0) |
| 71 | else: |
| 72 | print("'{}' is not in the json object".format(_name)) |
| 73 | sys.exit(-1) |
| 74 | if cmd == "-": |
| 75 | # return len of the json array |
| 76 | print(len(ptr)) |
| 77 | elif cmd == "*": |
| 78 | #remove quotes |
| 79 | string = json.dumps(ptr) |
| 80 | if string.startswith('"') and string.endswith('"'): |
| 81 | string = string[1:-1] |
| 82 | print(string) |
| 83 | else: |
| 84 | print(json.dumps(ptr)) |
| 85 | EOT |
| 86 | } |
| 87 | |
| 88 | ################################################################# |
| 89 | # Convert a relative path to absolute path |
| 90 | # Globals: |
| 91 | # None |
| 92 | # Arguments: |
| 93 | # 1-Path to be converted |
| 94 | # Outputs: |
| 95 | # Absolute path |
| 96 | ################################################################ |
| 97 | get_abs_path() { |
| 98 | path="$1" |
| 99 | echo "$(cd $(dirname $path) && echo "$(pwd -P)"/$(basename $path))" |
| 100 | } |
| 101 | |
| 102 | ################################################################# |
| 103 | # Clone the source files |
| 104 | # Globals: |
| 105 | # None |
| 106 | # Arguments: |
| 107 | # 1-Json file with the sources to be cloned |
| 108 | # 2-Folder where to clone the sources |
| 109 | # Outputs: |
| 110 | # None |
| 111 | ################################################################ |
| 112 | clone_repos() { |
| 113 | export OUTPUT_JSON="$1" |
| 114 | export CSOURCE_FOLDER="${2:-$LOCAL_WORKSPACE}" |
| 115 | |
| 116 | cd $DIR # To be run at the same level of this script |
| 117 | python3 - << EOT |
| 118 | import os |
| 119 | import clone_sources |
| 120 | |
| 121 | output_file = os.getenv('OUTPUT_JSON', 'output_file.json') |
| 122 | source_folder = os.getenv('CSOURCE_FOLDER', 'source') |
| 123 | try: |
| 124 | r = clone_sources.CloneSources(output_file) |
| 125 | r.clone_repo(source_folder) |
| 126 | except Exception as ex: |
| 127 | print(ex) |
| 128 | EOT |
saul-romero-arm | 6c40b24 | 2021-06-18 10:21:04 +0000 | [diff] [blame] | 129 | cd - |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | ################################################################# |
| 133 | # Get the a file defined in the json object |
| 134 | # Globals: |
| 135 | # None |
| 136 | # Arguments: |
| 137 | # 1-Json object that defines the locations of the info and json |
| 138 | # files |
| 139 | # 2-Folder to save the info and json files |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 140 | # 3-Reference argument to hold the copied file name location |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 141 | # Outputs: |
| 142 | # None |
| 143 | ################################################################ |
| 144 | get_file() { |
| 145 | json_object="$1" |
| 146 | where="$2" |
| 147 | var_name="${3:-param_cloned}" # Defaults to globar var |
| 148 | |
| 149 | local _type=$(get_json_object "$json_object" "type") |
| 150 | local _origin=$(get_json_object "$json_object" "*origin") |
| 151 | local _compression=$(get_json_object "$json_object" "*compression" None) |
| 152 | local fname="" |
| 153 | local cloned_file="" |
| 154 | local full_filename=$(basename -- "$_origin") |
| 155 | local extension="${full_filename##*.}" |
| 156 | local filename="${full_filename%.*}" |
| 157 | |
| 158 | if [ "$_type" = '"http"' ];then |
| 159 | fname="$where.$extension" # Same filename as folder |
| 160 | rm $where/$fname &>/dev/null || true |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 161 | wget -nv $_origin -O $where/$fname || return -1 |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 162 | cloned_file="$(get_abs_path $where/$fname)" |
| 163 | elif [ "$_type" = '"bundle"' ];then |
| 164 | # Check file exists at origin, i.e. was unbundled before |
| 165 | fname="$_origin" |
| 166 | if [ -f "$where/$fname" ];then |
| 167 | cloned_file="$(get_abs_path $where/$fname)" |
| 168 | fi |
| 169 | elif [ "$_type" = '"file"' ];then |
saul-romero-arm | 6c40b24 | 2021-06-18 10:21:04 +0000 | [diff] [blame] | 170 | if [[ "$_origin" = http* ]]; then |
| 171 | echo "$_origin looks like 'http' rather than 'file' please check..." |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 172 | return -1 |
saul-romero-arm | 6c40b24 | 2021-06-18 10:21:04 +0000 | [diff] [blame] | 173 | fi |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 174 | fname="$where.$extension" # Same filename as folder |
| 175 | cp -f $_origin $where/$fname |
| 176 | cloned_file="$(get_abs_path $where/$fname)" |
| 177 | else |
| 178 | echo "Error unsupported file type:$_type.... Aborting." |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 179 | return -1 |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 180 | fi |
| 181 | if [ "$_compression" = "tar.xz" ];then |
| 182 | cd $where |
| 183 | pwd |
| 184 | tar -xzf $fname |
| 185 | rm -f $fname |
| 186 | cd - |
| 187 | fi |
| 188 | eval "${var_name}=${cloned_file}" |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 189 | return 0 |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | ##################################################################### |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 193 | # Get (download/copy) info and json files from the configuration json |
| 194 | # file |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 195 | # Globals: |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 196 | # merge_configuration_file: Input json file with locations of info |
| 197 | # and json scm files to be merged. |
| 198 | # info_files: Array of info file locations. |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 199 | # Arguments: |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 200 | # 1: Target folder to download info and json files to be merged. |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 201 | # Outputs: |
| 202 | # None |
| 203 | ################################################################### |
| 204 | get_info_json_files() { |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 205 | local input_folder="${1:-$LCOV_FOLDER}" |
| 206 | local json_string="$(cat $merge_configuration_file)" |
| 207 | local config_json_file="" |
| 208 | local info_file="" |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 209 | |
| 210 | #printf "\tReading from JSON data:\n\t\t%s" $json_string |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 211 | # Get files array |
| 212 | local nf=$(get_json_object "$json_string" "-files") |
| 213 | # Init target folder |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 214 | rm -rf $input_folder > /dev/null || true |
| 215 | mkdir -p $input_folder |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 216 | # Iterate through each file element and get the files |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 217 | for f in $(seq 0 $(($nf - 1))); |
| 218 | do |
| 219 | pushd $input_folder > /dev/null |
| 220 | _file=$(get_json_object "$json_string" "files.$f") |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 221 | # The name of the folder is the 'id' value |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 222 | id=$(get_json_object "$_file" "*id") |
| 223 | tf_config=$(get_json_object "$_file" "*tf-configuration" "N/A") |
| 224 | folder=$id |
| 225 | printf "Getting files from configuration '$tf_config', build '$folder' into '$input_folder'...\n" |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 226 | mkdir -p $folder |
| 227 | bundles=$(get_json_object "$_file" "bundles" None) |
| 228 | if [ "$bundles" != "None" ];then |
| 229 | nb=$(get_json_object "$_file" "-bundles") |
| 230 | for n in $(seq 0 $(($nb - 1))); |
| 231 | do |
| 232 | get_file "$(get_json_object "$bundles" "$n")" $folder |
| 233 | done |
| 234 | fi |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 235 | # Download/copy files and save their locations only if all are found |
| 236 | get_file "$(get_json_object "$_file" "config")" $folder config_json_file && \ |
| 237 | get_file "$(get_json_object "$_file" "info")" $folder info_file && \ |
| 238 | info_files+=($info_file) && json_files+=($config_json_file) && \ |
| 239 | list_of_merged_builds+=($id) |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 240 | popd > /dev/null |
| 241 | done |
| 242 | } |
| 243 | |
| 244 | ################################################################# |
| 245 | # Merge json and info files and generate branch coverage report |
| 246 | # Globals: |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 247 | # merged_coverage_file: Location and name for merged coverage info |
| 248 | # merged_json_file: Location and name for merged json scm sources |
| 249 | # LOCAL_WORKSPACE: Local workspace folder with the source code files |
| 250 | # generate_local: Flag to generate local lcov reports |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 251 | # info_files: Array of locations and names of info files |
| 252 | # json_files: Array of locations and names of json files |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 253 | # Arguments: |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 254 | # 1: Location where reside json and info files |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 255 | # Outputs: |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 256 | # Merged coverage file |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 257 | # Merged json configuration file |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 258 | ################################################################ |
| 259 | merge_files() { |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 260 | # Merge info and json configuration files |
| 261 | printf "\tFound report files from %d code coverage folders to be merged...\n" ${#info_files[@]} |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 262 | local lc=" " |
| 263 | if [ -n "$LOCAL_WORKSPACE" ];then |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 264 | # Translation from info workspaces into local workspace |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 265 | lc=" --local-workspace $LOCAL_WORKSPACE" |
| 266 | fi |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 267 | if [ "$generate_local" = true ];then |
| 268 | # Generate local reports |
| 269 | lc="${lc} -k" |
| 270 | fi |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 271 | # Getting the path of the merge.py must reside at the same |
| 272 | # path as the merge.sh |
| 273 | python3 ${DIR}/merge.py \ |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 274 | ${info_files[@]/#/-a } \ |
| 275 | ${json_files[@]/#/-j } \ |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 276 | -o $merged_coverage_file \ |
| 277 | -m $merged_json_file \ |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 278 | $lc |
| 279 | |
| 280 | } |
| 281 | |
| 282 | |
| 283 | ################################################################# |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 284 | # Generate local lcov reports |
| 285 | # Globals: |
| 286 | # info_files: Array of locations and names of info files |
| 287 | # Arguments: |
| 288 | # None |
| 289 | # Outputs: |
| 290 | # Lcov report files for each info file |
| 291 | ################################################################ |
| 292 | generate_local_reports() { |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 293 | printf "\tCreating local code coverage reports...\n" |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 294 | for i in ${!info_files[@]}; |
| 295 | do |
| 296 | local info_file=${info_files[$i]} |
| 297 | local parentdir=$(dirname "$info_file") |
| 298 | local t_info_file="${info_file/.info/_local.info}" |
| 299 | genhtml --branch-coverage $t_info_file \ |
| 300 | --output-directory $parentdir |
| 301 | done |
| 302 | } |
| 303 | |
| 304 | |
| 305 | ################################################################# |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 306 | # Print scripts usage |
| 307 | # Arguments: |
| 308 | # None |
| 309 | # Outputs: |
| 310 | # Prints to stdout script usage |
| 311 | ################################################################ |
| 312 | usage() { |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 313 | help_message=$(cat <<EOF |
| 314 | |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 315 | # The script merging the info files (code coverage) and json SCM sources |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 316 | # (intermediate layer) needs a minimum JSON configuration file with the following |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 317 | # properties: |
| 318 | # files: array of objects that describe the type of file/project to be |
| 319 | # merged. |
| 320 | # id: Unique identifier (project) associated to the info and |
| 321 | # intermediate json files |
| 322 | # config: Intermediate json file |
| 323 | # type: Type of storage for the file. (http or file) |
| 324 | # origin: Location (url or folder) of the file |
| 325 | # info: Info file |
| 326 | # type: Type of storage for the file. (http or file) |
| 327 | # origin: Location (url or folder) of the file |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 328 | # <metadata>: Metadata that can be used for print more information related to |
| 329 | # each project [Optional] |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 330 | # Example: |
| 331 | { "files" : [ |
| 332 | { |
| 333 | "id": "<project 1>", |
| 334 | "config": |
| 335 | { |
| 336 | "type": "http", |
| 337 | "origin": "<URL of json file for project 1>" |
| 338 | }, |
| 339 | "info": |
| 340 | { |
| 341 | "type": "http", |
| 342 | "origin": "<URL of info file for project 1>" |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 343 | }, |
| 344 | "metadata": .... |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 345 | }, |
| 346 | { |
| 347 | "id": "<project 2>", |
| 348 | "config": |
| 349 | { |
| 350 | "type": "http", |
| 351 | "origin": "<URL of json file for project 2>" |
| 352 | }, |
| 353 | "info": |
| 354 | { |
| 355 | "type": "http", |
| 356 | "origin": "<URL of info file for project 2>" |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 357 | }, |
| 358 | "metadata": .... |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 359 | }, |
| 360 | . |
| 361 | . |
| 362 | . |
| 363 | ] |
| 364 | } |
| 365 | EOF |
| 366 | ) |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 367 | clear || true |
Saul ROMERO DOMINGUEZ | 7bae620 | 2025-04-23 14:25:24 +0000 | [diff] [blame^] | 368 | echo "Receiving arguments:" |
| 369 | echo $@ |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 370 | echo "Usage:" |
| 371 | echo "merge -h Display this help message." |
| 372 | echo "-j <JSON filename> JSON configuration file (info and intermediate json filenames to be merged)." |
| 373 | echo "[-l <Report path>] Coverage reports directory. Defaults to ./Coverage" |
| 374 | echo "[-w <Workspace path>] Workspace directory for source code files." |
| 375 | echo "[-o <Info filename>] Merged info file. Defaults to ./merged_coverage.info" |
| 376 | echo "[-m <JSON filename>] JSON merged SCM sources. Defaults to ./merged_scm.json" |
| 377 | echo "[-c] Flag to download/copy the source files from the JSON merged SCM into the workspace directory." |
| 378 | echo "[-g] Flag to generate local reports for each info/json instance." |
Saul Romero | 7438b3d | 2024-08-20 16:12:40 +0100 | [diff] [blame] | 379 | echo "[-i] Ignore errors on genhtml." |
| 380 | echo "[-d] Enable debug mode for the script." |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 381 | echo "$help_message" |
| 382 | } |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 383 | |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 384 | [ ${-/x} != ${-} ] && TRACING=true || TRACING=false |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 385 | LOCAL_WORKSPACE="" |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 386 | CLONE_SOURCES=false |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 387 | merge_configuration_file="" |
| 388 | generate_local=false |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 389 | # Folder to to put the reports |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 390 | LCOV_FOLDER="./Coverage" |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 391 | # File name for merge coverage info |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 392 | merged_coverage_file="./merged_coverage.info" |
| 393 | merged_json_file="./merged_scm.json" |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 394 | # File name to pass variables to calling script |
| 395 | variables_file="./variables.sh" |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 396 | info_files=() # Array of info files |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 397 | json_files=() # Array of configuration json files |
| 398 | list_of_merged_builds=() |
Saul Romero | 7438b3d | 2024-08-20 16:12:40 +0100 | [diff] [blame] | 399 | GENHTML_ARGS="" |
| 400 | DEBUG_MODE=false |
| 401 | genhtml_version=$(genhtml --version | rev | cut -d ' ' -f1 | rev | xargs) |
| 402 | gen_major=$(echo "$genhtml_version" | cut -d '.' -f1) |
| 403 | gen_minor=$(echo "$genhtml_version" | rev | cut -d '.' -f1 | rev) |
Saul ROMERO DOMINGUEZ | 7bae620 | 2025-04-23 14:25:24 +0000 | [diff] [blame^] | 404 | unset OPTIND |
Saul Romero | 7438b3d | 2024-08-20 16:12:40 +0100 | [diff] [blame] | 405 | while getopts ":hj:o:l:w:idcm:g" opt; do |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 406 | case ${opt} in |
| 407 | h ) |
| 408 | usage |
| 409 | exit 0 |
| 410 | ;; |
| 411 | w ) |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 412 | LOCAL_WORKSPACE=$(cd $OPTARG &>/dev/null || true; pwd) |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 413 | ;; |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 414 | c ) |
| 415 | CLONE_SOURCES=true |
| 416 | ;; |
Saul Romero | 7438b3d | 2024-08-20 16:12:40 +0100 | [diff] [blame] | 417 | d ) |
| 418 | DEBUG_MODE=true |
| 419 | ;; |
| 420 | i ) |
| 421 | GENHTML_ARGS="${GENHTML_ARGS} --ignore-errors $([ $gen_major = '2' ] && echo inconsistent || echo source)" |
| 422 | ;; |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 423 | j ) |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 424 | merge_configuration_file=$OPTARG |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 425 | ;; |
| 426 | l ) |
| 427 | LCOV_FOLDER=$OPTARG |
| 428 | ;; |
| 429 | o ) |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 430 | merged_coverage_file=$OPTARG |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 431 | ;; |
| 432 | m ) |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 433 | merged_json_file=$OPTARG |
| 434 | ;; |
| 435 | g ) |
| 436 | generate_local=true |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 437 | ;; |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 438 | x ) |
| 439 | variables_file=$OPTARG |
| 440 | ;; |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 441 | \? ) |
| 442 | echo "Invalid option: $OPTARG" 1>&2 |
| 443 | usage |
| 444 | exit -1 |
| 445 | ;; |
| 446 | : ) |
| 447 | echo "Invalid option: $OPTARG requires an argument" 1>&2 |
| 448 | usage |
| 449 | exit -1 |
| 450 | ;; |
| 451 | esac |
| 452 | done |
Saul Romero | 7438b3d | 2024-08-20 16:12:40 +0100 | [diff] [blame] | 453 | [ $DEBUG_MODE = true ] && set -x || set +x |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 454 | shift $((OPTIND -1)) |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 455 | if [ -z "$merge_configuration_file" ]; then |
| 456 | echo "Merged configuration file required." |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 457 | usage |
| 458 | exit -1 |
| 459 | fi |
| 460 | if [ -z "$LOCAL_WORKSPACE" ] && [ $CLONE_SOURCES = true ]; then |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 461 | echo "A local workspace directory is required to clone/copy sources!" |
saul-romero-arm | 6c40b24 | 2021-06-18 10:21:04 +0000 | [diff] [blame] | 462 | exit -1 |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 463 | fi |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 464 | # Getting the script folder where other qa-tools script files must reside, i.e |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 465 | # merge.py, clone_sources.py |
Saul ROMERO DOMINGUEZ | 7bae620 | 2025-04-23 14:25:24 +0000 | [diff] [blame^] | 466 | mkdir -p "${LCOV_FOLDER}" |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 467 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 468 | LCOV_FOLDER="$(get_abs_path $LCOV_FOLDER)" |
| 469 | merged_coverage_file="$(get_abs_path $merged_coverage_file)" |
| 470 | merged_json_file="$(get_abs_path $merged_json_file)" |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 471 | param_cloned="" |
Saul Romero | 7438b3d | 2024-08-20 16:12:40 +0100 | [diff] [blame] | 472 | set +x |
| 473 | get_info_json_files # always disabled for debug |
| 474 | [ $DEBUG_MODE = true ] && set -x || set +x |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 475 | merge_files |
| 476 | if [ $CLONE_SOURCES = true ];then |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 477 | clone_repos $merged_json_file |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 478 | fi |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 479 | |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 480 | # Generate merged coverage report |
| 481 | merged_status=true |
Saul Romero | 7438b3d | 2024-08-20 16:12:40 +0100 | [diff] [blame] | 482 | genhtml $GENHTML_ARGS --branch-coverage $merged_coverage_file \ |
Basil Eljuse | 4b14afb | 2020-09-30 13:07:23 +0100 | [diff] [blame] | 483 | --output-directory $LCOV_FOLDER |
Saul Romero | 190b4f1 | 2023-12-11 14:22:22 +0000 | [diff] [blame] | 484 | if [ $? -ne 0 ];then |
| 485 | merged_status=false |
| 486 | echo "ERROR: Cannot merge coverage reports" |
| 487 | fi |
Saul Romero | 884d214 | 2023-01-16 10:31:22 +0000 | [diff] [blame] | 488 | |
| 489 | if [ "$generate_local" = true ];then |
| 490 | generate_local_reports |
| 491 | fi |