blob: ccc040133bb4f4d6d58c4efd2beaf63feda50532 [file] [log] [blame]
#!/bin/bash
#
# This script runs jflex generating java code based on .jflex files.
# jflex tool itself resides in external/jflex. At the time of this writing
# it's not a part of jflex manifest and needs to be checked out manually.
#
# The script can be run from anywhere (it does not depend on current working directory)
# Set $JFLEX to overwrite jflex location, if desired
#
# After making any changes to the lexer, the update source file(s) generated by
# this script should be checked in to the repository
# Update when switching to a different version of jflex
EXPECTED_JFLEX_VERSION_STR="This is JFlex 1.4.3"
# Get the location of this script used to find locations of other things in the tree.
SCRIPT_DIR=`dirname $0`
echo $SCRIPT_DIR
TOP_PATH="$SCRIPT_DIR/../../.."
# All specifying jflex but fallback to default location
if [ -z "$JFLEX" ]
then
JFLEX=$TOP_PATH/external/jflex/bin/jflex
fi
JFLEX_VERSION=`"$JFLEX" --version`
if [ "$JFLEX_VERSION" = "" ]
then
echo "ERROR: Failed to execute jflex at \"$JFLEX\""
exit 1
fi
if [ "$EXPECTED_JFLEX_VERSION_STR" != "$JFLEX_VERSION" ]
then
echo "ERROR: Wrong version of jflex: \"$JFLEX_VERSION\". Expected: \"$EXPECTED_JFLEX_VERSION_STR\""
exit 1
fi
JAVA_FILE=$SCRIPT_DIR/src/main/java/org/jf/smali/smaliFlexLexer.java
rm -f "$JAVA_FILE"
$JFLEX --nobak -d $SCRIPT_DIR/src/main/java/org/jf/smali $SCRIPT_DIR/src/main/jflex/smaliLexer.flex
# delete trailing space from end of each line to make gerrit happy
sed 's/[ ]*$//' "$JAVA_FILE" > "$JAVA_FILE.tmp"
rm "$JAVA_FILE"
mv "$JAVA_FILE.tmp" "$JAVA_FILE"