Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2015 Google Inc. All rights reserved. |
| 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 | # Note: This script runs on Mac and Linux. It requires `kotlin` to be installed |
| 18 | # and `flatc` to be built (using `cmake` in the root directory). |
| 19 | |
| 20 | sampledir=$(cd $(dirname $BASH_SOURCE) && pwd) |
| 21 | rootdir=$(cd $sampledir/.. && pwd) |
| 22 | currentdir=$(pwd) |
| 23 | |
| 24 | if [[ "$sampledir" != "$currentdir" ]]; then |
| 25 | echo Error: This script must be run from inside the $sampledir directory. |
| 26 | echo You executed it from the $currentdir directory. |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | # Run `flatc`. Note: This requires you to compile using `cmake` from the |
| 31 | # root `/flatbuffers` directory. |
| 32 | if [ -e ../flatc ]; then |
| 33 | echo "compiling now" |
| 34 | ../flatc --kotlin --gen-mutable monster.fbs |
| 35 | elif [ -e ../Debug/flatc ]; then |
| 36 | ../Debug/flatc --kotlin --gen-mutable monster.fbs |
| 37 | else |
| 38 | echo 'flatc' could not be found. Make sure to build FlatBuffers from the \ |
| 39 | $rootdir directory. |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
| 43 | echo Compiling and running the Kotlin sample |
| 44 | |
| 45 | all_kt_files=`find $sampledir -name "*.kt" -print` |
| 46 | # Run test |
| 47 | mkdir -v "${sampledir}/kotlin" |
| 48 | echo Compiling Java Runtime |
| 49 | javac ${rootdir}/java/com/google/flatbuffers/*.java -d ${sampledir}/kotlin |
| 50 | echo Compiling Kotlin source |
| 51 | kotlinc -classpath ${sampledir}/../java:${sampledir}/kotlin $all_kt_files SampleBinary.kt -include-runtime -d ${sampledir}/kotlin |
| 52 | # Make jar |
| 53 | echo Making jar |
| 54 | jar cvf ${sampledir}/kotlin/kotlin_sample.jar -C ${sampledir}/kotlin . > /dev/null |
| 55 | echo Running test |
| 56 | kotlin -cp ${sampledir}/kotlin/kotlin_sample.jar SampleBinary |
| 57 | |
| 58 | # Cleanup temporary files. |
| 59 | # rm -rf MyGame/ |
| 60 | # rm -rf ${sampledir}/kotlin |