github.com/MetalBlockchain/metalgo@v1.11.9/scripts/mock.gen.sh (about) 1 #!/usr/bin/env bash 2 3 set -euo pipefail 4 5 if ! [[ "$0" =~ scripts/mock.gen.sh ]]; then 6 echo "must be run from repository root" 7 exit 255 8 fi 9 10 # https://github.com/uber-go/mock 11 go install -v go.uber.org/mock/mockgen@v0.4.0 12 13 source ./scripts/constants.sh 14 15 outputted_files=() 16 17 # tuples of (source interface import path, comma-separated interface names, output file path) 18 input="scripts/mocks.mockgen.txt" 19 while IFS= read -r line 20 do 21 IFS='=' read -r src_import_path interface_name output_path <<< "${line}" 22 package_name="$(basename "$(dirname "$output_path")")" 23 echo "Generating ${output_path}..." 24 outputted_files+=("${output_path}") 25 mockgen -package="${package_name}" -destination="${output_path}" "${src_import_path}" "${interface_name}" 26 27 done < "$input" 28 29 # tuples of (source import path, comma-separated interface names to exclude, output file path) 30 input="scripts/mocks.mockgen.source.txt" 31 while IFS= read -r line 32 do 33 IFS='=' read -r source_path exclude_interfaces output_path <<< "${line}" 34 package_name=$(basename "$(dirname "$output_path")") 35 outputted_files+=("${output_path}") 36 echo "Generating ${output_path}..." 37 38 mockgen \ 39 -source="${source_path}" \ 40 -destination="${output_path}" \ 41 -package="${package_name}" \ 42 -exclude_interfaces="${exclude_interfaces}" 43 44 done < "$input" 45 46 mapfile -t all_generated_files < <(grep -Rl 'Code generated by MockGen. DO NOT EDIT.') 47 48 # Exclude certain files 49 outputted_files+=('scripts/mock.gen.sh') # This file 50 outputted_files+=('vms/components/avax/mock_transferable_out.go') # Embedded verify.IsState 51 outputted_files+=('vms/platformvm/fx/mock_fx.go') # Embedded verify.IsNotState 52 53 mapfile -t diff_files < <(echo "${all_generated_files[@]}" "${outputted_files[@]}" | tr ' ' '\n' | sort | uniq -u) 54 55 if (( ${#diff_files[@]} )); then 56 printf "\nFAILURE\n" 57 echo "Detected MockGen generated files that are not in scripts/mocks.mockgen.source.txt or scripts/mocks.mockgen.txt:" 58 printf "%s\n" "${diff_files[@]}" 59 exit 255 60 fi 61 62 echo "SUCCESS"