Skip to content

Instantly share code, notes, and snippets.

@andrewseidl
Last active April 11, 2017 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewseidl/5b659e852a549a53630a3a051485924c to your computer and use it in GitHub Desktop.
Save andrewseidl/5b659e852a549a53630a3a051485924c to your computer and use it in GitHub Desktop.
Given one header, recursively find all other files it #includes
#!/bin/bash
set -e
START="folly/SharedMutex.h"
ALL=$START
NEW=""
# could simplyify with `sort -t' ' -u`
while ! diff -q <(echo $ALL | tr ' ' '\n' | sort -u) <(echo $NEW | tr ' ' '\n' | sort -u) >/dev/null ; do
ALL=$(echo "$NEW $ALL" | tr ' ' '\n' | sort -u | tr '\n' ' ')
NEW=$(grep \#include ${ALL} | grep -o "<folly/[^>]*" | sed 's/<//g' | sort -u | tr '\n' ' ')
NEW=$(echo "$START $NEW" | tr ' ' '\n' | sort -u | tr '\n' ' ')
done
echo $ALL
echo
BASE=slimfolly
for i in $ALL ; do
mkdir -p $BASE/$(dirname $i)
CPP=$(echo $i | sed 's/.h$/.cpp/')
cp $i $BASE/$i
if [ -e $CPP ] ; then
cp $CPP $BASE/$CPP
echo $CPP
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment