tools/uuiddeps/uuidgrep.bash

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/uuiddeps/uuidgrep.bash	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +#!/bin/bash
     1.5 +#
     1.6 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.9 +
    1.10 +#
    1.11 +# This file is meant to be run from the parent directory of the
    1.12 +#  source tree.
    1.13 +# It does some fairly brain dead grepping to determine where
    1.14 +#  uuids are defined, and where they may be refereced.
    1.15 +#
    1.16 +# A report is generated in the end, which could be saved.
    1.17 +# There are two sections to the report, on one usage and one on
    1.18 +#  definitions.
    1.19 +#
    1.20 +# One day a stronger tool will likely be written, but this is a start
    1.21 +#  on reporting source dependencies on uuids.
    1.22 +#
    1.23 +
    1.24 +
    1.25 +# Place to store stuff.
    1.26 +MYTMPDIR=`mktemp -d /tmp/deps.tmp.XXXXXXXX`
    1.27 +
    1.28 +# What we are matching on.
    1.29 +# If you want only CIDs, or IIDs, change.
    1.30 +SEARCHING4="[~#]*NS_DEFINE_[CI]ID[:space:]*(.*,.*)[:space:]*;"
    1.31 +
    1.32 +# Find the source files.
    1.33 +# Exclude the dist directory to find the headers in their natural dirs.
    1.34 +ALLSOURCEFILES=$MYTMPDIR/allsources.txt
    1.35 +find . -type f -and \( -name \*.cpp -or -name \*.c -or -name \*.h \) > $ALLSOURCEFILES
    1.36 +
    1.37 +# Go through the sources and find what we want.
    1.38 +# Assuming it is all on one line....
    1.39 +export IDMATCHFILE=$MYTMPDIR/idmatches.txt
    1.40 +xargs -l grep -Hn $SEARCHING4 < $ALLSOURCEFILES > $IDMATCHFILE
    1.41 +
    1.42 +# Separate the variable names out of the matches.
    1.43 +# We have the possibility here of having duplicates with differing names
    1.44 +#  or of having different CIDs with the same names here, but this is as
    1.45 +#  good as it gets for now.
    1.46 +VARNAMESFILE=$MYTMPDIR/varnames.txt
    1.47 +sed "{ s/.*://; s/\/\/.*//; s/\/\*.*\*\///; s/.*(//; s/[#,].*//; s/ *//; }" < $IDMATCHFILE | grep -v \^\$ | sort | uniq > $VARNAMESFILE
    1.48 +
    1.49 +# Create a file that has states which variable were defined where.
    1.50 +# This also helps with identification of duplicate names
    1.51 +export DEFINITIONFILE=$MYTMPDIR/definevars.txt
    1.52 +testdefinition () {
    1.53 +    FILENAMES=`grep $0 $IDMATCHFILE | sed s/:.*//`
    1.54 +    if [ "" != "$FILENAMES" ]; then
    1.55 +	echo $0:$FILENAMES
    1.56 +    fi
    1.57 +}
    1.58 +export -f testdefinition
    1.59 +xargs -l bash -c testdefinition < $VARNAMESFILE > $DEFINITIONFILE
    1.60 +export -n testdefinition
    1.61 +
    1.62 +# Find all sources which use variable names.
    1.63 +# This will imply which libraries use the IDs, subsequently linking with said
    1.64 +#  library would cause a dependency.
    1.65 +# This is an inferior matching method compared to actually looking at the
    1.66 +#  symbols in resultant binaries.
    1.67 +export GREPVARMATCHFILE=$MYTMPDIR/grepvarmatches.txt
    1.68 +xargs -l grep -F -Hn --file=$VARNAMESFILE < $ALLSOURCEFILES > $GREPVARMATCHFILE
    1.69 +
    1.70 +# Make a variable match file that is more readable.
    1.71 +# Basically, remove the actual code and leave only varaible to file mapping.
    1.72 +export VARMATCHFILE=$MYTMPDIR/usevars.txt
    1.73 +testvarname () {
    1.74 +    grep $0 $GREPVARMATCHFILE | sed s/:.*$0.*/:$0/
    1.75 +}
    1.76 +export -f testvarname
    1.77 +xargs -l bash -c testvarname < $VARNAMESFILE | sort | uniq > $VARMATCHFILE
    1.78 +export -n testvarname
    1.79 +
    1.80 +# Make a file which only contains filenames that use variables.
    1.81 +LISTUSERFILES=$MYTMPDIR/listuserfiles.txt
    1.82 +stripfname() {
    1.83 +    THEFNAME=`echo $0 | sed s/:.*//`
    1.84 +    echo $THEFNAME
    1.85 +}
    1.86 +export -f stripfname
    1.87 +xargs -l bash -c stripfname < $VARMATCHFILE | sort | uniq > $LISTUSERFILES
    1.88 +export -n stripfname
    1.89 +
    1.90 +# Output a delimiter.
    1.91 +# Output a list of files that use the vars.
    1.92 +# With each file, output the variable names.
    1.93 +echo -e \*\*\* DELIMITER \*\*\*  FILE depends on ID\\n
    1.94 +listusers() {
    1.95 +    echo -e $0 depends on:
    1.96 +    SYMBOLS=`grep $0 $VARMATCHFILE | sed s/.*://`
    1.97 +    for symbol in $SYMBOLS; do
    1.98 +	echo -e \\t$symbol
    1.99 +    done
   1.100 +    echo -e \\n
   1.101 +}
   1.102 +export -f listusers
   1.103 +xargs -l bash -c listusers < $LISTUSERFILES
   1.104 +export -n listusers
   1.105 +
   1.106 +# Output a delimiter.
   1.107 +# Output a list of variables.
   1.108 +# With each variable, output the files which defined them.
   1.109 +echo -e \*\*\* DELIMITER \*\*\*  ID defined in FILE\\n
   1.110 +listdefs() {
   1.111 +    echo -e $0 defined in:
   1.112 +    DEFINES=`grep $0 $DEFINITIONFILE | sed s/.*://`
   1.113 +    for define in $DEFINES; do
   1.114 +	echo -e \\t$define
   1.115 +    done
   1.116 +    echo -e \\n
   1.117 +}
   1.118 +export -f listdefs
   1.119 +xargs -l bash -c listdefs < $VARNAMESFILE
   1.120 +export -n listdefs
   1.121 +
   1.122 +# Done with the temporary stuff.
   1.123 +rm -rf $MYTMPDIR

mercurial