1# -*- coding: utf-8 -*- 2 3#------------------------------------------------------------------------- 4# drawElements Quality Program utilities 5# -------------------------------------- 6# 7# Copyright 2017 The Android Open Source Project 8# 9# Licensed under the Apache License, Version 2.0 (the "License"); 10# you may not use this file except in compliance with the License. 11# You may obtain a copy of the License at 12# 13# http://www.apache.org/licenses/LICENSE-2.0 14# 15# Unless required by applicable law or agreed to in writing, software 16# distributed under the License is distributed on an "AS IS" BASIS, 17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18# See the License for the specific language governing permissions and 19# limitations under the License. 20# 21#------------------------------------------------------------------------- 22 23import os 24import posixpath 25from fnmatch import fnmatch 26 27from build.common import DEQP_DIR, writeFile 28 29SRC_ROOTS = [ 30 "execserver", 31 "executor", 32 "external/vulkancts", 33 "framework/common", 34 "framework/delibs", 35 "framework/egl", 36 "framework/opengl", 37 "framework/platform/android", 38 "framework/qphelper", 39 "framework/randomshaders", 40 "framework/referencerenderer", 41 "modules", 42] 43 44INCLUDE_PATTERNS = [ 45 "*.cpp", 46 "*.c", 47] 48 49EXCLUDE_PATTERNS = [ 50 "execserver/xsWin32TestProcess.cpp", 51 "external/vulkancts/modules/vulkan/vktBuildPrograms.cpp", 52 "framework/delibs/dethread/standalone_test.c", 53 "framework/randomshaders/rsgTest.cpp", 54 "executor/tools/*", 55 "execserver/tools/*", 56] 57 58TEMPLATE = """ 59# WARNING: This is auto-generated file. Do not modify, since changes will 60# be lost! Modify scripts/gen_android_mk.py instead. 61 62LOCAL_SRC_FILES :={SRC_FILES} 63 64LOCAL_C_INCLUDES :={INCLUDES} 65 66"""[1:-1] 67 68def matchesAny (filename, patterns): 69 for ptrn in patterns: 70 if fnmatch(filename, ptrn): 71 return True 72 return False 73 74def isSourceFile (filename): 75 return matchesAny(filename, INCLUDE_PATTERNS) and not matchesAny(filename, EXCLUDE_PATTERNS) 76 77def toPortablePath (nativePath): 78 # os.path is so convenient... 79 head, tail = os.path.split(nativePath) 80 components = [tail] 81 82 while head != None and head != '': 83 head, tail = os.path.split(head) 84 components.append(tail) 85 86 components.reverse() 87 88 portablePath = "" 89 for component in components: 90 portablePath = posixpath.join(portablePath, component) 91 92 return portablePath 93 94def getSourceFiles (): 95 sources = [] 96 97 for srcRoot in SRC_ROOTS: 98 baseDir = os.path.join(DEQP_DIR, srcRoot) 99 for root, dirs, files in os.walk(baseDir): 100 for file in files: 101 absPath = os.path.join(root, file) 102 nativeRelPath = os.path.relpath(absPath, DEQP_DIR) 103 portablePath = toPortablePath(nativeRelPath) 104 105 if isSourceFile(portablePath): 106 sources.append(portablePath) 107 108 sources.sort() 109 110 return sources 111 112def getSourceDirs (sourceFiles): 113 seenDirs = set() 114 sourceDirs = [] 115 116 for sourceFile in sourceFiles: 117 sourceDir = posixpath.dirname(sourceFile) 118 119 if not sourceDir in seenDirs: 120 sourceDirs.append(sourceDir) 121 seenDirs.add(sourceDir) 122 123 return sourceDirs 124 125def genMkStringList (items): 126 src = "" 127 128 for item in items: 129 src += " \\\n\t%s" % item 130 131 return src 132 133def genAndroidMk (sourceDirs, sourceFiles): 134 src = TEMPLATE 135 src = src.replace("{INCLUDES}", genMkStringList(["$(deqp_dir)/%s" % s for s in sourceDirs])) 136 src = src.replace("{SRC_FILES}", genMkStringList(sourceFiles)) 137 138 return src 139 140if __name__ == "__main__": 141 sourceFiles = getSourceFiles() 142 sourceDirs = getSourceDirs(sourceFiles) 143 androidMkText = genAndroidMk(sourceDirs, sourceFiles) 144 145 writeFile(os.path.join(DEQP_DIR, "AndroidGen.mk"), androidMkText) 146