1#!/usr/bin/env bash 2#*************************************************************************** 3# _ _ ____ _ 4# Project ___| | | | _ \| | 5# / __| | | | |_) | | 6# | (__| |_| | _ <| |___ 7# \___|\___/|_| \_\_____| 8# 9# Copyright (C) Viktor Szakats 10# 11# This software is licensed as described in the file COPYING, which 12# you should have received as part of this distribution. The terms 13# are also available at https://curl.se/docs/copyright.html. 14# 15# You may opt to use, copy, modify, merge, publish, distribute and/or sell 16# copies of the Software, and permit persons to whom the Software is 17# furnished to do so, under the terms of the COPYING file. 18# 19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20# KIND, either express or implied. 21# 22# SPDX-License-Identifier: curl 23# 24########################################################################### 25 26detect_in_reused_sources=1 27 28if [ "$detect_in_reused_sources" = '1' ]; then 29 # Make symlinks for all re-used sources 30 grep -E '^(lib|unit)[0-9]+_SOURCES = ' libtest/Makefile.inc unit/Makefile.inc \ 31 | sed -E 's@^([a-z]+)/[a-zA-Z.]+:(lib|unit)([0-9]+)_SOURCES = (lib|unit)([0-9]+).+@\1 \2 \3 \5@g' | \ 32 while read -r l; do 33 if [[ "${l}" =~ ([a-z]+)\ ([a-z]+)\ ([0-9]+)\ ([0-9]+) ]]; then 34 trg="${BASH_REMATCH[3]}" 35 src="${BASH_REMATCH[4]}" 36 if [ "${trg}" != "${src}" ]; then 37 dir="${BASH_REMATCH[1]}" 38 pfx="${BASH_REMATCH[2]}" 39 ln -s "${pfx}${src}.c" "${dir}/${pfx}${trg}.c" 40 fi 41 fi 42 done 43fi 44 45# Look for symbols possibly re-used in multiple sources. 46# 47# Falsely picks ups symbols in re-used sources, but guarded for a single use. 48# Misses shadowed variables. 49# shellcheck disable=SC2046 50grep -E '^ *(static|struct) +' $(find libtest unit -maxdepth 1 -name 'lib*.c' -o -name 'unit*.c' -o -name 'mk-*.pl') \ 51 | grep -E '^(libtest|unit)/' \ 52 | grep -E '\.(c|pl):(static|struct)( +[a-zA-Z_* ]+)? +[a-zA-Z_][a-zA-Z0-9_]+ *' | sort -u \ 53 | grep -o -E '[a-zA-Z_][a-zA-Z0-9_]+ *[=;[({]' | tr -d '=;[({ ' \ 54 | grep -v -E '^(NULL$|sizeof$|CURLE_)' \ 55 | sort | uniq -c | sort -k 2 | grep -v -E '^ +1 ' \ 56 | awk '{print " \"" $2 "\","}' 57 58echo '---' 59 60# Extract list of macros that may be re-used by multiple tests. 61# 62# Picks up false-positive when the macro is defined to the same value everywhere. 63# shellcheck disable=SC2046 64grep -E '^ *# *define +' $(find libtest unit -maxdepth 1 -name 'lib*.c' -o -name 'unit*.c' -o -name 'mk-*.pl') \ 65 | grep -E '^(libtest|unit)/' \ 66 | grep -o -E '.+\.(c|pl): *# *define +[A-Z_][A-Z0-9_]+' | sort -u \ 67 | grep -o -E '[A-Z_][A-Z0-9_]+' \ 68 | sort | uniq -c | sort -k 2 | grep -v -E '^ +1 ' \ 69 | awk '{print " \"" $2 "\","}' 70 71if [ "$detect_in_reused_sources" = '1' ]; then 72 # Delete symlinks for all re-used sources 73 find libtest unit -type l -delete 74fi 75