1#!/bin/bash 2set -u 3set -e 4 5if [ -z "$ANDROID_BUILD_TOP" ] ; then 6 echo "ANDROID_BUILD_TOP is not set, did you run lunch?" 7 exit 1 8fi 9 10# Avoid spewing files in any location other than the intended one. 11if [ ! -x "$PWD/gen" ] ; then 12 echo "Run this script from its parent directory". 13 exit 1 14fi 15 16rm -rf out generated 17 18mkdir out 19 20# Create stub Java files for Android APIs that are used by the code we generate. 21# This allows us to test the generated code without building the rest of Android. 22 23mkdir -p out/javax/microedition/khronos/opengles 24mkdir -p out/com/google/android/gles_jni 25mkdir -p out/android/app 26mkdir -p out/android/graphics 27mkdir -p out/android/view 28mkdir -p out/android/opengl 29mkdir -p out/android/content 30mkdir -p out/android/content/pm 31mkdir -p out/android/os 32mkdir -p out/android/util 33 34echo "package android.graphics;" > out/android/graphics/Canvas.java 35echo "public interface Canvas {}" >> out/android/graphics/Canvas.java 36 37echo "package android.app; import android.content.pm.IPackageManager; public class AppGlobals { public static IPackageManager getPackageManager() { return null;} }" > out/android/app/AppGlobals.java 38# echo "package android.content; import android.content.pm.PackageManager; public interface Context { public PackageManager getPackageManager(); }" > out/android/content/Context.java 39echo "package android.content.pm; public class ApplicationInfo {public int targetSdkVersion;}" > out/android/content/pm/ApplicationInfo.java 40echo "package android.content.pm; public interface IPackageManager {ApplicationInfo getApplicationInfo(java.lang.String packageName, int flags, java.lang.String userId) throws android.os.RemoteException;}" > out/android/content/pm/IPackageManager.java 41echo "package android.os; public class Build {public static class VERSION_CODES { public static final int CUPCAKE = 3;}; }" > out/android/os/Build.java 42echo "package android.os; public class UserHandle {public static String myUserId() { return \"\"; } }" > out/android/os/UserHandle.java 43echo "package android.os; public class RemoteException extends Exception {}" > out/android/os/RemoteException.java 44echo "package android.util; public class Log {public static void w(String a, String b) {} public static void e(String a, String b) {}}" > out/android/util/Log.java 45 46echo "package android.opengl; public abstract class EGLObjectHandle { public int getHandle() { return 0; } }" > out/android/opengl/EGLObjectHandle.java 47 48 49echo "package android.graphics;" > out/android/graphics/SurfaceTexture.java 50echo "public interface SurfaceTexture {}" >> out/android/graphics/SurfaceTexture.java 51echo "package android.view;" > out/android/view/SurfaceView.java 52echo "public interface SurfaceView { SurfaceHolder getHolder(); }" >> out/android/view/SurfaceView.java 53echo "package android.view;" > out/android/view/Surface.java 54echo "public interface Surface {}" >> out/android/view/Surface.java 55echo "package android.view;" > out/android/view/SurfaceHolder.java 56echo "public interface SurfaceHolder { Surface getSurface(); }" >> out/android/view/SurfaceHolder.java 57 58cp static/egl/*.java out/android/opengl/ 59 60GLFILE=out/javax/microedition/khronos/opengles/GL.java 61cp stubs/jsr239/GLHeader.java-if $GLFILE 62 63GLGEN_FILES="CFunc.java CType.java CodeEmitter.java EGLCodeEmitter.java GenerateEGL.java GenerateGL.java GenerateGLES.java GLESCodeEmitter.java JFunc.java JniCodeEmitter.java JType.java Jsr239CodeEmitter.java ParameterChecker.java" 64 65pushd src > /dev/null 66javac ${GLGEN_FILES} 67JAVAC_RESULT=$? 68if [ $JAVAC_RESULT -ne 0 ]; then 69 echo "Could not compile glgen." 70 exit $JAVAC_RESULT 71fi 72popd > /dev/null 73 74echo "Generating JSR239-like APIs" 75java -classpath src GenerateGL -c specs/jsr239/glspec-1.0 \ 76 specs/jsr239/glspec-1.0ext \ 77 specs/jsr239/glspec-1.1 \ 78 specs/jsr239/glspec-1.1ext \ 79 specs/jsr239/glspec-1.1extpack \ 80 specs/jsr239/glspec-checks 81JAVA_RESULT=$? 82if [ $JAVA_RESULT -ne 0 ]; then 83 echo "Could not run GenerateGL." 84 exit $JAVA_RESULT 85fi 86 87echo "Generating static OpenGLES bindings" 88java -classpath src GenerateGLES 89JAVA_RESULT=$? 90if [ $JAVA_RESULT -ne 0 ]; then 91 echo "Could not run GenerateGLES." 92 exit $JAVA_RESULT 93fi 94 95echo "Generating static EGL bindings" 96java -classpath src GenerateEGL 97JAVA_RESULT=$? 98if [ $JAVA_RESULT -ne 0 ]; then 99 echo "Could not run GenerateEGL." 100 exit $JAVA_RESULT 101fi 102 103rm src/*.class 104 105# Add UnsupportedAppUsage.java to known sources. 106mkdir -p out/android/compat/annotation 107cp ${ANDROID_BUILD_TOP}/tools/platform-compat/java/android/compat/annotation/UnsupportedAppUsage.java out/android/compat/annotation 108 109pushd out > /dev/null 110mkdir classes 111javac -d classes android/opengl/EGL14.java \ 112 android/opengl/EGL15.java \ 113 android/opengl/EGLExt.java \ 114 com/google/android/gles_jni/GLImpl.java \ 115 javax/microedition/khronos/opengles/GL10.java \ 116 javax/microedition/khronos/opengles/GL10Ext.java \ 117 javax/microedition/khronos/opengles/GL11.java \ 118 javax/microedition/khronos/opengles/GL11Ext.java \ 119 javax/microedition/khronos/opengles/GL11ExtensionPack.java \ 120 android/opengl/GLES10.java \ 121 android/opengl/GLES10Ext.java \ 122 android/opengl/GLES11.java \ 123 android/opengl/GLES11Ext.java \ 124 android/opengl/GLES20.java \ 125 android/opengl/GLES30.java \ 126 android/opengl/GLES31.java \ 127 android/opengl/GLES31Ext.java \ 128 android/opengl/GLES32.java \ 129 android/compat/annotation/UnsupportedAppUsage.java 130popd > /dev/null 131JAVA_RESULT=$? 132if [ $JAVA_RESULT -ne 0 ]; then 133 echo "Could not compile generated classes." 134 exit $JAVA_RESULT 135fi 136 137rm -rf generated 138mkdir -p generated/C 139cp out/com_google_android_gles_jni_GLImpl.cpp generated/C 140cp -r out/com generated 141cp -r out/javax generated 142 143cp out/android_opengl_*.cpp generated/C 144mkdir -p generated/android/opengl 145cp -r out/android/opengl generated/android 146 147rm -rf out 148KEEP_GENERATED=0 149SAID_PLEASE=0 150 151# compareGenerated destDir generatedDir file 152compareGenerated() { 153 if cmp -s $1/$3 $2/$3 ; then 154 echo "# " $3 unchanged 155 else 156 echo "# " $3 changed 157 if [ $SAID_PLEASE == "0" ] ; then 158 echo Please evaluate the following commands: 159 echo 160 SAID_PLEASE=1 161 fi 162 echo " cp $2/$3 $1/$3" 163 echo " (cd $1; git add $3)" 164 KEEP_GENERATED=1 165 fi 166} 167 168compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/core/jni generated/C com_google_android_gles_jni_GLImpl.cpp 169compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/com/google/android/gles_jni generated/com/google/android/gles_jni GLImpl.java 170 171for x in GL.java GL10.java GL10Ext.java GL11.java GL11Ext.java GL11ExtensionPack.java 172do 173 compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x 174done 175 176for x in EGL14 EGL15 EGLExt GLES10 GLES10Ext GLES11 GLES11Ext GLES20 GLES30 GLES31 GLES31Ext GLES32 177do 178 compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/android/opengl generated/android/opengl ${x}.java 179 compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/core/jni generated/C android_opengl_${x}.cpp 180done 181 182for x in EGLConfig EGLContext EGLDisplay EGLObjectHandle EGLSurface EGLImage EGLSync 183do 184 compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/android/opengl generated/android/opengl ${x}.java 185done 186 187if [ $KEEP_GENERATED == "0" ] ; then 188 rm -rf generated 189fi 190