Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #!/bin/bash |
michael@0 | 2 | # |
michael@0 | 3 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 6 | |
michael@0 | 7 | # |
michael@0 | 8 | # This file is meant to be run from the parent directory of the |
michael@0 | 9 | # source tree. |
michael@0 | 10 | # It does some fairly brain dead grepping to determine where |
michael@0 | 11 | # uuids are defined, and where they may be refereced. |
michael@0 | 12 | # |
michael@0 | 13 | # A report is generated in the end, which could be saved. |
michael@0 | 14 | # There are two sections to the report, on one usage and one on |
michael@0 | 15 | # definitions. |
michael@0 | 16 | # |
michael@0 | 17 | # One day a stronger tool will likely be written, but this is a start |
michael@0 | 18 | # on reporting source dependencies on uuids. |
michael@0 | 19 | # |
michael@0 | 20 | |
michael@0 | 21 | |
michael@0 | 22 | # Place to store stuff. |
michael@0 | 23 | MYTMPDIR=`mktemp -d /tmp/deps.tmp.XXXXXXXX` |
michael@0 | 24 | |
michael@0 | 25 | # What we are matching on. |
michael@0 | 26 | # If you want only CIDs, or IIDs, change. |
michael@0 | 27 | SEARCHING4="[~#]*NS_DEFINE_[CI]ID[:space:]*(.*,.*)[:space:]*;" |
michael@0 | 28 | |
michael@0 | 29 | # Find the source files. |
michael@0 | 30 | # Exclude the dist directory to find the headers in their natural dirs. |
michael@0 | 31 | ALLSOURCEFILES=$MYTMPDIR/allsources.txt |
michael@0 | 32 | find . -type f -and \( -name \*.cpp -or -name \*.c -or -name \*.h \) > $ALLSOURCEFILES |
michael@0 | 33 | |
michael@0 | 34 | # Go through the sources and find what we want. |
michael@0 | 35 | # Assuming it is all on one line.... |
michael@0 | 36 | export IDMATCHFILE=$MYTMPDIR/idmatches.txt |
michael@0 | 37 | xargs -l grep -Hn $SEARCHING4 < $ALLSOURCEFILES > $IDMATCHFILE |
michael@0 | 38 | |
michael@0 | 39 | # Separate the variable names out of the matches. |
michael@0 | 40 | # We have the possibility here of having duplicates with differing names |
michael@0 | 41 | # or of having different CIDs with the same names here, but this is as |
michael@0 | 42 | # good as it gets for now. |
michael@0 | 43 | VARNAMESFILE=$MYTMPDIR/varnames.txt |
michael@0 | 44 | sed "{ s/.*://; s/\/\/.*//; s/\/\*.*\*\///; s/.*(//; s/[#,].*//; s/ *//; }" < $IDMATCHFILE | grep -v \^\$ | sort | uniq > $VARNAMESFILE |
michael@0 | 45 | |
michael@0 | 46 | # Create a file that has states which variable were defined where. |
michael@0 | 47 | # This also helps with identification of duplicate names |
michael@0 | 48 | export DEFINITIONFILE=$MYTMPDIR/definevars.txt |
michael@0 | 49 | testdefinition () { |
michael@0 | 50 | FILENAMES=`grep $0 $IDMATCHFILE | sed s/:.*//` |
michael@0 | 51 | if [ "" != "$FILENAMES" ]; then |
michael@0 | 52 | echo $0:$FILENAMES |
michael@0 | 53 | fi |
michael@0 | 54 | } |
michael@0 | 55 | export -f testdefinition |
michael@0 | 56 | xargs -l bash -c testdefinition < $VARNAMESFILE > $DEFINITIONFILE |
michael@0 | 57 | export -n testdefinition |
michael@0 | 58 | |
michael@0 | 59 | # Find all sources which use variable names. |
michael@0 | 60 | # This will imply which libraries use the IDs, subsequently linking with said |
michael@0 | 61 | # library would cause a dependency. |
michael@0 | 62 | # This is an inferior matching method compared to actually looking at the |
michael@0 | 63 | # symbols in resultant binaries. |
michael@0 | 64 | export GREPVARMATCHFILE=$MYTMPDIR/grepvarmatches.txt |
michael@0 | 65 | xargs -l grep -F -Hn --file=$VARNAMESFILE < $ALLSOURCEFILES > $GREPVARMATCHFILE |
michael@0 | 66 | |
michael@0 | 67 | # Make a variable match file that is more readable. |
michael@0 | 68 | # Basically, remove the actual code and leave only varaible to file mapping. |
michael@0 | 69 | export VARMATCHFILE=$MYTMPDIR/usevars.txt |
michael@0 | 70 | testvarname () { |
michael@0 | 71 | grep $0 $GREPVARMATCHFILE | sed s/:.*$0.*/:$0/ |
michael@0 | 72 | } |
michael@0 | 73 | export -f testvarname |
michael@0 | 74 | xargs -l bash -c testvarname < $VARNAMESFILE | sort | uniq > $VARMATCHFILE |
michael@0 | 75 | export -n testvarname |
michael@0 | 76 | |
michael@0 | 77 | # Make a file which only contains filenames that use variables. |
michael@0 | 78 | LISTUSERFILES=$MYTMPDIR/listuserfiles.txt |
michael@0 | 79 | stripfname() { |
michael@0 | 80 | THEFNAME=`echo $0 | sed s/:.*//` |
michael@0 | 81 | echo $THEFNAME |
michael@0 | 82 | } |
michael@0 | 83 | export -f stripfname |
michael@0 | 84 | xargs -l bash -c stripfname < $VARMATCHFILE | sort | uniq > $LISTUSERFILES |
michael@0 | 85 | export -n stripfname |
michael@0 | 86 | |
michael@0 | 87 | # Output a delimiter. |
michael@0 | 88 | # Output a list of files that use the vars. |
michael@0 | 89 | # With each file, output the variable names. |
michael@0 | 90 | echo -e \*\*\* DELIMITER \*\*\* FILE depends on ID\\n |
michael@0 | 91 | listusers() { |
michael@0 | 92 | echo -e $0 depends on: |
michael@0 | 93 | SYMBOLS=`grep $0 $VARMATCHFILE | sed s/.*://` |
michael@0 | 94 | for symbol in $SYMBOLS; do |
michael@0 | 95 | echo -e \\t$symbol |
michael@0 | 96 | done |
michael@0 | 97 | echo -e \\n |
michael@0 | 98 | } |
michael@0 | 99 | export -f listusers |
michael@0 | 100 | xargs -l bash -c listusers < $LISTUSERFILES |
michael@0 | 101 | export -n listusers |
michael@0 | 102 | |
michael@0 | 103 | # Output a delimiter. |
michael@0 | 104 | # Output a list of variables. |
michael@0 | 105 | # With each variable, output the files which defined them. |
michael@0 | 106 | echo -e \*\*\* DELIMITER \*\*\* ID defined in FILE\\n |
michael@0 | 107 | listdefs() { |
michael@0 | 108 | echo -e $0 defined in: |
michael@0 | 109 | DEFINES=`grep $0 $DEFINITIONFILE | sed s/.*://` |
michael@0 | 110 | for define in $DEFINES; do |
michael@0 | 111 | echo -e \\t$define |
michael@0 | 112 | done |
michael@0 | 113 | echo -e \\n |
michael@0 | 114 | } |
michael@0 | 115 | export -f listdefs |
michael@0 | 116 | xargs -l bash -c listdefs < $VARNAMESFILE |
michael@0 | 117 | export -n listdefs |
michael@0 | 118 | |
michael@0 | 119 | # Done with the temporary stuff. |
michael@0 | 120 | rm -rf $MYTMPDIR |