Skip to content

Commit

Permalink
Some scripts I used in my header-cleanups branch
Browse files Browse the repository at this point in the history
Usage:
   ./search-headers.sh | tee RESULTS
   ./search-warnings-headers.sh
   ./search-files.sh | tee RESULTS
   ./search-warnings-files.sh

and then, uh, figure it out.  :-)
  • Loading branch information
newren committed Feb 23, 2023
1 parent 06dd2ba commit db81c8d
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
31 changes: 31 additions & 0 deletions search-files.sh
@@ -0,0 +1,31 @@
#!/bin/bash

warn() {
echo "$@" >&2
git checkout -q HEAD $2
}

FLAGS="-DUSE_THE_INDEX_COMPATIBILITY_MACROS -DHAVE_FSMONITOR_DAEMON_BACKEND -Wmissing-prototypes"
for f in `git grep -l 'include.*"cache.h"' -- '*.c'`; do
sed -i 's/#include "cache.h"/#include "git-compat-util.h"/' $f

if gcc $FLAGS -E -I. $f 2>/dev/null | grep -e '"cache.h"' -e '/cache.h"' >/dev/null; then
warn FAILURE-PREPROCESS $f
continue
fi

OBJ_FILE=$(echo $f | sed -e s/\\.c$/\\.o/)
if ! make DEVELOPER=1 $OBJ_FILE >/dev/null 2>&1; then

if gcc -c $FLAGS -I. $f >/dev/null 2>&1; then
echo SUCCESS-WITH-WARNINGS $f
git checkout -q HEAD $f
continue
fi

warn FAILURE-COMPILE $f
continue
fi

echo SUCCESS $f
done
38 changes: 38 additions & 0 deletions search-headers.sh
@@ -0,0 +1,38 @@
#!/bin/bash

warn() {
echo "$@" >&2
git checkout -q HEAD $2
}

FLAGS="-DUSE_THE_INDEX_COMPATIBILITY_MACROS -DHAVE_FSMONITOR_DAEMON_BACKEND -Wmissing-prototypes"
for f in `git grep -l 'include.*"cache.h"' -- '*.h'`; do
sed -i '/#include "cache.h"/d' $f

if gcc $FLAGS -E -I. $f | grep '"cache.h"' >/dev/null; then
warn FAILURE-PREPROCESS $f
continue
fi

cat >temp.c <<-EOF &&
#include "git-compat-util.h"
#include "$f"
int main() {}
EOF

if ! gcc -c $FLAGS -I. temp.c >output 2>&1; then
warn FAILURE-COMPILE $f
rm output
continue
fi

if [[ -s output ]]; then
echo SUCCESS-WITH-WARNINGS $f
git checkout -q HEAD $f
rm output
continue
fi

rm output
echo SUCCESS $f
done
12 changes: 12 additions & 0 deletions search-warnings-files.sh
@@ -0,0 +1,12 @@
#!/bin/bash

FLAGS="-DUSE_THE_INDEX_COMPATIBILITY_MACROS -DHAVE_FSMONITOR_DAEMON_BACKEND -Wmissing-prototypes"
for f in $(grep WARNINGS RESULTS | awk {print\$2}); do
echo "======================================================================"
echo "=== $f ==="
echo "======================================================================"
sed -i 's/#include "cache.h"/#include "git-compat-util.h"/' $f
OBJ_FILE=$(echo $f | sed -e s/\\.c$/\\.o/)
make DEVELOPER=1 $OBJ_FILE
git checkout -q HEAD $f
done
17 changes: 17 additions & 0 deletions search-warnings-headers.sh
@@ -0,0 +1,17 @@
#!/bin/bash

FLAGS="-DUSE_THE_INDEX_COMPATIBILITY_MACROS -DHAVE_FSMONITOR_DAEMON_BACKEND -Wmissing-prototypes"
for f in $(grep WARNINGS RESULTS | awk {print\$2}); do
echo "======================================================================"
echo "=== $f ==="
echo "======================================================================"
sed -i '/#include "cache.h"/d' $f
cat >temp.c <<-EOF &&
#include "git-compat-util.h"
#include "$f"
int main() {}
EOF

gcc -c $FLAGS -I. temp.c
git checkout -q HEAD $f
done

0 comments on commit db81c8d

Please sign in to comment.