michael@0: #!/bin/bash michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: # michael@0: # This file is meant to be run from the parent directory of the michael@0: # source tree. michael@0: # It does some fairly brain dead grepping to determine where michael@0: # uuids are defined, and where they may be refereced. michael@0: # michael@0: # A report is generated in the end, which could be saved. michael@0: # There are two sections to the report, on one usage and one on michael@0: # definitions. michael@0: # michael@0: # One day a stronger tool will likely be written, but this is a start michael@0: # on reporting source dependencies on uuids. michael@0: # michael@0: michael@0: michael@0: # Place to store stuff. michael@0: MYTMPDIR=`mktemp -d /tmp/deps.tmp.XXXXXXXX` michael@0: michael@0: # What we are matching on. michael@0: # If you want only CIDs, or IIDs, change. michael@0: SEARCHING4="[~#]*NS_DEFINE_[CI]ID[:space:]*(.*,.*)[:space:]*;" michael@0: michael@0: # Find the source files. michael@0: # Exclude the dist directory to find the headers in their natural dirs. michael@0: ALLSOURCEFILES=$MYTMPDIR/allsources.txt michael@0: find . -type f -and \( -name \*.cpp -or -name \*.c -or -name \*.h \) > $ALLSOURCEFILES michael@0: michael@0: # Go through the sources and find what we want. michael@0: # Assuming it is all on one line.... michael@0: export IDMATCHFILE=$MYTMPDIR/idmatches.txt michael@0: xargs -l grep -Hn $SEARCHING4 < $ALLSOURCEFILES > $IDMATCHFILE michael@0: michael@0: # Separate the variable names out of the matches. michael@0: # We have the possibility here of having duplicates with differing names michael@0: # or of having different CIDs with the same names here, but this is as michael@0: # good as it gets for now. michael@0: VARNAMESFILE=$MYTMPDIR/varnames.txt michael@0: sed "{ s/.*://; s/\/\/.*//; s/\/\*.*\*\///; s/.*(//; s/[#,].*//; s/ *//; }" < $IDMATCHFILE | grep -v \^\$ | sort | uniq > $VARNAMESFILE michael@0: michael@0: # Create a file that has states which variable were defined where. michael@0: # This also helps with identification of duplicate names michael@0: export DEFINITIONFILE=$MYTMPDIR/definevars.txt michael@0: testdefinition () { michael@0: FILENAMES=`grep $0 $IDMATCHFILE | sed s/:.*//` michael@0: if [ "" != "$FILENAMES" ]; then michael@0: echo $0:$FILENAMES michael@0: fi michael@0: } michael@0: export -f testdefinition michael@0: xargs -l bash -c testdefinition < $VARNAMESFILE > $DEFINITIONFILE michael@0: export -n testdefinition michael@0: michael@0: # Find all sources which use variable names. michael@0: # This will imply which libraries use the IDs, subsequently linking with said michael@0: # library would cause a dependency. michael@0: # This is an inferior matching method compared to actually looking at the michael@0: # symbols in resultant binaries. michael@0: export GREPVARMATCHFILE=$MYTMPDIR/grepvarmatches.txt michael@0: xargs -l grep -F -Hn --file=$VARNAMESFILE < $ALLSOURCEFILES > $GREPVARMATCHFILE michael@0: michael@0: # Make a variable match file that is more readable. michael@0: # Basically, remove the actual code and leave only varaible to file mapping. michael@0: export VARMATCHFILE=$MYTMPDIR/usevars.txt michael@0: testvarname () { michael@0: grep $0 $GREPVARMATCHFILE | sed s/:.*$0.*/:$0/ michael@0: } michael@0: export -f testvarname michael@0: xargs -l bash -c testvarname < $VARNAMESFILE | sort | uniq > $VARMATCHFILE michael@0: export -n testvarname michael@0: michael@0: # Make a file which only contains filenames that use variables. michael@0: LISTUSERFILES=$MYTMPDIR/listuserfiles.txt michael@0: stripfname() { michael@0: THEFNAME=`echo $0 | sed s/:.*//` michael@0: echo $THEFNAME michael@0: } michael@0: export -f stripfname michael@0: xargs -l bash -c stripfname < $VARMATCHFILE | sort | uniq > $LISTUSERFILES michael@0: export -n stripfname michael@0: michael@0: # Output a delimiter. michael@0: # Output a list of files that use the vars. michael@0: # With each file, output the variable names. michael@0: echo -e \*\*\* DELIMITER \*\*\* FILE depends on ID\\n michael@0: listusers() { michael@0: echo -e $0 depends on: michael@0: SYMBOLS=`grep $0 $VARMATCHFILE | sed s/.*://` michael@0: for symbol in $SYMBOLS; do michael@0: echo -e \\t$symbol michael@0: done michael@0: echo -e \\n michael@0: } michael@0: export -f listusers michael@0: xargs -l bash -c listusers < $LISTUSERFILES michael@0: export -n listusers michael@0: michael@0: # Output a delimiter. michael@0: # Output a list of variables. michael@0: # With each variable, output the files which defined them. michael@0: echo -e \*\*\* DELIMITER \*\*\* ID defined in FILE\\n michael@0: listdefs() { michael@0: echo -e $0 defined in: michael@0: DEFINES=`grep $0 $DEFINITIONFILE | sed s/.*://` michael@0: for define in $DEFINES; do michael@0: echo -e \\t$define michael@0: done michael@0: echo -e \\n michael@0: } michael@0: export -f listdefs michael@0: xargs -l bash -c listdefs < $VARNAMESFILE michael@0: export -n listdefs michael@0: michael@0: # Done with the temporary stuff. michael@0: rm -rf $MYTMPDIR