Home | History | Annotate | Download | only in smali
      1 #!/bin/bash
      2 #
      3 # This script runs jflex generating java code based on .jflex files.
      4 # jflex tool itself resides in external/jflex. At the time of this writing
      5 # it's not a part of jflex manifest and needs to be checked out manually.
      6 #
      7 # The script can be run from anywhere (it does not depend on current working directory)
      8 # Set $JFLEX to overwrite jflex location, if desired
      9 #
     10 # After making any changes to the lexer, the update source file(s) generated by
     11 # this script should be checked in to the repository
     12 
     13 # Update when switching to a different version of jflex
     14 EXPECTED_JFLEX_VERSION_STR="This is JFlex 1.4.3"
     15 
     16 # Get the location of this script used to find locations of other things in the tree.
     17 SCRIPT_DIR=`dirname $0`
     18 echo $SCRIPT_DIR
     19 
     20 TOP_PATH="$SCRIPT_DIR/../../.."
     21 
     22 # All specifying jflex but fallback to default location
     23 if [ -z  "$JFLEX" ]
     24 then
     25   JFLEX=$TOP_PATH/external/jflex/bin/jflex
     26 fi
     27 
     28 JFLEX_VERSION=`"$JFLEX" --version`
     29 
     30 if [ "$JFLEX_VERSION" = "" ]
     31 then
     32   echo "ERROR: Failed to execute jflex at \"$JFLEX\""
     33   exit 1
     34 fi
     35 
     36 if [ "$EXPECTED_JFLEX_VERSION_STR" != "$JFLEX_VERSION" ]
     37 then
     38   echo "ERROR: Wrong version of jflex: \"$JFLEX_VERSION\". Expected: \"$EXPECTED_JFLEX_VERSION_STR\""
     39   exit 1
     40 fi
     41 
     42 JAVA_FILE=$SCRIPT_DIR/src/main/java/org/jf/smali/smaliFlexLexer.java
     43 rm -f "$JAVA_FILE"
     44 
     45 $JFLEX --nobak -d $SCRIPT_DIR/src/main/java/org/jf/smali $SCRIPT_DIR/src/main/jflex/smaliLexer.flex
     46 
     47 # delete trailing space from end of each line to make gerrit happy
     48 sed 's/[ ]*$//' "$JAVA_FILE" > "$JAVA_FILE.tmp"
     49 rm "$JAVA_FILE"
     50 mv "$JAVA_FILE.tmp" "$JAVA_FILE"
     51