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