From: "Ds, Sreedhara" <[email protected]>

        new file:   scripts/build_igt_cairo_tests.py
---
 scripts/build_igt_cairo_tests.py |  362 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 362 insertions(+)
 create mode 100755 scripts/build_igt_cairo_tests.py

diff --git a/scripts/build_igt_cairo_tests.py b/scripts/build_igt_cairo_tests.py
new file mode 100755
index 0000000..bb506fe
--- /dev/null
+++ b/scripts/build_igt_cairo_tests.py
@@ -0,0 +1,362 @@
+#!/usr/bin/env python
+
+# This python script helps to build tests in intel gpu tools which have cairo 
and glib
+# dependency. This script downloads cairo, pixman and glib for android
+# Generates android make file to build cairo and tests which have cairo 
dependency
+# modifies cairo and glib make files to enable the build
+# This script must be run under inetl_gpu_tools/scripts directory
+# Creates new directory "igt_kms_tests" under intel_gpu_tools and puts all 
required
+# software here. Generates environment file "build_igt.sh" to include Android
+# drm and pci-include paths. This file may need modification depending on drm 
and
+# pci-include paths in android source
+#
+# Generates "Android.mk" which can build cairo and glib libraries and all 
tests under
+# intel_gpu_tools/tests which have cairo dependency
+
+# Generate stubs for cairo functions for which no implementation available
+# Generates stubs for _pixman_implementation_create_sse2,
+# cairo_image_surface_create_from_png, cairo_surface_write_to_png,
+# __android_log_print, testdisplay_setup_hotplug, and 
testdisplay_cleanup_hotplug
+# These functions are either not supported, not used and not required in 
android
+
+# To build, follow the instructions shown after running this script under
+# intel_gpu_tools/scripts
+
+import sys
+import os
+import string
+
+CAIRO_REPO = 'git clone --recursive https://github.com/anoek/android-cairo.git'
+
+makefile1 = """ LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+include $(LOCAL_PATH)/jni/Android.mk
+#-----------------------------------------
+"""
+
+make1="""LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+#-----------------------------------------
+"""
+
+make2 = """
+LOCAL_C_INCLUDES +=                                      \\
+       $(LOCAL_PATH)/android-cairo/jni/cairo-extra                         \\
+       $(LOCAL_PATH)/android-cairo/jni/pixman/pixman                       \\
+       $(LOCAL_PATH)/android-cairo/jni/pixman-extra                       \\
+
+LIBCAIRO_CFLAGS:=                                                   \\
+    -DPACKAGE_VERSION="\"android-cairo\""                           \\
+    -DPACKAGE_BUGREPORT="\"http://github.com/anoek/android-cairo\""; \\
+    -DCAIRO_NO_MUTEX=1                                              \\
+    -DHAVE_STDINT_H                                                 \\
+    -DHAVE_UINT64_T                                                 \\
+
+LIBPIXMAN_CFLAGS:=                                                 \\
+    -D_USE_MATH_DEFINES                                            \\
+    -DPIXMAN_NO_TLS                                                \\
+    -DPACKAGE="android-cairo"                                      \\
+
+
+LOCAL_MODULE    := libcairo-pixman
+
+LOCAL_CFLAGS    := \\
+    -O2 $(LIBCAIRO_CFLAGS) \\
+    -O2 $(LIBPIXMAN_CFLAGS) \\
+    -Iandroid-cairo/jni/pixman/pixman -Iandroid-cairo/jni/cairo/src \\
+    -Iandroid-cairo/jni/cairo-extra -Iandroid-cairo/jni/pixman-extra \\
+    -Wno-missing-field-initializers -Wno-attributes \\
+    -include "pixman-elf-fix.h"
+    -include "limits.h"
+
+LOCAL_LDFLAGS   := -lz
+LOCAL_SRC_FILES := $(LIBCAIRO_SRC)
+
+include $(BUILD_STATIC_LIBRARY)
+"""
+
+env1 = """export TOP=$ANDROID_BUILD_TOP
+export BUILD_STATIC=true
+
+export 
IGT_LIB_CFLAGS="-I$ANDROID_BUILD_TOP/external/PRIVATE/libpciaccess/include \\
+                        -I$ANDROID_BUILD_TOP/external/PRIVATE/drm \\
+                        -I$ANDROID_BUILD_TOP/external/PRIVATE/drm/intel \\
+                        -I$ANDROID_BUILD_TOP/external/PRIVATE/drm/include \\
+                        -I$ANDROID_BUILD_TOP/external/PRIVATE/drm/include/drm 
\\
+                        -DHAVE_MMAP64"
+"""
+
+cario_glib_includes = """LOCAL_C_INCLUDES += \\
+                $(LOCAL_PATH)/android-cairo/jni/cairo/src \\
+                $(LOCAL_PATH)/android-cairo/jni/cairo-extra \\
+                $(LOCAL_PATH)/android-cairo/jni/pixman/pixman \\
+                $(LOCAL_PATH)/android-cairo/jni/pixman-extra \\
+                $(LOCAL_PATH)/glib \\
+                $(LOCAL_PATH)/glib/android \\
+                $(LOCAL_PATH)/glib/glib
+"""
+
+# Following files are not required in building cairo library
+cairo_file_filter = [ 'xcb', 'cogl', 'directfb', 'egl', 'cairo-gl', 'ft-font',
+'cairo-image-mask-compositor', 'cairo-os2-surface', 'cairo-pdf', 'cairo-png',
+'cairo-ps-surface', 'cairo-quartz', 'cairo-script-surface',
+'cairo-svg-surface', 'cairo-vg-surface', 'cairo-wgl', 'cairo-xlib',
+'cairo-xml', 'check-',
+]
+
+# Many files exists under pixman. Only following files are required in 
building pixman
+pixman_files1 = ['pixman-access.c', 'pixman-access-accessors.c',
+'pixman-gradient-walker.c', 'pixman-region16.c', 'pixman-region32.c',
+'pixman-image.c', 'pixman-implementation.c', 'pixman-general.c', 'pixman.c',
+'pixman-fast-path.c', 'pixman-solid-fill.c', 'pixman-conical-gradient.c',
+'pixman-linear-gradient.c', 'pixman-radial-gradient.c', 'pixman-bits-image.c',
+'pixman-utils.c', 'pixman-edge.c', 'pixman-edge-accessors.c', 'pixman-trap.c',
+'pixman-timer.c', 'pixman-matrix.c', 'pixman-noop.c', 'pixman-cpu.c',
+]
+
+#Files under pixman-extra
+pixman_files2 = ['pixman-combine32.c', 'pixman-combine64.c',]
+
+#Downlaods cairo and glib for android
+def download_cairo_glib():
+       print 'Downloading cairo ....'
+       os.system('git clone --recursive 
https://github.com/anoek/android-cairo.git')
+       print 'Downloading glib ....'
+       os.system('git clone https://github.com/ieei/glib.git')
+
+#Checks is files is under filter list or not
+#Entry in cairo_file_filter is not included in building cairo library
+def is_filtered(file):
+       for filter in cairo_file_filter:
+               if(string.find(file, filter) >= 0): return True
+       return False
+
+#Default glib make is for ARM. Edit the make file to suite our needs
+#Adds defines for G_BIT_LOCK_FORCE_FUTEX_EMULATION to overcome compilatiuon 
error
+#Adds compiler flag no-format-security to overcome compilatiuon error
+def edit_glib_make():
+       if(os.path.exists('glib/glib/Android.mk_ORG')):
+               return
+       os.system('cp glib/glib/Android.mk glib/glib/Android.mk_ORG')
+       f = open('glib/glib/Android.mk')
+       lines = f.readlines()
+       f.close()
+
+       f = open('glib/glib/Android.mk', 'w')
+       for line in lines:
+               if(string.find(line, '-DG_DISABLE_DEPRECATED') >= 0):
+                       f.write('\t' + '-DG_BIT_LOCK_FORCE_FUTEX_EMULATION' + 
'\t\\\n')
+                       f.write('\t' + '-Wno-format-security' + '\t\\\n')
+               f.write(line)
+
+#Add missing header <pthread.h> in kms_flip.c
+def edit_igt_kms_flip(pardir):
+       sfile = pardir + os.sep + 'tests' + os.sep + 'kms_flip.c'
+       if(os.path.exists(sfile + '_ORG')):
+               return
+       os.system('cp ' + sfile + ' ' + sfile + '_ORG')
+       f = open(sfile)
+       lines = f.readlines()
+       f.close()
+       f = open(sfile, 'w')
+       for line in lines:
+               if(string.find(line, '<linux/kd.h>') >= 0):
+                       f.write('#include <pthread.h>' + '\n')
+               f.write(line)
+
+#Edit make file for building libintel_gpu-tools (intel_gpu_tools/lib/Andrid.nk)
+#Adds environ variable IGT_LIB_CFLAGS which is defined in igtbuild.sh
+def edit_igt_lib_make(pardir):
+       mfile = pardir + os.sep + 'lib' + os.sep + 'Android.mk'
+
+       if(os.path.exists( mfile + '_ORG')):
+               return
+
+       if(not os.path.exists(mfile)):
+               print 'No "' + mfile + '" found'
+
+       os.system('cp ' + mfile + ' ' + mfile + '_ORG')
+       f = open(mfile)
+       lines = f.readlines()
+       f.close()
+       f = open(mfile, 'w')
+       for line in lines:
+               if(string.find(line, 'LOCAL_CFLAGS += -DANDROID') >= 0):
+                       f.write('LOCAL_CFLAGS += $(IGT_LIB_CFLAGS)' + '\n')
+               f.write(line)
+
+#Create "igtbuild.sh" which has include paths under android source
+#User need to modify this according to andoird source tree
+def gen_environ_file(pdir):
+       f = open(pdir + os.sep +  'igtbuild.sh', 'w')
+       f.write(env1)
+       f.close()
+
+#Creates make file (intel_gpu_tools/igt_cairo_tests/Android.mk) to build cairo,
+# intel gpu tools library and test display.
+def gen_make(pardir, f):
+       android_cairo_dir = pardir + os.sep + 'android-cairo'
+       cairo_files = os.listdir(android_cairo_dir + os.sep + 'jni/cairo/src')
+       cairo_files.sort()
+       f.write('LOCAL_PATH := $(call my-dir)' + '\n')
+       f.write('INTEL_GPU_TOOLS := ' + '..' + '\n')
+       f.write('include $(CLEAR_VARS)' + '\n')
+       f.write('#-----------------------------------------' + '\n')
+       f.write('LIBCAIRO_SRC = \\' + '\n')
+       for file in cairo_files:
+               if(os.path.splitext(file)[1] != '.c'): continue
+               if(is_filtered(file)): continue
+               #f.write('\tcairo/src' + os.sep + file + ' \\' + '\n')
+               f.write('\tandroid-cairo/jni/cairo/src' + os.sep + file + ' \\' 
+ '\n')
+       for file in pixman_files1:
+               f.write('\tandroid-cairo/jni/pixman/pixman' + os.sep + file + ' 
\\' + '\n')
+       for file in pixman_files2:
+               f.write('\tandroid-cairo/jni/pixman-extra' + os.sep + file + ' 
\\' + '\n')
+       f.write('\n')
+       f.write(make2)
+       
f.write('#----------------------------------------------------------------\n')
+
+       gen_tests(igt_cairo_tests_dir, f)
+
+def gen_includes(pardir, f):
+        f.write('LOCAL_CFLAGS += -I' + pardir + '/android-cairo/jni/cairo/src' 
+ '\n')
+        f.write('LOCAL_CFLAGS += -I' + pardir + 
'/android-cairo/jni/cairo-extra' + '\n')
+        f.write('LOCAL_CFLAGS += -I' + pardir + '/glib' + '\n')
+        f.write('LOCAL_CFLAGS += -I' + pardir + '/glib/android' + '\n')
+        f.write('LOCAL_CFLAGS += -I' + pardir + '/glib/glib' + '\n')
+        f.write('LOCAL_CFLAGS += 
-I$(ANDROID_BUILD_TOP)/external/PRIVATE/libpciaccess/include' + '\n')
+
+def is_cairo_dependent(file):
+       f = open(file)
+       lines = f.readlines()
+       f.close()
+       for line in lines:
+               if(not string.find(line, 'include') > 0): continue
+               if(string.find(line, 'cairo.h') > 0): return True
+       return False
+
+def gen_cairo_test(f, file):
+       
f.write('#-----------------------------------------------------------------\n')
+       f.write('include $(CLEAR_VARS)' + '\n')
+       f.write('LOCAL_SRC_FILES := $(INTEL_GPU_TOOLS)/tests/' + file + ' \\\n')
+       f.write('\t\t$(INTEL_GPU_TOOLS)/lib/' + 'igt_kms.c' + ' \\\n')
+       f.write('\t\tigt_cairo_tests_stub.c' + '\n\n')
+       f.write('LOCAL_CFLAGS += -DHAVE_LIBDRM_ATOMIC_PRIMITIVES -DANDROID' + 
'\n')
+       f.write('LOCAL_CFLAGS += -DHAVE_MMAP64 -DIGT_DATADIR="\\"\\""' + '\n')
+       f.write('LOCAL_CFLAGS += -std=c99 -Wno-return-type' + '\n')
+       f.write('LOCAL_CFLAGS += -Wno-implicit-function-declaration\n')
+       f.write('LOCAL_CFLAGS += $(IGT_LIB_CFLAGS)\n')
+       f.write(cario_glib_includes)
+       f.write('LOCAL_MODULE_TAGS := optional' + '\n')
+       f.write('LOCAL_STATIC_LIBRARIES := libintel_gpu_tools libcairo-pixman' 
+ '\n')
+       f.write('LOCAL_STATIC_LIBRARIES += libglib-2.0 libgmodule-2.0' + '\n')
+       f.write('LOCAL_SHARED_LIBRARIES := libpciaccess  libdrm libdrm_intel' + 
'\n')
+       f.write('LOCAL_MODULE := ' + os.path.splitext(file)[0] + '\n')
+       f.write('include $(BUILD_EXECUTABLE)' + '\n')
+       
f.write('#----------------------------------------------------------------------\n')
+
+cairo_tests = []
+def gen_tests(pardir, f):
+       f.write('include $(CLEAR_VARS)\n')
+        f.write('\n')
+
+       igttestsdir = os.path.abspath(os.path.join(pardir + '/..')) + os.sep + 
'tests'
+       igt_tests = os.listdir(igttestsdir)
+       for file in igt_tests:
+               if(os.path.splitext(file)[1] != '.c'): continue
+               if(is_cairo_dependent(igttestsdir + os.sep + file)):
+                       cairo_tests.append(file)
+                       gen_cairo_test(f, file)
+
+        f.write('\n')
+
+
+
+if __name__ == "__main__":
+       """
+       if(len(sys.argv) <= 1):
+               usage();
+               sys.exit(0);
+       """
+
+       pardir, curdir = os.path.split(os.getcwd())
+       igt_cairo_tests_dir = pardir + os.sep + 'igt_cairo_tests'
+       android_cairo_dir = igt_cairo_tests_dir + os.sep + 'android-cairo'
+       if(curdir == 'scripts'):
+               if(not os.path.exists(igt_cairo_tests_dir)): 
os.mkdir(igt_cairo_tests_dir)
+               os.chdir(igt_cairo_tests_dir)
+               #os.system('cd ..')
+       else:
+               print 'Run the script in the directory \"scripts\"'
+               sys.exit(0)
+
+       if(not os.path.exists('android-cairo')):
+               download_cairo_glib()
+       if(not os.path.exists(android_cairo_dir + os.sep + 'jni/cairo/src')):
+               print 'Invalid android cairo, download cairo sources from ' + \
+                       CAIRO_REPO + ' and try again'
+               sys.exit(0);
+
+       make_file = igt_cairo_tests_dir + os.sep + 'Android.mk'
+       print ''
+       if(1):
+       #if(not os.path.exists(make_file)):
+               print 'Generating makefile "' + make_file + '"'
+               f = open(make_file, 'w')
+               gen_make(igt_cairo_tests_dir, f)
+               f.close()
+       else:
+               print 'Nothing to do, make file already exists ...'
+
+       edit_glib_make()
+
+       stub_file = igt_cairo_tests_dir + os.sep + 'igt_cairo_tests_stub.c'
+       print 'Generating stub file "' + stub_file + '"'
+       f = open(stub_file, 'w')
+       f.write('void _pixman_implementation_create_sse2() {}' + '\n')
+       f.write('void cairo_image_surface_create_from_png()' + '\n')
+       f.write('{' + '\n')
+       f.write('\tprintf("%s not supported\\n", __FUNCTION__); exit(0);' + 
'\n')
+       f.write('}' + '\n')
+       f.write('void cairo_surface_write_to_png()' + '\n')
+       f.write('{' + '\n')
+       f.write('\tprintf("%s not supported\\n", __FUNCTION__); exit(0);' + 
'\n')
+       f.write('}' + '\n')
+       f.write('void __android_log_print() {}' + '\n')
+       f.write('void testdisplay_setup_hotplug() {}' + '\n')
+       f.write('void testdisplay_cleanup_hotplug() {}' + '\n')
+       print 'Generated stubs for following functions'
+       print 'These are not supported, not used and not required in android'
+       print '1. _pixman_implementation_create_sse2 '
+       print '2. cairo_image_surface_create_from_png'
+       print '3. cairo_surface_write_to_png '
+       print '4. __android_log_print'
+       print '5. testdisplay_setup_hotplug'
+       print '6. testdisplay_cleanup_hotplug'
+       print '\n'
+
+       f.close()
+
+       edit_igt_lib_make(pardir)
+
+       #Add missing header <pthread.h> in kms_flip.c to overcome compilation 
error
+       edit_igt_kms_flip(pardir)
+
+       #Create igtbuild.sh which has include paths from android source tree
+       gen_environ_file(igt_cairo_tests_dir)
+
+       print '\nYou can build following tests'
+       c = 1
+       for file in cairo_tests:
+               print `c` + '). ' + file + ' => ' + os.path.splitext(file)[0]
+               c += 1
+
+       print '\nFollow the steps below to build igt_cairo_tests\n'
+       print 
'----------------------------------------------------------------------'
+       print '1.Run "lunch <target platform>'
+       print '2.cd intel_gpu_tools/igt_cairo_tests'
+       print '3.source igtbuild.sh. (edit according to android source path)'
+       print '4.Build igt_cairo_tests - Run " cd glib; mm; cd -; cd ../lib; 
mm; cd -; mm"'
+       print 
'----------------------------------------------------------------------'
+
-- 
1.7.9.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to