Home | History | Annotate | Download | only in scripts
      1 #!/bin/bash
      2 #
      3 # Copyright (C) 2008 The Android Open Source Project
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 #      http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an "AS IS" BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 
     17 BASEDIR=`pwd`
     18 CLASSFOLDERS='out/classes_cfh out/classes_jasmin out/classes_javac'
     19 
     20 function findClassFile()
     21 {
     22     i=0;
     23     for path in $1; 
     24     do
     25         if [ -f ${path}/$2 ]; then
     26             CLASSFOLDER=$path
     27             return
     28         fi
     29     done
     30 }
     31 
     32 function mapOpcode()
     33 {
     34     MAPPED_OPCODE=""
     35     if [ -z $1 ]; then
     36         MAPPED_OPCODE=""
     37         return;
     38     fi
     39     
     40     line=`grep -e "^$1    " ${BASEDIR}/data/opcode_mapping`
     41     if [ $? -ne 0 ]; then
     42         MAPPED_OPCODE=""
     43     else
     44         echo $line
     45         MAPPED_OPCODE=`echo -n $line | cut -d" " -f2`
     46     fi
     47 }
     48 
     49 while read -u 3 myline;
     50 do
     51     jpackageclass=`echo $myline | cut -d";" -f1` # e.g dxc.junit.verify.t482_9.Main_testVFE2
     52     jpackageclassfile=`echo $jpackageclass | sed -e 's/\./\//g;s/$/.java/'`
     53     echo $jpackageclassfile
     54     jtestclass=`echo $myline | cut -d";" -f2` # e.g dxc.junit.verity.t482_9.jm.T_t482_9_1
     55     jtestclassfile=`echo $jtestclass | sed -e 's/\./\//g;s/$/.class/'`
     56     jtestsourcefile=`echo $jtestclass | sed -e 's/\./\//g;s/$/.java/'`
     57 #    echo $jtestclassfile
     58     
     59 rm -rf out/tmp
     60 mkdir -p out/tmp
     61 
     62 findClassFile "${CLASSFOLDERS}" $jtestclassfile
     63 cd ${CLASSFOLDER}
     64 cp -P --parent $jtestclassfile ${BASEDIR}/out/tmp/
     65 cd ${BASEDIR}
     66 
     67 #findClassFile "${CLASSFOLDERS}" $jpackageclassfile
     68 #cd ${CLASSFOLDER}
     69 #cp -P --parents $jpackageclassfile ${BASEDIR}/out/tmp/
     70 #cd ${BASEDIR}
     71 
     72 # echo ${CLASSFOLDER}/${jtestclassfile}
     73 
     74 OPCODE=`echo $jtestclass | sed -e 's/.*T_\(.*\)_[0-9]\+[_]*[a-z]*/\1/'`
     75 mapOpcode ${OPCODE}
     76 # echo ${OPCODE} " - " ${MAPPED_OPCODE}
     77 if [ -z ${MAPPED_OPCODE} ]; then
     78     continue
     79 fi
     80 
     81 for subcode in `echo $MAPPED_OPCODE | cut -d";" -f1,2 --output-delimiter=" "`; do
     82 
     83     SCRIPT="s#out/classes_[^/]*/dxc/\(.*\)/${OPCODE}/jm/T_${OPCODE}\(.*\)\.class#src/dot/\1/${subcode}/d/T_${subcode}\2.d#"
     84     FILEDEST=`echo ${CLASSFOLDER}/${jtestclassfile} | sed -e $SCRIPT`
     85     echo ${FILEDEST}
     86 #    SCRIPT="s#out/classes_[^/]*/dxc/\(.*\)${OPCODE}/Main_\(.*\)\.class#src/dot/\1/${subcode}/Main_\2.d#"
     87 #    FILEDEST=`echo ${CLASSFOLDER}/${jpackageclassfile} | sed -e $SCRIPT`
     88 #    echo ${FILEDEST}
     89     
     90     cd out/tmp
     91     OUT=`dx --dex --no-optimize --positions=lines --output="/tmp/dxclasses.jar" ${jtestclassfile} 2>&1`
     92     
     93     if [ $? -eq 0 ]; then
     94         cd ${BASEDIR}
     95         mkdir -p `dirname ${FILEDEST}`
     96         dexdump -g /tmp/dxclasses.jar > ${FILEDEST}
     97         sed -i -e 's/dxc\([\.|\/]\)junit/dot\1junit/' ${FILEDEST}
     98         SCRIPT="s/${OPCODE}\([\.|\/]\)jm\([\.|\/]\)/${subcode}\1d\2/g"
     99         sed -i -e ${SCRIPT} ${FILEDEST}
    100         SCRIPT="s/T_${OPCODE}/T_${subcode}/g"
    101         sed -i -e ${SCRIPT} ${FILEDEST}
    102         
    103         SCRIPT="s#dxc/\(.*\)/${OPCODE}/\(.*\)#src/dot/\1/${subcode}/\2#"
    104         jpackagedestfile=`echo ${jpackageclassfile} | sed -e $SCRIPT`
    105         cp src/${jpackageclassfile} ${jpackagedestfile}
    106         sed -i -e 's/dxc\([\.|\/]\)junit/dot\1junit/' ${jpackagedestfile}
    107         SCRIPT="s/${OPCODE}\([\.|\/]\)jm\([\.|\/]\)/${subcode}\1d\2/g"
    108         sed -i -e ${SCRIPT} ${jpackagedestfile}
    109         SCRIPT="s/T_${OPCODE}/T_${subcode}/g"
    110         sed -i -e ${SCRIPT} ${jpackagedestfile}
    111         sed -i -e "s/\(package .*\)${OPCODE}/\1${subcode}/" ${jpackagedestfile}
    112 
    113 
    114         SCRIPT="s#dxc/\(.*\)/${OPCODE}/jm/\(.*\)${OPCODE}\(.*\).class#src/dot/\1/${subcode}/d/\2${subcode}\3.java#"
    115         jpackagedestfile=`echo ${jtestclassfile} | sed -e $SCRIPT`
    116         cp src/${jtestsourcefile} ${jpackagedestfile}
    117         sed -i -e 's/dxc\([\.|\/]\)junit/dot\1junit/' ${jpackagedestfile}
    118         SCRIPT="s/${OPCODE}\([\.|\/]\)jm\([\.|\/|;]\)/${subcode}\1d\2/g"
    119         sed -i -e ${SCRIPT} ${jpackagedestfile}
    120         SCRIPT="s/T_${OPCODE}/T_${subcode}/g"
    121         sed -i -e ${SCRIPT} ${jpackagedestfile}
    122         sed -i -e "s/\(package .*\)${OPCODE}/\1${subcode}/" ${jpackagedestfile}
    123         
    124         srcdir=`dirname ${jtestsourcefile}`
    125         for srcfile in `find src/${srcdir} -maxdepth 1 -type f ! -name "T_*.java" -a -name "*.java"`; do
    126             echo $srcfile
    127             SCRIPT="s#dxc/\(.*\)/${OPCODE}/jm/\(.*\).java#dot/\1/${subcode}/d/\2.java#"
    128             jpackagedestfile=`echo ${srcfile} | sed -e $SCRIPT`
    129             cp ${srcfile} ${jpackagedestfile}
    130             sed -i -e 's/dxc\([\.|\/]\)junit/dot\1junit/' ${jpackagedestfile}
    131             SCRIPT="s/${OPCODE}\([\.|\/]\)jm\([\.|\/|;]\)/${subcode}\1d\2/g"
    132             sed -i -e ${SCRIPT} ${jpackagedestfile}
    133             SCRIPT="s/T_${OPCODE}/T_${subcode}/g"
    134             sed -i -e ${SCRIPT} ${jpackagedestfile}
    135             sed -i -e "s/\(package .*\)${OPCODE}/\1${subcode}/" ${jpackagedestfile}
    136         done
    137         
    138         srcdir=`dirname ${jpackageclassfile}`
    139         for srcfile in `find src/${srcdir} -maxdepth 1 -type f ! -name "Main_*.java" -a ! -name "Test_*.java" -a -name "*.java"`; do
    140             echo $srcfile
    141             SCRIPT="s#dxc/\(.*\)/${OPCODE}/\(.*\)#dot/\1/${subcode}/\2#"
    142             jpackagedestfile=`echo ${srcfile} | sed -e $SCRIPT`
    143             cp -v ${srcfile} ${jpackagedestfile}
    144         done
    145         
    146     else
    147         echo "--- not dexable"
    148     fi
    149     cd ${BASEDIR}
    150 done
    151 
    152 
    153 done 3<$BASEDIR/data/scriptdata
    154 
    155