tools/uuiddeps/uuidgrep.bash

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rwxr-xr-x

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial