• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/annotation
26mkdir -p out/android/app
27mkdir -p out/android/graphics
28mkdir -p out/android/hardware
29mkdir -p out/android/view
30mkdir -p out/android/opengl
31mkdir -p out/android/content
32mkdir -p out/android/content/pm
33mkdir -p out/android/os
34mkdir -p out/android/util
35
36echo "package android.graphics;" > out/android/graphics/Canvas.java
37echo "public interface Canvas {}" >> out/android/graphics/Canvas.java
38
39echo "package android.annotation; public @interface NonNull {}" > out/android/annotation/NonNull.java
40echo "package android.app; import android.content.pm.IPackageManager; public class AppGlobals { public static IPackageManager getPackageManager() { return null;} }" > out/android/app/AppGlobals.java
41# echo "package android.content; import android.content.pm.PackageManager; public interface Context { public PackageManager getPackageManager(); }" > out/android/content/Context.java
42echo "package android.content.pm; public class ApplicationInfo {public int targetSdkVersion;}" > out/android/content/pm/ApplicationInfo.java
43echo "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
44echo "package android.hardware; import android.os.ParcelFileDescriptor; public class SyncFence { public static SyncFence create(ParcelFileDescriptor w) { return null; } public static SyncFence createEmpty() { return null; } }" > out/android/hardware/SyncFence.java
45echo "package android.os; public class Build {public static class VERSION_CODES { public static final int CUPCAKE = 0; public static final int R = 0; }; }" > out/android/os/Build.java
46echo "package android.os; public class ParcelFileDescriptor { public static ParcelFileDescriptor adoptFd(int fd) { return null; } }" > out/android/os/ParcelFileDescriptor.java
47echo "package android.os; public class UserHandle {public static String myUserId() { return \"\"; } }" > out/android/os/UserHandle.java
48echo "package android.os; public class RemoteException extends Exception {}" > out/android/os/RemoteException.java
49echo "package android.util; public class Log {public static void d(String a, String b) {} public static void w(String a, String b) {} public static void e(String a, String b) {}}" > out/android/util/Log.java
50
51echo "package android.opengl; public abstract class EGLObjectHandle { public int getHandle() { return 0; } }" > out/android/opengl/EGLObjectHandle.java
52
53echo "package android.graphics;" > out/android/graphics/SurfaceTexture.java
54echo "public interface SurfaceTexture {}" >> out/android/graphics/SurfaceTexture.java
55echo "package android.view;" > out/android/view/SurfaceView.java
56echo "public interface SurfaceView { SurfaceHolder getHolder(); }" >> out/android/view/SurfaceView.java
57echo "package android.view;" > out/android/view/Surface.java
58echo "public interface Surface {}" >> out/android/view/Surface.java
59echo "package android.view;" > out/android/view/SurfaceHolder.java
60echo "public interface SurfaceHolder { Surface getSurface(); }" >> out/android/view/SurfaceHolder.java
61
62cp static/egl/*.java out/android/opengl/
63
64GLFILE=out/javax/microedition/khronos/opengles/GL.java
65cp stubs/jsr239/GLHeader.java-if $GLFILE
66
67GLGEN_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"
68
69pushd src > /dev/null
70javac ${GLGEN_FILES}
71JAVAC_RESULT=$?
72if [ $JAVAC_RESULT -ne 0 ]; then
73    echo "Could not compile glgen."
74    exit $JAVAC_RESULT
75fi
76popd > /dev/null
77
78echo "Generating JSR239-like APIs"
79java -classpath src GenerateGL -c specs/jsr239/glspec-1.0 \
80                                  specs/jsr239/glspec-1.0ext \
81                                  specs/jsr239/glspec-1.1 \
82                                  specs/jsr239/glspec-1.1ext \
83                                  specs/jsr239/glspec-1.1extpack \
84                                  specs/jsr239/glspec-checks
85JAVA_RESULT=$?
86if [ $JAVA_RESULT -ne 0 ]; then
87    echo "Could not run GenerateGL."
88    exit $JAVA_RESULT
89fi
90
91echo "Generating static OpenGLES bindings"
92java -classpath src GenerateGLES
93JAVA_RESULT=$?
94if [ $JAVA_RESULT -ne 0 ]; then
95    echo "Could not run GenerateGLES."
96    exit $JAVA_RESULT
97fi
98
99echo "Generating static EGL bindings"
100java -classpath src GenerateEGL
101JAVA_RESULT=$?
102if [ $JAVA_RESULT -ne 0 ]; then
103    echo "Could not run GenerateEGL."
104    exit $JAVA_RESULT
105fi
106
107rm src/*.class
108
109# Add UnsupportedAppUsage.java to known sources.
110mkdir -p out/android/compat/annotation
111cp ${ANDROID_BUILD_TOP}/tools/platform-compat/java/android/compat/annotation/UnsupportedAppUsage.java out/android/compat/annotation
112
113pushd out > /dev/null
114mkdir classes
115javac -d classes    android/opengl/EGL14.java \
116                    android/opengl/EGL15.java \
117                    android/opengl/EGLExt.java \
118                    com/google/android/gles_jni/GLImpl.java \
119                    javax/microedition/khronos/opengles/GL10.java \
120                    javax/microedition/khronos/opengles/GL10Ext.java \
121                    javax/microedition/khronos/opengles/GL11.java \
122                    javax/microedition/khronos/opengles/GL11Ext.java \
123                    javax/microedition/khronos/opengles/GL11ExtensionPack.java \
124                    android/opengl/GLES10.java \
125                    android/opengl/GLES10Ext.java \
126                    android/opengl/GLES11.java \
127                    android/opengl/GLES11Ext.java \
128                    android/opengl/GLES20.java \
129                    android/opengl/GLES30.java \
130                    android/opengl/GLES31.java \
131                    android/opengl/GLES31Ext.java \
132                    android/opengl/GLES32.java \
133                    android/compat/annotation/UnsupportedAppUsage.java
134popd > /dev/null
135JAVA_RESULT=$?
136if [ $JAVA_RESULT -ne 0 ]; then
137    echo "Could not compile generated classes."
138    exit $JAVA_RESULT
139fi
140
141rm -rf generated
142mkdir -p generated/C
143cp out/com_google_android_gles_jni_GLImpl.cpp generated/C
144cp -r out/com generated
145cp -r out/javax generated
146
147cp out/android_opengl_*.cpp generated/C
148mkdir -p generated/android/opengl
149cp -r out/android/opengl generated/android
150
151rm -rf out
152KEEP_GENERATED=0
153SAID_PLEASE=0
154
155# compareGenerated destDir generatedDir file
156compareGenerated() {
157    if cmp -s $1/$3 $2/$3 ; then
158        echo "#    " $3 unchanged
159    else
160        echo "#    " $3 changed
161        if [ $SAID_PLEASE == "0" ] ; then
162            echo Please evaluate the following commands:
163            echo
164            SAID_PLEASE=1
165        fi
166        echo "    cp $2/$3 $1/$3"
167        echo "    (cd $1; git add $3)"
168        KEEP_GENERATED=1
169    fi
170}
171
172compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/core/jni generated/C com_google_android_gles_jni_GLImpl.cpp
173compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/com/google/android/gles_jni generated/com/google/android/gles_jni GLImpl.java
174
175for x in GL.java GL10.java GL10Ext.java GL11.java GL11Ext.java GL11ExtensionPack.java
176do
177    compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x
178done
179
180for x in EGL14 EGL15 EGLExt GLES10 GLES10Ext GLES11 GLES11Ext GLES20 GLES30 GLES31 GLES31Ext GLES32
181do
182    compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/android/opengl generated/android/opengl ${x}.java
183    compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/core/jni generated/C android_opengl_${x}.cpp
184done
185
186for x in EGLConfig EGLContext EGLDisplay EGLObjectHandle EGLSurface EGLImage EGLSync
187do
188    compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/android/opengl generated/android/opengl ${x}.java
189done
190
191if [ $KEEP_GENERATED == "0" ] ; then
192    rm -rf generated
193fi
194